Reduce verbosity when calling for
-loop on non-Iterator
expression
This commit is contained in:
parent
7227a87371
commit
75b62757e4
4 changed files with 12 additions and 7 deletions
|
@ -350,6 +350,8 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
|
||||
AwaitableExpr,
|
||||
|
||||
ForLoopIterator,
|
||||
|
||||
/// Well-formed checking. If a `WellFormedLoc` is provided,
|
||||
/// then it will be used to eprform HIR-based wf checking
|
||||
/// after an error occurs, in order to generate a more precise error span.
|
||||
|
|
|
@ -887,8 +887,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
let span = obligation.cause.span;
|
||||
|
||||
if let ObligationCauseCode::AwaitableExpr = obligation.cause.code {
|
||||
// FIXME: use `trait_ref.self_ty().no_bound_vars()` to typecheck if `()` and if not
|
||||
// maybe suggest returning instead?
|
||||
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
|
||||
// and if not maybe suggest doing something else? If we kept the expression around we
|
||||
// could also check if it is an fn call (very likely) and suggest changing *that*, if
|
||||
// it is from the local crate.
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
"do not `.await` the expression",
|
||||
|
@ -1961,6 +1963,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
| ObligationCauseCode::ReturnValue(_)
|
||||
| ObligationCauseCode::BlockTailExpression(_)
|
||||
| ObligationCauseCode::AwaitableExpr
|
||||
| ObligationCauseCode::ForLoopIterator
|
||||
| ObligationCauseCode::LetElse => {}
|
||||
ObligationCauseCode::SliceOrArrayElem => {
|
||||
err.note("slice and array elements must have `Sized` type");
|
||||
|
|
|
@ -810,8 +810,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
&substs,
|
||||
match lang_item {
|
||||
hir::LangItem::FuturePoll => ObligationCauseCode::AwaitableExpr,
|
||||
// FIXME: see if there are other obligation specializations we could do here beyond
|
||||
// what we do above for `.await`.
|
||||
hir::LangItem::IntoIterIntoIter => ObligationCauseCode::ForLoopIterator,
|
||||
// FIXME: This could also be used for `?`. See if there are others.
|
||||
_ => traits::ItemObligation(def_id),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -16,10 +16,10 @@ error[E0271]: type mismatch resolving `<std::collections::hash_map::Iter<'_, _,
|
|||
--> $DIR/issue-33941.rs:4:14
|
||||
|
|
||||
LL | for _ in HashMap::new().iter().cloned() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found tuple
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected tuple, found reference
|
||||
|
|
||||
= note: expected reference `&_`
|
||||
found tuple `(&_, &_)`
|
||||
= note: expected tuple `(&_, &_)`
|
||||
found reference `&_`
|
||||
= note: required because of the requirements on the impl of `Iterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
|
||||
= note: required because of the requirements on the impl of `IntoIterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue