From bc60d50eaa045f6c17b1c127e486d0e3232f1e89 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 6 Dec 2022 17:34:24 +0000 Subject: Provide associated type information in method chains When encountering an unmet obligation that affects a method chain, like in iterator chains where one of the links has the wrong associated type, we point at every method call and mention their evaluated associated type at that point to give context to the user of where expectations diverged from the code as written. ``` note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>` --> $DIR/invalid-iterator-chain.rs:12:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() | ------ associated type `std::iter::Iterator::Item` is `&{integer}` here LL | .map(|x| { x; }) | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here ``` --- src/test/ui/issues/issue-34334.stderr | 8 ++ .../issue-66923-show-error-for-correct-call.stderr | 14 +++ src/test/ui/iterators/invalid-iterator-chain.rs | 17 ++++ .../ui/iterators/invalid-iterator-chain.stderr | 111 +++++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 src/test/ui/iterators/invalid-iterator-chain.rs create mode 100644 src/test/ui/iterators/invalid-iterator-chain.stderr (limited to 'src') diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index 3188cd80cca..5e84dcdef30 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -22,6 +22,14 @@ LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_rece | = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` = help: the trait `FromIterator` is implemented for `Vec` +note: the expression is of type `Map, [closure@$DIR/issue-34334.rs:5:47: 5:82]>` + --> $DIR/issue-34334.rs:5:43 + | +LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); + | -- ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here + | | | + | | associated type `std::iter::Iterator::Item` is `&(_, _, _)` here + | this expression has type `Vec<(_, _, _)>` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr index ce38c3320bb..5ee287b1b15 100644 --- a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -8,6 +8,13 @@ LL | let x2: Vec = x1.into_iter().collect(); | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` +note: the expression is of type `std::slice::Iter<'_, f64>` + --> $DIR/issue-66923-show-error-for-correct-call.rs:8:27 + | +LL | let x2: Vec = x1.into_iter().collect(); + | -- ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here + | | + | this expression has type `&[f64]` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -24,6 +31,13 @@ LL | let x3 = x1.into_iter().collect::>(); | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` +note: the expression is of type `std::slice::Iter<'_, f64>` + --> $DIR/issue-66923-show-error-for-correct-call.rs:12:17 + | +LL | let x3 = x1.into_iter().collect::>(); + | -- ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here + | | + | this expression has type `&[f64]` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/iterators/invalid-iterator-chain.rs b/src/test/ui/iterators/invalid-iterator-chain.rs new file mode 100644 index 00000000000..de174807ab6 --- /dev/null +++ b/src/test/ui/iterators/invalid-iterator-chain.rs @@ -0,0 +1,17 @@ +fn main() { + let scores = vec![(0, 0)] + .iter() + .map(|(a, b)| { + a + b; + }); + println!("{}", scores.sum::()); //~ ERROR E0277 + println!( + "{}", + vec![0, 1] //~ ERROR E0277 + .iter() + .map(|x| { x; }) + .sum::(), + ); + println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); //~ ERROR E0277 + println!("{}", vec![(), ()].iter().sum::()); //~ ERROR E0277 +} diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr new file mode 100644 index 00000000000..03298089d88 --- /dev/null +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -0,0 +1,111 @@ +error[E0277]: the trait bound `i32: Sum<()>` is not satisfied + --> $DIR/invalid-iterator-chain.rs:7:20 + | +LL | println!("{}", scores.sum::()); + | ^^^^^^ --- required by a bound introduced by this call + | | + | the trait `Sum<()>` is not implemented for `i32` + | + = help: the following other types implement trait `Sum`: + > + +note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:4:14: 4:22]>` + --> $DIR/invalid-iterator-chain.rs:7:20 + | +LL | let scores = vec![(0, 0)] + | ------------ this expression has type `Vec<({integer}, {integer})>` +LL | .iter() + | ------ associated type `std::iter::Iterator::Item` is `&({integer}, {integer})` here +LL | .map(|(a, b)| { + | __________- +LL | | a + b; +LL | | }); + | |__________- associated type `std::iter::Iterator::Item` is `()` here +LL | println!("{}", scores.sum::()); + | ^^^^^^ +note: required by a bound in `std::iter::Iterator::sum` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | S: Sum, + | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + +error[E0277]: the trait bound `i32: Sum<()>` is not satisfied + --> $DIR/invalid-iterator-chain.rs:10:9 + | +LL | / vec![0, 1] +LL | | .iter() +LL | | .map(|x| { x; }) + | |____________________________^ the trait `Sum<()>` is not implemented for `i32` +LL | .sum::(), + | --- required by a bound introduced by this call + | + = help: the following other types implement trait `Sum`: + > + +note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>` + --> $DIR/invalid-iterator-chain.rs:12:14 + | +LL | vec![0, 1] + | ---------- this expression has type `Vec<{integer}>` +LL | .iter() + | ------ associated type `std::iter::Iterator::Item` is `&{integer}` here +LL | .map(|x| { x; }) + | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here +note: required by a bound in `std::iter::Iterator::sum` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | S: Sum, + | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + +error[E0277]: the trait bound `i32: Sum<()>` is not satisfied + --> $DIR/invalid-iterator-chain.rs:15:20 + | +LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call + | | + | the trait `Sum<()>` is not implemented for `i32` + | + = help: the following other types implement trait `Sum`: + > + +note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:15:42: 15:45]>` + --> $DIR/invalid-iterator-chain.rs:15:38 + | +LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); + | ---------- ------ ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here + | | | + | | associated type `std::iter::Iterator::Item` is `&{integer}` here + | this expression has type `Vec<{integer}>` +note: required by a bound in `std::iter::Iterator::sum` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | S: Sum, + | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + +error[E0277]: the trait bound `i32: Sum<&()>` is not satisfied + --> $DIR/invalid-iterator-chain.rs:16:20 + | +LL | println!("{}", vec![(), ()].iter().sum::()); + | ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call + | | + | the trait `Sum<&()>` is not implemented for `i32` + | + = help: the following other types implement trait `Sum`: + > + +note: the expression is of type `std::slice::Iter<'_, ()>` + --> $DIR/invalid-iterator-chain.rs:16:33 + | +LL | println!("{}", vec![(), ()].iter().sum::()); + | ------------ ^^^^^^ associated type `std::iter::Iterator::Item` is `&()` here + | | + | this expression has type `Vec<()>` +note: required by a bound in `std::iter::Iterator::sum` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | S: Sum, + | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From 49d5bef5867012a3ec39a04c81694b64b22f0067 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Tue, 6 Dec 2022 10:32:49 -0800 Subject: Expand iterator chain test --- src/test/ui/iterators/invalid-iterator-chain.rs | 5 ++++ .../ui/iterators/invalid-iterator-chain.stderr | 28 ++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/test/ui/iterators/invalid-iterator-chain.rs b/src/test/ui/iterators/invalid-iterator-chain.rs index de174807ab6..3d4801b3732 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.rs +++ b/src/test/ui/iterators/invalid-iterator-chain.rs @@ -9,6 +9,11 @@ fn main() { "{}", vec![0, 1] //~ ERROR E0277 .iter() + .map(|x| x * 2) + .map(|x| x as f64) + .map(|x| x as i64) + .filter(|x| *x > 0) + .map(|x| { x + 1 }) .map(|x| { x; }) .sum::(), ); diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 03298089d88..0b3e0653864 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -34,6 +34,10 @@ error[E0277]: the trait bound `i32: Sum<()>` is not satisfied | LL | / vec![0, 1] LL | | .iter() +LL | | .map(|x| x * 2) +LL | | .map(|x| x as f64) +... | +LL | | .map(|x| { x + 1 }) LL | | .map(|x| { x; }) | |____________________________^ the trait `Sum<()>` is not implemented for `i32` LL | .sum::(), @@ -42,13 +46,23 @@ LL | .sum::(), = help: the following other types implement trait `Sum`: > -note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>` - --> $DIR/invalid-iterator-chain.rs:12:14 +note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>, [closure@$DIR/invalid-iterator-chain.rs:13:18: 13:21]>, [closure@$DIR/invalid-iterator-chain.rs:14:18: 14:21]>, [closure@$DIR/invalid-iterator-chain.rs:15:21: 15:24]>, [closure@$DIR/invalid-iterator-chain.rs:16:18: 16:21]>, [closure@$DIR/invalid-iterator-chain.rs:17:18: 17:21]>` + --> $DIR/invalid-iterator-chain.rs:17:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() | ------ associated type `std::iter::Iterator::Item` is `&{integer}` here +LL | .map(|x| x * 2) + | -------------- associated type `std::iter::Iterator::Item` is `{integer}` here +LL | .map(|x| x as f64) + | ----------------- associated type `std::iter::Iterator::Item` is `f64` here +LL | .map(|x| x as i64) + | ----------------- associated type `std::iter::Iterator::Item` is `i64` here +LL | .filter(|x| *x > 0) + | ------------------ associated type `std::iter::Iterator::Item` is `i64` here +LL | .map(|x| { x + 1 }) + | ------------------ associated type `std::iter::Iterator::Item` is `i64` here LL | .map(|x| { x; }) | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here note: required by a bound in `std::iter::Iterator::sum` @@ -58,7 +72,7 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` error[E0277]: the trait bound `i32: Sum<()>` is not satisfied - --> $DIR/invalid-iterator-chain.rs:15:20 + --> $DIR/invalid-iterator-chain.rs:20:20 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call @@ -68,8 +82,8 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); = help: the following other types implement trait `Sum`: > -note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:15:42: 15:45]>` - --> $DIR/invalid-iterator-chain.rs:15:38 +note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:20:42: 20:45]>` + --> $DIR/invalid-iterator-chain.rs:20:38 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); | ---------- ------ ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here @@ -83,7 +97,7 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` error[E0277]: the trait bound `i32: Sum<&()>` is not satisfied - --> $DIR/invalid-iterator-chain.rs:16:20 + --> $DIR/invalid-iterator-chain.rs:21:20 | LL | println!("{}", vec![(), ()].iter().sum::()); | ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call @@ -94,7 +108,7 @@ LL | println!("{}", vec![(), ()].iter().sum::()); > note: the expression is of type `std::slice::Iter<'_, ()>` - --> $DIR/invalid-iterator-chain.rs:16:33 + --> $DIR/invalid-iterator-chain.rs:21:33 | LL | println!("{}", vec![(), ()].iter().sum::()); | ------------ ^^^^^^ associated type `std::iter::Iterator::Item` is `&()` here -- cgit 1.4.1-3-g733a5 From 64bc975d27f86aaa1d3d94921c9c042477b4e88b Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Tue, 6 Dec 2022 12:08:17 -0800 Subject: Mention only assoc types changes --- .../src/traits/error_reporting/suggestions.rs | 96 ++++++++++++++++------ src/test/ui/issues/issue-34334.stderr | 6 +- .../issue-66923-show-error-for-correct-call.stderr | 4 +- .../ui/iterators/invalid-iterator-chain.stderr | 38 ++++----- 4 files changed, 92 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 8bfa405cbea..2f9b8c21071 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2865,11 +2865,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } - let span = expr.span; - let mut multi_span: MultiSpan = match expr.kind { - hir::ExprKind::MethodCall(_, _, _, span) => span.into(), - _ => span.into(), - }; + let mut primary_spans = vec![]; + let mut span_labels = vec![]; // FIXME: visit the ty to see if there's any closure involved, and if there is, // check whether its evaluated return type is the same as the one corresponding @@ -2897,12 +2894,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } } let point_at_chain = |expr: &hir::Expr<'_>| { + let mut assocs = vec![]; + // We still want to point at the different methods even if there hasn't + // been a change of assoc type. + let mut call_spans = vec![]; let mut expr = expr; let mut prev_ty = self.resolve_vars_if_possible( typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error()), ); - let outer_ty = prev_ty; - let mut assoc_seen = 0; while let hir::ExprKind::MethodCall(_path_segment, rcvr_expr, _args, span) = expr.kind { @@ -2910,12 +2909,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // vec![1, 2, 3].iter().map(mapper).sum() // ^^^^^^ ^^^^^^^^^^^ expr = rcvr_expr; + let mut assocs_in_this_method = Vec::with_capacity(type_diffs.len()); + call_spans.push(span); let ocx = ObligationCtxt::new_in_snapshot(self.infcx); for diff in &type_diffs { let Sorts(expected_found) = diff else { continue; }; let ty::Projection(proj) = expected_found.expected.kind() else { continue; }; - assoc_seen += 1; let origin = TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, @@ -2963,23 +2963,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if ocx.select_where_possible().is_empty() { // `ty_var` now holds the type that `Item` is for `ExprTy`. let assoc = self.tcx.def_path_str(proj.item_def_id); - multi_span.push_span_label( - span, - &format!( - "associated type `{assoc}` is `{}` here", - self.resolve_vars_if_possible(ty_var), - ), - ); + let ty_var = self.resolve_vars_if_possible(ty_var); + assocs_in_this_method.push(Some((span, (assoc, ty_var)))); } else { // `` didn't select, so likely we've // reached the end of the iterator chain, like the originating // `Vec<_>`. - multi_span.push_span_label( - span, - format!("this call has type `{prev_ty}`"), - ); + // Keep the space consistent for later zipping. + assocs_in_this_method.push(None); } } + assocs.push(assocs_in_this_method); prev_ty = self.resolve_vars_if_possible( typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error()), ); @@ -2992,17 +2986,65 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // Point at the root expression // vec![1, 2, 3].iter().map(mapper).sum() // ^^^^^^^^^^^^^ - multi_span.push_span_label( - expr.span, - format!("this expression has type `{ty}`"), - ); + span_labels + .push((expr.span, format!("this expression has type `{ty}`"))); }; - if assoc_seen > 0 { - // Only show this if it is not a "trivial" expression (not a method - // chain) and there are associated types to talk about. + // Only show this if it is not a "trivial" expression (not a method + // chain) and there are associated types to talk about. + let mut assocs = assocs.into_iter().peekable(); + while let Some(assocs_in_method) = assocs.next() { + let Some(prev_assoc_in_method) = assocs.peek() else { + for entry in assocs_in_method { + let Some((span, (assoc, ty))) = entry else { continue; }; + primary_spans.push(span); + span_labels.push(( + span, + format!("associated type `{assoc}` is `{ty}` here"), + )); + } + break; + }; + for (entry, prev_entry) in + assocs_in_method.into_iter().zip(prev_assoc_in_method.into_iter()) + { + match (entry, prev_entry) { + (Some((span, (assoc, ty))), Some((_, (_, prev_ty)))) => { + if ty != *prev_ty { + primary_spans.push(span); + span_labels.push(( + span, + format!("associated type `{assoc}` changed to `{ty}` here"), + )); + } + } + (Some((span, (assoc, ty))), None) => { + span_labels.push(( + span, + format!("associated type `{assoc}` is `{ty}` here"), + )); + } + (None, Some(_)) | (None, None) => {} + } + } + } + for span in call_spans { + if span_labels.iter().find(|(s, _)| *s == span).is_none() { + // Ensure we are showing the entire chain, even if the assoc types + // haven't changed. + span_labels.push((span, String::new())); + } + } + if !primary_spans.is_empty() { + let mut multi_span: MultiSpan = primary_spans.into(); + for (span, label) in span_labels { + multi_span.push_span_label(span, label); + } err.span_note( multi_span, - format!("the expression is of type `{outer_ty}`"), + format!( + "the method call chain might not have had the expected \ + associated types", + ), ); } }; diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index 5e84dcdef30..eca961633dc 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -22,11 +22,11 @@ LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_rece | = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` = help: the trait `FromIterator` is implemented for `Vec` -note: the expression is of type `Map, [closure@$DIR/issue-34334.rs:5:47: 5:82]>` - --> $DIR/issue-34334.rs:5:43 +note: the method call chain might not have had the expected associated types + --> $DIR/issue-34334.rs:5:36 | LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); - | -- ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here + | -- ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here | | | | | associated type `std::iter::Iterator::Item` is `&(_, _, _)` here | this expression has type `Vec<(_, _, _)>` diff --git a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr index 5ee287b1b15..7f97b5bfcbe 100644 --- a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -8,7 +8,7 @@ LL | let x2: Vec = x1.into_iter().collect(); | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` -note: the expression is of type `std::slice::Iter<'_, f64>` +note: the method call chain might not have had the expected associated types --> $DIR/issue-66923-show-error-for-correct-call.rs:8:27 | LL | let x2: Vec = x1.into_iter().collect(); @@ -31,7 +31,7 @@ LL | let x3 = x1.into_iter().collect::>(); | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` -note: the expression is of type `std::slice::Iter<'_, f64>` +note: the method call chain might not have had the expected associated types --> $DIR/issue-66923-show-error-for-correct-call.rs:12:17 | LL | let x3 = x1.into_iter().collect::>(); diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 0b3e0653864..57be01a2442 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -9,20 +9,18 @@ LL | println!("{}", scores.sum::()); = help: the following other types implement trait `Sum`: > -note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:4:14: 4:22]>` - --> $DIR/invalid-iterator-chain.rs:7:20 +note: the method call chain might not have had the expected associated types + --> $DIR/invalid-iterator-chain.rs:3:10 | LL | let scores = vec![(0, 0)] | ------------ this expression has type `Vec<({integer}, {integer})>` LL | .iter() - | ------ associated type `std::iter::Iterator::Item` is `&({integer}, {integer})` here + | ^^^^^^ associated type `std::iter::Iterator::Item` is `&({integer}, {integer})` here LL | .map(|(a, b)| { - | __________- + | __________^ LL | | a + b; LL | | }); - | |__________- associated type `std::iter::Iterator::Item` is `()` here -LL | println!("{}", scores.sum::()); - | ^^^^^^ + | |__________^ associated type `std::iter::Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -46,25 +44,25 @@ LL | .sum::(), = help: the following other types implement trait `Sum`: > -note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>, [closure@$DIR/invalid-iterator-chain.rs:13:18: 13:21]>, [closure@$DIR/invalid-iterator-chain.rs:14:18: 14:21]>, [closure@$DIR/invalid-iterator-chain.rs:15:21: 15:24]>, [closure@$DIR/invalid-iterator-chain.rs:16:18: 16:21]>, [closure@$DIR/invalid-iterator-chain.rs:17:18: 17:21]>` - --> $DIR/invalid-iterator-chain.rs:17:14 +note: the method call chain might not have had the expected associated types + --> $DIR/invalid-iterator-chain.rs:11:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() - | ------ associated type `std::iter::Iterator::Item` is `&{integer}` here + | ^^^^^^ associated type `std::iter::Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) - | -------------- associated type `std::iter::Iterator::Item` is `{integer}` here + | ^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) - | ----------------- associated type `std::iter::Iterator::Item` is `f64` here + | ^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `f64` here LL | .map(|x| x as i64) - | ----------------- associated type `std::iter::Iterator::Item` is `i64` here + | ^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `i64` here LL | .filter(|x| *x > 0) - | ------------------ associated type `std::iter::Iterator::Item` is `i64` here + | ------------------ LL | .map(|x| { x + 1 }) - | ------------------ associated type `std::iter::Iterator::Item` is `i64` here + | ------------------ LL | .map(|x| { x; }) - | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here + | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -82,11 +80,11 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); = help: the following other types implement trait `Sum`: > -note: the expression is of type `Map, [closure@$DIR/invalid-iterator-chain.rs:20:42: 20:45]>` - --> $DIR/invalid-iterator-chain.rs:20:38 +note: the method call chain might not have had the expected associated types + --> $DIR/invalid-iterator-chain.rs:20:31 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); - | ---------- ------ ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here + | ---------- ^^^^^^ ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here | | | | | associated type `std::iter::Iterator::Item` is `&{integer}` here | this expression has type `Vec<{integer}>` @@ -107,7 +105,7 @@ LL | println!("{}", vec![(), ()].iter().sum::()); = help: the following other types implement trait `Sum`: > -note: the expression is of type `std::slice::Iter<'_, ()>` +note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:21:33 | LL | println!("{}", vec![(), ()].iter().sum::()); -- cgit 1.4.1-3-g733a5 From 71db025cfa85ea3c1e7d628f4c596ca498c7acf0 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Wed, 7 Dec 2022 11:11:06 -0800 Subject: Account for method call chains split across multiple bindings --- .../src/traits/error_reporting/suggestions.rs | 12 ++++++++ src/test/ui/issues/issue-34334.stderr | 10 +++--- .../issue-66923-show-error-for-correct-call.stderr | 13 ++++---- src/test/ui/iterators/invalid-iterator-chain.rs | 9 ++++++ .../ui/iterators/invalid-iterator-chain.stderr | 36 +++++++++++++++++++++- 5 files changed, 69 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 2f9b8c21071..87ab863fa7b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2977,6 +2977,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { prev_ty = self.resolve_vars_if_possible( typeck_results.expr_ty_adjusted_opt(expr).unwrap_or(tcx.ty_error()), ); + + if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind + && let hir::Path { res: hir::def::Res::Local(hir_id), .. } = path + && let Some(hir::Node::Pat(binding)) = self.tcx.hir().find(*hir_id) + && let parent_hir_id = self.tcx.hir().get_parent_node(binding.hir_id) + && let Some(hir::Node::Local(local)) = self.tcx.hir().find(parent_hir_id) + && let Some(binding_expr) = local.init + { + // We've reached the root of the method call chain and it is a + // binding. Get the binding creation and try to continue the chain. + expr = binding_expr; + } } // We want the type before deref coercions, otherwise we talk about `&[_]` diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index eca961633dc..89f5c45d7a9 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -25,11 +25,13 @@ LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_rece note: the method call chain might not have had the expected associated types --> $DIR/issue-34334.rs:5:36 | +LL | let sr: Vec<(u32, _, _) = vec![]; + | ------ this expression has type `Vec<(_, _, _)>` +... LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); - | -- ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here - | | | - | | associated type `std::iter::Iterator::Item` is `&(_, _, _)` here - | this expression has type `Vec<(_, _, _)>` + | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here + | | + | associated type `std::iter::Iterator::Item` is `&(_, _, _)` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr index 7f97b5bfcbe..7fe786dcfb5 100644 --- a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -11,10 +11,10 @@ LL | let x2: Vec = x1.into_iter().collect(); note: the method call chain might not have had the expected associated types --> $DIR/issue-66923-show-error-for-correct-call.rs:8:27 | +LL | let x1: &[f64] = &v; + | -- this expression has type `&Vec` LL | let x2: Vec = x1.into_iter().collect(); - | -- ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here - | | - | this expression has type `&[f64]` + | ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -34,10 +34,11 @@ LL | let x3 = x1.into_iter().collect::>(); note: the method call chain might not have had the expected associated types --> $DIR/issue-66923-show-error-for-correct-call.rs:12:17 | +LL | let x1: &[f64] = &v; + | -- this expression has type `&Vec` +... LL | let x3 = x1.into_iter().collect::>(); - | -- ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here - | | - | this expression has type `&[f64]` + | ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/iterators/invalid-iterator-chain.rs b/src/test/ui/iterators/invalid-iterator-chain.rs index 3d4801b3732..e17b471b692 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.rs +++ b/src/test/ui/iterators/invalid-iterator-chain.rs @@ -19,4 +19,13 @@ fn main() { ); println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); //~ ERROR E0277 println!("{}", vec![(), ()].iter().sum::()); //~ ERROR E0277 + let a = vec![0]; + let b = a.into_iter(); + let c = b.map(|x| x + 1); + let d = c.filter(|x| *x > 10 ); + let e = d.map(|x| { + x + 1; + }); + let f = e.filter(|_| false); + let g: Vec = f.collect(); //~ ERROR E0277 } diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 57be01a2442..8bf7eb93a72 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -118,6 +118,40 @@ note: required by a bound in `std::iter::Iterator::sum` LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` -error: aborting due to 4 previous errors +error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `()` + --> $DIR/invalid-iterator-chain.rs:30:23 + | +LL | let g: Vec = f.collect(); + | ^ ------- required by a bound introduced by this call + | | + | value of type `Vec` cannot be built from `std::iter::Iterator` + | + = help: the trait `FromIterator<()>` is not implemented for `Vec` + = help: the trait `FromIterator` is implemented for `Vec` +note: the method call chain might not have had the expected associated types + --> $DIR/invalid-iterator-chain.rs:23:15 + | +LL | let a = vec![0]; + | ------- this expression has type `Vec<{integer}>` +LL | let b = a.into_iter(); + | ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `{integer}` here +LL | let c = b.map(|x| x + 1); + | -------------- +LL | let d = c.filter(|x| *x > 10 ); + | -------------------- +LL | let e = d.map(|x| { + | _______________^ +LL | | x + 1; +LL | | }); + | |______^ associated type `std::iter::Iterator::Item` changed to `()` here +LL | let f = e.filter(|_| false); + | ----------------- +note: required by a bound in `collect` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | fn collect>(self) -> B + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From c77ad2d76576b97f6b2ea8c8b5ddb672c3383512 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Wed, 7 Dec 2022 11:32:26 -0800 Subject: Remove mention of "assoc type" in label as it is already in the `note` message --- .../src/traits/error_reporting/suggestions.rs | 12 +++++------ src/test/ui/issues/issue-34334.stderr | 4 ++-- .../issue-66923-show-error-for-correct-call.stderr | 4 ++-- .../ui/iterators/invalid-iterator-chain.stderr | 24 +++++++++++----------- 4 files changed, 21 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 87ab863fa7b..bef2a067ae3 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3011,7 +3011,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { primary_spans.push(span); span_labels.push(( span, - format!("associated type `{assoc}` is `{ty}` here"), + format!("`{assoc}` is `{ty}` here"), )); } break; @@ -3025,15 +3025,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { primary_spans.push(span); span_labels.push(( span, - format!("associated type `{assoc}` changed to `{ty}` here"), + format!("`{assoc}` changed to `{ty}` here"), )); } } (Some((span, (assoc, ty))), None) => { - span_labels.push(( - span, - format!("associated type `{assoc}` is `{ty}` here"), - )); + span_labels + .push((span, format!("`{assoc}` is `{ty}` here"))); } (None, Some(_)) | (None, None) => {} } @@ -3055,7 +3053,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { multi_span, format!( "the method call chain might not have had the expected \ - associated types", + associated types", ), ); } diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index 89f5c45d7a9..ac3b3e95faf 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -29,9 +29,9 @@ LL | let sr: Vec<(u32, _, _) = vec![]; | ------ this expression has type `Vec<(_, _, _)>` ... LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here + | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here | | - | associated type `std::iter::Iterator::Item` is `&(_, _, _)` here + | `std::iter::Iterator::Item` is `&(_, _, _)` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr index 7fe786dcfb5..9a560c631fe 100644 --- a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types LL | let x1: &[f64] = &v; | -- this expression has type `&Vec` LL | let x2: Vec = x1.into_iter().collect(); - | ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here + | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -38,7 +38,7 @@ LL | let x1: &[f64] = &v; | -- this expression has type `&Vec` ... LL | let x3 = x1.into_iter().collect::>(); - | ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `&f64` here + | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 8bf7eb93a72..0505dd86af3 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -15,12 +15,12 @@ note: the method call chain might not have had the expected associated types LL | let scores = vec![(0, 0)] | ------------ this expression has type `Vec<({integer}, {integer})>` LL | .iter() - | ^^^^^^ associated type `std::iter::Iterator::Item` is `&({integer}, {integer})` here + | ^^^^^^ `std::iter::Iterator::Item` is `&({integer}, {integer})` here LL | .map(|(a, b)| { | __________^ LL | | a + b; LL | | }); - | |__________^ associated type `std::iter::Iterator::Item` changed to `()` here + | |__________^ `std::iter::Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -50,19 +50,19 @@ note: the method call chain might not have had the expected associated types LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() - | ^^^^^^ associated type `std::iter::Iterator::Item` is `&{integer}` here + | ^^^^^^ `std::iter::Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) - | ^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `{integer}` here + | ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) - | ^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `f64` here + | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `f64` here LL | .map(|x| x as i64) - | ^^^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `i64` here + | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `i64` here LL | .filter(|x| *x > 0) | ------------------ LL | .map(|x| { x + 1 }) | ------------------ LL | .map(|x| { x; }) - | ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here + | ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -84,9 +84,9 @@ note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:20:31 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); - | ---------- ^^^^^^ ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` changed to `()` here + | ---------- ^^^^^^ ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here | | | - | | associated type `std::iter::Iterator::Item` is `&{integer}` here + | | `std::iter::Iterator::Item` is `&{integer}` here | this expression has type `Vec<{integer}>` note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL @@ -109,7 +109,7 @@ note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:21:33 | LL | println!("{}", vec![(), ()].iter().sum::()); - | ------------ ^^^^^^ associated type `std::iter::Iterator::Item` is `&()` here + | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here | | | this expression has type `Vec<()>` note: required by a bound in `std::iter::Iterator::sum` @@ -134,7 +134,7 @@ note: the method call chain might not have had the expected associated types LL | let a = vec![0]; | ------- this expression has type `Vec<{integer}>` LL | let b = a.into_iter(); - | ^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `{integer}` here + | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `{integer}` here LL | let c = b.map(|x| x + 1); | -------------- LL | let d = c.filter(|x| *x > 10 ); @@ -143,7 +143,7 @@ LL | let e = d.map(|x| { | _______________^ LL | | x + 1; LL | | }); - | |______^ associated type `std::iter::Iterator::Item` changed to `()` here + | |______^ `std::iter::Iterator::Item` changed to `()` here LL | let f = e.filter(|_| false); | ----------------- note: required by a bound in `collect` -- cgit 1.4.1-3-g733a5 From aff0ab43c8fecbf9473d60d30e5d03f8612efd91 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Wed, 7 Dec 2022 12:25:49 -0800 Subject: Add label to method chains where assoc type remains the same --- .../src/traits/error_reporting/suggestions.rs | 5 +++++ src/test/ui/iterators/invalid-iterator-chain.stderr | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index bef2a067ae3..1d6e749b9e3 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3027,6 +3027,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { span, format!("`{assoc}` changed to `{ty}` here"), )); + } else { + span_labels.push(( + span, + format!("`{assoc}` remains `{ty}` here"), + )); } } (Some((span, (assoc, ty))), None) => { diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 0505dd86af3..14e430726f6 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -58,9 +58,9 @@ LL | .map(|x| x as f64) LL | .map(|x| x as i64) | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `i64` here LL | .filter(|x| *x > 0) - | ------------------ + | ------------------ `std::iter::Iterator::Item` remains `i64` here LL | .map(|x| { x + 1 }) - | ------------------ + | ------------------ `std::iter::Iterator::Item` remains `i64` here LL | .map(|x| { x; }) | ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` @@ -136,16 +136,16 @@ LL | let a = vec![0]; LL | let b = a.into_iter(); | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `{integer}` here LL | let c = b.map(|x| x + 1); - | -------------- + | -------------- `std::iter::Iterator::Item` remains `{integer}` here LL | let d = c.filter(|x| *x > 10 ); - | -------------------- + | -------------------- `std::iter::Iterator::Item` remains `{integer}` here LL | let e = d.map(|x| { | _______________^ LL | | x + 1; LL | | }); | |______^ `std::iter::Iterator::Item` changed to `()` here LL | let f = e.filter(|_| false); - | ----------------- + | ----------------- `std::iter::Iterator::Item` remains `()` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | -- cgit 1.4.1-3-g733a5 From 78f97595a3e7ef9d796b77cd5572676a1a41fb71 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Wed, 7 Dec 2022 14:16:37 -0800 Subject: Only point at methods that might be relevant --- .../src/traits/error_reporting/suggestions.rs | 19 +++++- src/test/ui/issues/issue-34334.stderr | 4 +- src/test/ui/iterators/invalid-iterator-chain.rs | 10 ++++ .../ui/iterators/invalid-iterator-chain.stderr | 67 +++++++++++++++++----- 4 files changed, 81 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 1d6e749b9e3..cfd7c20767f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3008,7 +3008,17 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let Some(prev_assoc_in_method) = assocs.peek() else { for entry in assocs_in_method { let Some((span, (assoc, ty))) = entry else { continue; }; - primary_spans.push(span); + if type_diffs.iter().any(|diff| { + let Sorts(expected_found) = diff else { return false; }; + self.can_eq(param_env, expected_found.found, ty).is_ok() + }) { + // FIXME: this doesn't quite work for `Iterator::collect` + // because we have `Vec` and `()`, but we'd want `i32` + // to point at the `.into_iter()` call, but as long as we + // still point at the other method calls that might have + // introduced the issue, this is fine for now. + primary_spans.push(span); + } span_labels.push(( span, format!("`{assoc}` is `{ty}` here"), @@ -3022,7 +3032,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { match (entry, prev_entry) { (Some((span, (assoc, ty))), Some((_, (_, prev_ty)))) => { if ty != *prev_ty { - primary_spans.push(span); + if type_diffs.iter().any(|diff| { + let Sorts(expected_found) = diff else { return false; }; + self.can_eq(param_env, expected_found.found, ty).is_ok() + }) { + primary_spans.push(span); + } span_labels.push(( span, format!("`{assoc}` changed to `{ty}` here"), diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index ac3b3e95faf..688a532adc6 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -23,13 +23,13 @@ LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_rece = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` = help: the trait `FromIterator` is implemented for `Vec` note: the method call chain might not have had the expected associated types - --> $DIR/issue-34334.rs:5:36 + --> $DIR/issue-34334.rs:5:43 | LL | let sr: Vec<(u32, _, _) = vec![]; | ------ this expression has type `Vec<(_, _, _)>` ... LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); - | ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here + | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here | | | `std::iter::Iterator::Item` is `&(_, _, _)` here note: required by a bound in `collect` diff --git a/src/test/ui/iterators/invalid-iterator-chain.rs b/src/test/ui/iterators/invalid-iterator-chain.rs index e17b471b692..32141bf0fb8 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.rs +++ b/src/test/ui/iterators/invalid-iterator-chain.rs @@ -17,6 +17,16 @@ fn main() { .map(|x| { x; }) .sum::(), ); + println!( + "{}", + vec![0, 1] //~ ERROR E0277 + .iter() + .map(|x| x * 2) + .map(|x| x as f64) + .filter(|x| *x > 0.0) + .map(|x| { x + 1.0 }) + .sum::(), + ); println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); //~ ERROR E0277 println!("{}", vec![(), ()].iter().sum::()); //~ ERROR E0277 let a = vec![0]; diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 14e430726f6..55788ae80e6 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -10,12 +10,12 @@ LL | println!("{}", scores.sum::()); > note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:3:10 + --> $DIR/invalid-iterator-chain.rs:4:10 | LL | let scores = vec![(0, 0)] | ------------ this expression has type `Vec<({integer}, {integer})>` LL | .iter() - | ^^^^^^ `std::iter::Iterator::Item` is `&({integer}, {integer})` here + | ------ `std::iter::Iterator::Item` is `&({integer}, {integer})` here LL | .map(|(a, b)| { | __________^ LL | | a + b; @@ -45,18 +45,18 @@ LL | .sum::(), > note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:11:14 + --> $DIR/invalid-iterator-chain.rs:12:14 | LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() - | ^^^^^^ `std::iter::Iterator::Item` is `&{integer}` here + | ------ `std::iter::Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) | ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) - | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `f64` here + | ----------------- `std::iter::Iterator::Item` changed to `f64` here LL | .map(|x| x as i64) - | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `i64` here + | ----------------- `std::iter::Iterator::Item` changed to `i64` here LL | .filter(|x| *x > 0) | ------------------ `std::iter::Iterator::Item` remains `i64` here LL | .map(|x| { x + 1 }) @@ -69,8 +69,45 @@ note: required by a bound in `std::iter::Iterator::sum` LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` +error[E0277]: the trait bound `i32: Sum` is not satisfied + --> $DIR/invalid-iterator-chain.rs:22:9 + | +LL | / vec![0, 1] +LL | | .iter() +LL | | .map(|x| x * 2) +LL | | .map(|x| x as f64) +LL | | .filter(|x| *x > 0.0) +LL | | .map(|x| { x + 1.0 }) + | |_________________________________^ the trait `Sum` is not implemented for `i32` +LL | .sum::(), + | --- required by a bound introduced by this call + | + = help: the following other types implement trait `Sum`: + > + +note: the method call chain might not have had the expected associated types + --> $DIR/invalid-iterator-chain.rs:24:14 + | +LL | vec![0, 1] + | ---------- this expression has type `Vec<{integer}>` +LL | .iter() + | ------ `std::iter::Iterator::Item` is `&{integer}` here +LL | .map(|x| x * 2) + | ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here +LL | .map(|x| x as f64) + | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `f64` here +LL | .filter(|x| *x > 0.0) + | -------------------- `std::iter::Iterator::Item` remains `f64` here +LL | .map(|x| { x + 1.0 }) + | -------------------- `std::iter::Iterator::Item` remains `f64` here +note: required by a bound in `std::iter::Iterator::sum` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + | +LL | S: Sum, + | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + error[E0277]: the trait bound `i32: Sum<()>` is not satisfied - --> $DIR/invalid-iterator-chain.rs:20:20 + --> $DIR/invalid-iterator-chain.rs:30:20 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call @@ -81,10 +118,10 @@ LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); > note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:20:31 + --> $DIR/invalid-iterator-chain.rs:30:38 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); - | ---------- ^^^^^^ ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here + | ---------- ------ ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here | | | | | `std::iter::Iterator::Item` is `&{integer}` here | this expression has type `Vec<{integer}>` @@ -95,7 +132,7 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` error[E0277]: the trait bound `i32: Sum<&()>` is not satisfied - --> $DIR/invalid-iterator-chain.rs:21:20 + --> $DIR/invalid-iterator-chain.rs:31:20 | LL | println!("{}", vec![(), ()].iter().sum::()); | ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call @@ -106,7 +143,7 @@ LL | println!("{}", vec![(), ()].iter().sum::()); > note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:21:33 + --> $DIR/invalid-iterator-chain.rs:31:33 | LL | println!("{}", vec![(), ()].iter().sum::()); | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here @@ -119,7 +156,7 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:30:23 + --> $DIR/invalid-iterator-chain.rs:40:23 | LL | let g: Vec = f.collect(); | ^ ------- required by a bound introduced by this call @@ -129,12 +166,12 @@ LL | let g: Vec = f.collect(); = help: the trait `FromIterator<()>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` note: the method call chain might not have had the expected associated types - --> $DIR/invalid-iterator-chain.rs:23:15 + --> $DIR/invalid-iterator-chain.rs:36:15 | LL | let a = vec![0]; | ------- this expression has type `Vec<{integer}>` LL | let b = a.into_iter(); - | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `{integer}` here + | ----------- `std::iter::Iterator::Item` is `{integer}` here LL | let c = b.map(|x| x + 1); | -------------- `std::iter::Iterator::Item` remains `{integer}` here LL | let d = c.filter(|x| *x > 10 ); @@ -152,6 +189,6 @@ note: required by a bound in `collect` LL | fn collect>(self) -> B | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0277`. -- cgit 1.4.1-3-g733a5 From 8d9ffa379e2b6e0d8f4813c035daf6c567887c1e Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sat, 10 Dec 2022 19:08:59 -0800 Subject: fix rebase --- .../ui/iterators/invalid-iterator-chain.stderr | 25 +++++++++++++--------- src/test/ui/on-unimplemented/sum.stderr | 14 ++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 55788ae80e6..833a5a7474a 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -1,11 +1,12 @@ -error[E0277]: the trait bound `i32: Sum<()>` is not satisfied +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` --> $DIR/invalid-iterator-chain.rs:7:20 | LL | println!("{}", scores.sum::()); | ^^^^^^ --- required by a bound introduced by this call | | - | the trait `Sum<()>` is not implemented for `i32` + | value of type `i32` cannot be made by summing a `std::iter::Iterator` | + = help: the trait `Sum<()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: > @@ -27,7 +28,7 @@ note: required by a bound in `std::iter::Iterator::sum` LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` -error[E0277]: the trait bound `i32: Sum<()>` is not satisfied +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` --> $DIR/invalid-iterator-chain.rs:10:9 | LL | / vec![0, 1] @@ -37,10 +38,11 @@ LL | | .map(|x| x as f64) ... | LL | | .map(|x| { x + 1 }) LL | | .map(|x| { x; }) - | |____________________________^ the trait `Sum<()>` is not implemented for `i32` + | |____________________________^ value of type `i32` cannot be made by summing a `std::iter::Iterator` LL | .sum::(), | --- required by a bound introduced by this call | + = help: the trait `Sum<()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: > @@ -69,7 +71,7 @@ note: required by a bound in `std::iter::Iterator::sum` LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` -error[E0277]: the trait bound `i32: Sum` is not satisfied +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64` --> $DIR/invalid-iterator-chain.rs:22:9 | LL | / vec![0, 1] @@ -78,10 +80,11 @@ LL | | .map(|x| x * 2) LL | | .map(|x| x as f64) LL | | .filter(|x| *x > 0.0) LL | | .map(|x| { x + 1.0 }) - | |_________________________________^ the trait `Sum` is not implemented for `i32` + | |_________________________________^ value of type `i32` cannot be made by summing a `std::iter::Iterator` LL | .sum::(), | --- required by a bound introduced by this call | + = help: the trait `Sum` is not implemented for `i32` = help: the following other types implement trait `Sum`: > @@ -106,14 +109,15 @@ note: required by a bound in `std::iter::Iterator::sum` LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` -error[E0277]: the trait bound `i32: Sum<()>` is not satisfied +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` --> $DIR/invalid-iterator-chain.rs:30:20 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call | | - | the trait `Sum<()>` is not implemented for `i32` + | value of type `i32` cannot be made by summing a `std::iter::Iterator` | + = help: the trait `Sum<()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: > @@ -131,14 +135,15 @@ note: required by a bound in `std::iter::Iterator::sum` LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` -error[E0277]: the trait bound `i32: Sum<&()>` is not satisfied +error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()` --> $DIR/invalid-iterator-chain.rs:31:20 | LL | println!("{}", vec![(), ()].iter().sum::()); | ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call | | - | the trait `Sum<&()>` is not implemented for `i32` + | value of type `i32` cannot be made by summing a `std::iter::Iterator` | + = help: the trait `Sum<&()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: > diff --git a/src/test/ui/on-unimplemented/sum.stderr b/src/test/ui/on-unimplemented/sum.stderr index c3103671178..6405be01e67 100644 --- a/src/test/ui/on-unimplemented/sum.stderr +++ b/src/test/ui/on-unimplemented/sum.stderr @@ -10,6 +10,13 @@ LL | vec![(), ()].iter().sum::(); = help: the following other types implement trait `Sum`: > +note: the method call chain might not have had the expected associated types + --> $DIR/sum.rs:4:18 + | +LL | vec![(), ()].iter().sum::(); + | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here + | | + | this expression has type `Vec<()>` note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -28,6 +35,13 @@ LL | vec![(), ()].iter().product::(); = help: the following other types implement trait `Product`: > +note: the method call chain might not have had the expected associated types + --> $DIR/sum.rs:7:18 + | +LL | vec![(), ()].iter().product::(); + | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here + | | + | this expression has type `Vec<()>` note: required by a bound in `std::iter::Iterator::product` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | -- cgit 1.4.1-3-g733a5 From ce486d538b909658f72d6016dae758f075089d3c Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sun, 11 Dec 2022 11:38:43 -0800 Subject: Use `with_forced_trimmed_paths` --- .../src/traits/error_reporting/suggestions.rs | 41 +++++++++++----- .../malformed_closure/ruby_style_closure.stderr | 2 +- src/test/ui/issues/issue-34334.stderr | 4 +- .../issue-66923-show-error-for-correct-call.stderr | 4 +- .../ui/iterators/invalid-iterator-chain.stderr | 56 +++++++++++----------- .../feature-gate-never_type_fallback.stderr | 2 +- src/test/ui/on-unimplemented/sum.stderr | 4 +- 7 files changed, 64 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index cfd7c20767f..adc64463b3b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -2394,12 +2394,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { err.note("only the last element of a tuple may have a dynamically sized type"); } ObligationCauseCode::ProjectionWf(data) => { - err.note(&format!("required so that the projection `{}` is well-formed", data,)); + err.note(&format!("required so that the projection `{data}` is well-formed")); } ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => { err.note(&format!( - "required so that reference `{}` does not outlive its referent", - ref_ty, + "required so that reference `{ref_ty}` does not outlive its referent" )); } ObligationCauseCode::ObjectTypeBound(object_ty, region) => { @@ -2859,7 +2858,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if ty.references_error() { String::new() } else { - format!("this tail expression is of type `{:?}`", ty) + let ty = with_forced_trimmed_paths!(self.ty_to_string(ty)); + format!("this tail expression is of type `{ty}`") }, ); } @@ -2962,9 +2962,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { )); if ocx.select_where_possible().is_empty() { // `ty_var` now holds the type that `Item` is for `ExprTy`. - let assoc = self.tcx.def_path_str(proj.item_def_id); let ty_var = self.resolve_vars_if_possible(ty_var); - assocs_in_this_method.push(Some((span, (assoc, ty_var)))); + assocs_in_this_method + .push(Some((span, (proj.item_def_id, ty_var)))); } else { // `` didn't select, so likely we've // reached the end of the iterator chain, like the originating @@ -2994,7 +2994,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // We want the type before deref coercions, otherwise we talk about `&[_]` // instead of `Vec<_>`. if let Some(ty) = typeck_results.expr_ty_opt(expr) { - let ty = self.resolve_vars_if_possible(ty); + let ty = with_forced_trimmed_paths!(self.ty_to_string(ty)); // Point at the root expression // vec![1, 2, 3].iter().map(mapper).sum() // ^^^^^^^^^^^^^ @@ -3021,7 +3021,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } span_labels.push(( span, - format!("`{assoc}` is `{ty}` here"), + with_forced_trimmed_paths!(format!( + "`{}` is `{ty}` here", + self.tcx.def_path_str(assoc), + )), )); } break; @@ -3031,6 +3034,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { { match (entry, prev_entry) { (Some((span, (assoc, ty))), Some((_, (_, prev_ty)))) => { + let ty_str = + with_forced_trimmed_paths!(self.ty_to_string(ty)); + + let assoc = with_forced_trimmed_paths!( + self.tcx.def_path_str(assoc) + ); if ty != *prev_ty { if type_diffs.iter().any(|diff| { let Sorts(expected_found) = diff else { return false; }; @@ -3040,18 +3049,24 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } span_labels.push(( span, - format!("`{assoc}` changed to `{ty}` here"), + format!("`{assoc}` changed to `{ty_str}` here"), )); } else { span_labels.push(( span, - format!("`{assoc}` remains `{ty}` here"), + format!("`{assoc}` remains `{ty_str}` here"), )); } } (Some((span, (assoc, ty))), None) => { - span_labels - .push((span, format!("`{assoc}` is `{ty}` here"))); + span_labels.push(( + span, + with_forced_trimmed_paths!(format!( + "`{}` is `{}` here", + self.tcx.def_path_str(assoc), + self.ty_to_string(ty), + )), + )); } (None, Some(_)) | (None, None) => {} } @@ -3151,7 +3166,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } ObligationCauseCode::OpaqueReturnType(expr_info) => { if let Some((expr_ty, expr_span)) = expr_info { - let expr_ty = self.resolve_vars_if_possible(expr_ty); + let expr_ty = with_forced_trimmed_paths!(self.ty_to_string(expr_ty)); err.span_label( expr_span, format!("return type was inferred to be `{expr_ty}` here"), diff --git a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr index 759d79493a9..c7ed8e0de38 100644 --- a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr +++ b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr @@ -14,7 +14,7 @@ LL | let p = Some(45).and_then({ LL | | LL | | |x| println!("doubling {}", x); LL | | Some(x * 2) - | | ----------- this tail expression is of type `std::option::Option<_>` + | | ----------- this tail expression is of type `Option<_>` LL | | LL | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index 688a532adc6..a86da627b7e 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -29,9 +29,9 @@ LL | let sr: Vec<(u32, _, _) = vec![]; | ------ this expression has type `Vec<(_, _, _)>` ... LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); - | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here + | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here | | - | `std::iter::Iterator::Item` is `&(_, _, _)` here + | `Iterator::Item` is `&(_, _, _)` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr index 9a560c631fe..7dd135d91fb 100644 --- a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types LL | let x1: &[f64] = &v; | -- this expression has type `&Vec` LL | let x2: Vec = x1.into_iter().collect(); - | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here + | ^^^^^^^^^^^ `Iterator::Item` is `&f64` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | @@ -38,7 +38,7 @@ LL | let x1: &[f64] = &v; | -- this expression has type `&Vec` ... LL | let x3 = x1.into_iter().collect::>(); - | ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here + | ^^^^^^^^^^^ `Iterator::Item` is `&f64` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index 833a5a7474a..f8464c7ce76 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -16,17 +16,17 @@ note: the method call chain might not have had the expected associated types LL | let scores = vec![(0, 0)] | ------------ this expression has type `Vec<({integer}, {integer})>` LL | .iter() - | ------ `std::iter::Iterator::Item` is `&({integer}, {integer})` here + | ------ `Iterator::Item` is `&({integer}, {integer})` here LL | .map(|(a, b)| { | __________^ LL | | a + b; LL | | }); - | |__________^ `std::iter::Iterator::Item` changed to `()` here + | |__________^ `Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | LL | S: Sum, - | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` --> $DIR/invalid-iterator-chain.rs:10:9 @@ -52,24 +52,24 @@ note: the method call chain might not have had the expected associated types LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() - | ------ `std::iter::Iterator::Item` is `&{integer}` here + | ------ `Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) - | ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here + | ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) - | ----------------- `std::iter::Iterator::Item` changed to `f64` here + | ----------------- `Iterator::Item` changed to `f64` here LL | .map(|x| x as i64) - | ----------------- `std::iter::Iterator::Item` changed to `i64` here + | ----------------- `Iterator::Item` changed to `i64` here LL | .filter(|x| *x > 0) - | ------------------ `std::iter::Iterator::Item` remains `i64` here + | ------------------ `Iterator::Item` remains `i64` here LL | .map(|x| { x + 1 }) - | ------------------ `std::iter::Iterator::Item` remains `i64` here + | ------------------ `Iterator::Item` remains `i64` here LL | .map(|x| { x; }) - | ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here + | ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | LL | S: Sum, - | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64` --> $DIR/invalid-iterator-chain.rs:22:9 @@ -94,20 +94,20 @@ note: the method call chain might not have had the expected associated types LL | vec![0, 1] | ---------- this expression has type `Vec<{integer}>` LL | .iter() - | ------ `std::iter::Iterator::Item` is `&{integer}` here + | ------ `Iterator::Item` is `&{integer}` here LL | .map(|x| x * 2) - | ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here + | ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here LL | .map(|x| x as f64) - | ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `f64` here + | ^^^^^^^^^^^^^^^^^ `Iterator::Item` changed to `f64` here LL | .filter(|x| *x > 0.0) - | -------------------- `std::iter::Iterator::Item` remains `f64` here + | -------------------- `Iterator::Item` remains `f64` here LL | .map(|x| { x + 1.0 }) - | -------------------- `std::iter::Iterator::Item` remains `f64` here + | -------------------- `Iterator::Item` remains `f64` here note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | LL | S: Sum, - | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` --> $DIR/invalid-iterator-chain.rs:30:20 @@ -125,15 +125,15 @@ note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:30:38 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); - | ---------- ------ ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here + | ---------- ------ ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here | | | - | | `std::iter::Iterator::Item` is `&{integer}` here + | | `Iterator::Item` is `&{integer}` here | this expression has type `Vec<{integer}>` note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | LL | S: Sum, - | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()` --> $DIR/invalid-iterator-chain.rs:31:20 @@ -151,14 +151,14 @@ note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:31:33 | LL | println!("{}", vec![(), ()].iter().sum::()); - | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here + | ------------ ^^^^^^ `Iterator::Item` is `&()` here | | | this expression has type `Vec<()>` note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | LL | S: Sum, - | ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` + | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `()` --> $DIR/invalid-iterator-chain.rs:40:23 @@ -176,23 +176,23 @@ note: the method call chain might not have had the expected associated types LL | let a = vec![0]; | ------- this expression has type `Vec<{integer}>` LL | let b = a.into_iter(); - | ----------- `std::iter::Iterator::Item` is `{integer}` here + | ----------- `Iterator::Item` is `{integer}` here LL | let c = b.map(|x| x + 1); - | -------------- `std::iter::Iterator::Item` remains `{integer}` here + | -------------- `Iterator::Item` remains `{integer}` here LL | let d = c.filter(|x| *x > 10 ); - | -------------------- `std::iter::Iterator::Item` remains `{integer}` here + | -------------------- `Iterator::Item` remains `{integer}` here LL | let e = d.map(|x| { | _______________^ LL | | x + 1; LL | | }); - | |______^ `std::iter::Iterator::Item` changed to `()` here + | |______^ `Iterator::Item` changed to `()` here LL | let f = e.filter(|_| false); - | ----------------- `std::iter::Iterator::Item` remains `()` here + | ----------------- `Iterator::Item` remains `()` here note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | LL | fn collect>(self) -> B - | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` + | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect` error: aborting due to 6 previous errors diff --git a/src/test/ui/never_type/feature-gate-never_type_fallback.stderr b/src/test/ui/never_type/feature-gate-never_type_fallback.stderr index 6dc039fc35d..2db1cc4b776 100644 --- a/src/test/ui/never_type/feature-gate-never_type_fallback.stderr +++ b/src/test/ui/never_type/feature-gate-never_type_fallback.stderr @@ -5,7 +5,7 @@ LL | foo(panic!()) | --- ^^^^^^^^ | | | | | the trait `T` is not implemented for `()` - | | this tail expression is of type `_` + | | this tail expression is of type `()` | required by a bound introduced by this call | note: required by a bound in `foo` diff --git a/src/test/ui/on-unimplemented/sum.stderr b/src/test/ui/on-unimplemented/sum.stderr index 6405be01e67..c99f06da7a4 100644 --- a/src/test/ui/on-unimplemented/sum.stderr +++ b/src/test/ui/on-unimplemented/sum.stderr @@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types --> $DIR/sum.rs:4:18 | LL | vec![(), ()].iter().sum::(); - | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here + | ------------ ^^^^^^ `Iterator::Item` is `&()` here | | | this expression has type `Vec<()>` note: required by a bound in `std::iter::Iterator::sum` @@ -39,7 +39,7 @@ note: the method call chain might not have had the expected associated types --> $DIR/sum.rs:7:18 | LL | vec![(), ()].iter().product::(); - | ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here + | ------------ ^^^^^^ `Iterator::Item` is `&()` here | | | this expression has type `Vec<()>` note: required by a bound in `std::iter::Iterator::product` -- cgit 1.4.1-3-g733a5 From 2838b8e515d139245fba71895277fab26082d522 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sun, 11 Dec 2022 14:49:50 -0800 Subject: Point at method call when it is the source of the bound error --- compiler/rustc_errors/src/diagnostic.rs | 6 ++- .../src/traits/error_reporting/suggestions.rs | 10 ++++ .../generic-associated-types/issue-101020.stderr | 6 +-- src/test/ui/issues/issue-20162.stderr | 6 +-- src/test/ui/issues/issue-31173.rs | 3 +- src/test/ui/issues/issue-31173.stderr | 32 +++++-------- src/test/ui/issues/issue-33941.stderr | 6 +-- src/test/ui/issues/issue-34334.stderr | 6 +-- .../issue-66923-show-error-for-correct-call.stderr | 12 ++--- src/test/ui/iterators/collect-into-array.rs | 1 - src/test/ui/iterators/collect-into-array.stderr | 6 +-- src/test/ui/iterators/collect-into-slice.rs | 1 - src/test/ui/iterators/collect-into-slice.stderr | 6 +-- src/test/ui/iterators/invalid-iterator-chain.rs | 8 ++-- .../ui/iterators/invalid-iterator-chain.stderr | 55 +++++++--------------- .../ui/lazy-type-alias-impl-trait/branches.stderr | 6 +-- .../lazy-type-alias-impl-trait/recursion4.stderr | 12 ++--- .../method-help-unsatisfied-bound.stderr | 6 +-- src/test/ui/not-clone-closure.stderr | 6 +-- src/test/ui/on-unimplemented/sum.stderr | 12 ++--- .../const-default-method-bodies.stderr | 6 +-- .../cross-crate.gatednc.stderr | 6 +-- .../cross-crate.stocknc.stderr | 6 +-- ...fault-method-body-is-const-same-trait-ck.stderr | 6 +-- .../super-traits-fail-2.yn.stderr | 6 +-- .../super-traits-fail-2.yy.stderr | 6 +-- .../ui/suggestions/issue-71394-no-from-impl.stderr | 6 +-- src/test/ui/traits/issue-97576.stderr | 6 +-- src/test/ui/unsized/issue-71659.stderr | 6 +-- 29 files changed, 96 insertions(+), 164 deletions(-) (limited to 'src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 06bb5edc090..6bc0c261565 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -370,7 +370,11 @@ impl Diagnostic { self.set_span(after); for span_label in before.span_labels() { if let Some(label) = span_label.label { - self.span.push_span_label(after, label); + if span_label.is_primary { + self.span.push_span_label(after, label); + } else { + self.span.push_span_label(span_label.span, label); + } } } self diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index adc64463b3b..162e73faa2a 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3108,6 +3108,16 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { point_at_chain(expr); } } + let call_node = hir.find(call_hir_id); + if let Some(Node::Expr(hir::Expr { + kind: hir::ExprKind::MethodCall(path, rcvr, ..), + .. + })) = call_node + { + if Some(rcvr.span) == err.span.primary_span() { + err.replace_span_with(path.ident.span); + } + } if let Some(Node::Expr(hir::Expr { kind: hir::ExprKind::Call(hir::Expr { span, .. }, _) diff --git a/src/test/ui/generic-associated-types/issue-101020.stderr b/src/test/ui/generic-associated-types/issue-101020.stderr index b4e94cb83f7..422ac548427 100644 --- a/src/test/ui/generic-associated-types/issue-101020.stderr +++ b/src/test/ui/generic-associated-types/issue-101020.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `for<'a> &'a mut (): Foo<&'a mut ()>` is not satisfied - --> $DIR/issue-101020.rs:31:5 + --> $DIR/issue-101020.rs:31:22 | LL | (&mut EmptyIter).consume(()); - | ^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | the trait `for<'a> Foo<&'a mut ()>` is not implemented for `&'a mut ()` + | ^^^^^^^ the trait `for<'a> Foo<&'a mut ()>` is not implemented for `&'a mut ()` | note: required for `&'a mut ()` to implement `for<'a> FuncInput<'a, &'a mut ()>` --> $DIR/issue-101020.rs:27:20 diff --git a/src/test/ui/issues/issue-20162.stderr b/src/test/ui/issues/issue-20162.stderr index 3f9b3be9851..d70bf6e1d92 100644 --- a/src/test/ui/issues/issue-20162.stderr +++ b/src/test/ui/issues/issue-20162.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `X: Ord` is not satisfied - --> $DIR/issue-20162.rs:5:5 + --> $DIR/issue-20162.rs:5:7 | LL | b.sort(); - | ^ ---- required by a bound introduced by this call - | | - | the trait `Ord` is not implemented for `X` + | ^^^^ the trait `Ord` is not implemented for `X` | note: required by a bound in `slice::::sort` --> $SRC_DIR/alloc/src/slice.rs:LL:COL diff --git a/src/test/ui/issues/issue-31173.rs b/src/test/ui/issues/issue-31173.rs index 04efa27189b..f678df5b42b 100644 --- a/src/test/ui/issues/issue-31173.rs +++ b/src/test/ui/issues/issue-31173.rs @@ -4,12 +4,11 @@ pub fn get_tok(it: &mut IntoIter) { let mut found_e = false; let temp: Vec = it - //~^ ERROR to be an iterator that yields `&_`, but it yields `u8` .take_while(|&x| { found_e = true; false }) - .cloned() + .cloned() //~ ERROR to be an iterator that yields `&_`, but it yields `u8` .collect(); //~ ERROR the method } diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index 58d9b564427..62d841f3789 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -1,16 +1,8 @@ -error[E0271]: expected `TakeWhile<&mut std::vec::IntoIter, [closure@$DIR/issue-31173.rs:8:21: 8:25]>` to be an iterator that yields `&_`, but it yields `u8` - --> $DIR/issue-31173.rs:6:25 - | -LL | let temp: Vec = it - | _________________________^ -LL | | -LL | | .take_while(|&x| { -LL | | found_e = true; -LL | | false -LL | | }) - | |__________^ expected reference, found `u8` -LL | .cloned() - | ------ required by a bound introduced by this call +error[E0271]: expected `TakeWhile<&mut std::vec::IntoIter, [closure@$DIR/issue-31173.rs:7:21: 7:25]>` to be an iterator that yields `&_`, but it yields `u8` + --> $DIR/issue-31173.rs:11:10 + | +LL | .cloned() + | ^^^^^^ expected reference, found `u8` | = note: expected reference `&_` found type `u8` @@ -20,11 +12,11 @@ note: required by a bound in `cloned` LL | Self: Sized + Iterator, | ^^^^^^^^^^^^ required by this bound in `Iterator::cloned` -error[E0599]: the method `collect` exists for struct `Cloned, [closure@$DIR/issue-31173.rs:8:21: 8:25]>>`, but its trait bounds were not satisfied - --> $DIR/issue-31173.rs:13:10 +error[E0599]: the method `collect` exists for struct `Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>`, but its trait bounds were not satisfied + --> $DIR/issue-31173.rs:12:10 | LL | .collect(); - | ^^^^^^^ method cannot be called on `Cloned, [closure@$DIR/issue-31173.rs:8:21: 8:25]>>` due to unsatisfied trait bounds + | ^^^^^^^ method cannot be called on `Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>` due to unsatisfied trait bounds | ::: $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL | @@ -37,10 +29,10 @@ LL | pub struct Cloned { | -------------------- doesn't satisfy `_: Iterator` | = note: the following trait bounds were not satisfied: - `, [closure@$DIR/issue-31173.rs:8:21: 8:25]> as Iterator>::Item = &_` - which is required by `Cloned, [closure@$DIR/issue-31173.rs:8:21: 8:25]>>: Iterator` - `Cloned, [closure@$DIR/issue-31173.rs:8:21: 8:25]>>: Iterator` - which is required by `&mut Cloned, [closure@$DIR/issue-31173.rs:8:21: 8:25]>>: Iterator` + `, [closure@$DIR/issue-31173.rs:7:21: 7:25]> as Iterator>::Item = &_` + which is required by `Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` + `Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` + which is required by `&mut Cloned, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-33941.stderr b/src/test/ui/issues/issue-33941.stderr index c28986a2985..73a9b786fe2 100644 --- a/src/test/ui/issues/issue-33941.stderr +++ b/src/test/ui/issues/issue-33941.stderr @@ -1,10 +1,8 @@ error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)` - --> $DIR/issue-33941.rs:6:14 + --> $DIR/issue-33941.rs:6:36 | LL | for _ in HashMap::new().iter().cloned() {} - | ^^^^^^^^^^^^^^^^^^^^^ ------ required by a bound introduced by this call - | | - | expected reference, found tuple + | ^^^^^^ expected reference, found tuple | = note: expected reference `&_` found tuple `(&_, &_)` diff --git a/src/test/ui/issues/issue-34334.stderr b/src/test/ui/issues/issue-34334.stderr index a86da627b7e..b610e5c1366 100644 --- a/src/test/ui/issues/issue-34334.stderr +++ b/src/test/ui/issues/issue-34334.stderr @@ -13,12 +13,10 @@ LL | let sr: Vec<(u32, _, _)> = vec![]; | + error[E0277]: a value of type `Vec<(u32, _, _)>` cannot be built from an iterator over elements of type `()` - --> $DIR/issue-34334.rs:5:33 + --> $DIR/issue-34334.rs:5:87 | LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `Vec<(u32, _, _)>` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `Vec<(u32, _, _)>` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` = help: the trait `FromIterator` is implemented for `Vec` diff --git a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr index 7dd135d91fb..c6352978613 100644 --- a/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -1,10 +1,8 @@ error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `&f64` - --> $DIR/issue-66923-show-error-for-correct-call.rs:8:24 + --> $DIR/issue-66923-show-error-for-correct-call.rs:8:39 | LL | let x2: Vec = x1.into_iter().collect(); - | ^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `Vec` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` @@ -22,12 +20,10 @@ LL | fn collect>(self) -> B | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect` error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `&f64` - --> $DIR/issue-66923-show-error-for-correct-call.rs:12:14 + --> $DIR/issue-66923-show-error-for-correct-call.rs:12:29 | LL | let x3 = x1.into_iter().collect::>(); - | ^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `Vec` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` diff --git a/src/test/ui/iterators/collect-into-array.rs b/src/test/ui/iterators/collect-into-array.rs index 4c424999b75..99d0d9bd735 100644 --- a/src/test/ui/iterators/collect-into-array.rs +++ b/src/test/ui/iterators/collect-into-array.rs @@ -3,5 +3,4 @@ fn main() { //~^ ERROR an array of type `[u32; 10]` cannot be built directly from an iterator //~| NOTE try collecting into a `Vec<{integer}>`, then using `.try_into()` //~| NOTE required by a bound in `collect` - //~| NOTE required by a bound introduced by this call } diff --git a/src/test/ui/iterators/collect-into-array.stderr b/src/test/ui/iterators/collect-into-array.stderr index 544b1da178a..7a07fed1fae 100644 --- a/src/test/ui/iterators/collect-into-array.stderr +++ b/src/test/ui/iterators/collect-into-array.stderr @@ -1,10 +1,8 @@ error[E0277]: an array of type `[u32; 10]` cannot be built directly from an iterator - --> $DIR/collect-into-array.rs:2:31 + --> $DIR/collect-into-array.rs:2:39 | LL | let whatever: [u32; 10] = (0..10).collect(); - | ^^^^^^^ ------- required by a bound introduced by this call - | | - | try collecting into a `Vec<{integer}>`, then using `.try_into()` + | ^^^^^^^ try collecting into a `Vec<{integer}>`, then using `.try_into()` | = help: the trait `FromIterator<{integer}>` is not implemented for `[u32; 10]` note: required by a bound in `collect` diff --git a/src/test/ui/iterators/collect-into-slice.rs b/src/test/ui/iterators/collect-into-slice.rs index 09832c260d0..5a8aacb1a6d 100644 --- a/src/test/ui/iterators/collect-into-slice.rs +++ b/src/test/ui/iterators/collect-into-slice.rs @@ -13,6 +13,5 @@ fn main() { //~| NOTE all local variables must have a statically known size //~| NOTE doesn't have a size known at compile-time //~| NOTE doesn't have a size known at compile-time - //~| NOTE required by a bound introduced by this call process_slice(&some_generated_vec); } diff --git a/src/test/ui/iterators/collect-into-slice.stderr b/src/test/ui/iterators/collect-into-slice.stderr index 65ef124a463..58da222e039 100644 --- a/src/test/ui/iterators/collect-into-slice.stderr +++ b/src/test/ui/iterators/collect-into-slice.stderr @@ -22,12 +22,10 @@ LL | fn collect>(self) -> B | ^ required by this bound in `Iterator::collect` error[E0277]: a slice of type `[i32]` cannot be built since `[i32]` has no definite size - --> $DIR/collect-into-slice.rs:6:30 + --> $DIR/collect-into-slice.rs:6:38 | LL | let some_generated_vec = (0..10).collect(); - | ^^^^^^^ ------- required by a bound introduced by this call - | | - | try explicitly collecting into a `Vec<{integer}>` + | ^^^^^^^ try explicitly collecting into a `Vec<{integer}>` | = help: the trait `FromIterator<{integer}>` is not implemented for `[i32]` note: required by a bound in `collect` diff --git a/src/test/ui/iterators/invalid-iterator-chain.rs b/src/test/ui/iterators/invalid-iterator-chain.rs index 32141bf0fb8..87116e49245 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.rs +++ b/src/test/ui/iterators/invalid-iterator-chain.rs @@ -7,7 +7,7 @@ fn main() { println!("{}", scores.sum::()); //~ ERROR E0277 println!( "{}", - vec![0, 1] //~ ERROR E0277 + vec![0, 1] .iter() .map(|x| x * 2) .map(|x| x as f64) @@ -15,17 +15,17 @@ fn main() { .filter(|x| *x > 0) .map(|x| { x + 1 }) .map(|x| { x; }) - .sum::(), + .sum::(), //~ ERROR E0277 ); println!( "{}", - vec![0, 1] //~ ERROR E0277 + vec![0, 1] .iter() .map(|x| x * 2) .map(|x| x as f64) .filter(|x| *x > 0.0) .map(|x| { x + 1.0 }) - .sum::(), + .sum::(), //~ ERROR E0277 ); println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); //~ ERROR E0277 println!("{}", vec![(), ()].iter().sum::()); //~ ERROR E0277 diff --git a/src/test/ui/iterators/invalid-iterator-chain.stderr b/src/test/ui/iterators/invalid-iterator-chain.stderr index f8464c7ce76..49651b20fb1 100644 --- a/src/test/ui/iterators/invalid-iterator-chain.stderr +++ b/src/test/ui/iterators/invalid-iterator-chain.stderr @@ -1,10 +1,8 @@ error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:7:20 + --> $DIR/invalid-iterator-chain.rs:7:27 | LL | println!("{}", scores.sum::()); - | ^^^^^^ --- required by a bound introduced by this call - | | - | value of type `i32` cannot be made by summing a `std::iter::Iterator` + | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator` | = help: the trait `Sum<()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: @@ -29,18 +27,10 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:10:9 - | -LL | / vec![0, 1] -LL | | .iter() -LL | | .map(|x| x * 2) -LL | | .map(|x| x as f64) -... | -LL | | .map(|x| { x + 1 }) -LL | | .map(|x| { x; }) - | |____________________________^ value of type `i32` cannot be made by summing a `std::iter::Iterator` -LL | .sum::(), - | --- required by a bound introduced by this call + --> $DIR/invalid-iterator-chain.rs:18:14 + | +LL | .sum::(), + | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator` | = help: the trait `Sum<()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: @@ -72,17 +62,10 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64` - --> $DIR/invalid-iterator-chain.rs:22:9 - | -LL | / vec![0, 1] -LL | | .iter() -LL | | .map(|x| x * 2) -LL | | .map(|x| x as f64) -LL | | .filter(|x| *x > 0.0) -LL | | .map(|x| { x + 1.0 }) - | |_________________________________^ value of type `i32` cannot be made by summing a `std::iter::Iterator` -LL | .sum::(), - | --- required by a bound introduced by this call + --> $DIR/invalid-iterator-chain.rs:28:14 + | +LL | .sum::(), + | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator` | = help: the trait `Sum` is not implemented for `i32` = help: the following other types implement trait `Sum`: @@ -110,12 +93,10 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:30:20 + --> $DIR/invalid-iterator-chain.rs:30:54 | LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call - | | - | value of type `i32` cannot be made by summing a `std::iter::Iterator` + | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator` | = help: the trait `Sum<()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: @@ -136,12 +117,10 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()` - --> $DIR/invalid-iterator-chain.rs:31:20 + --> $DIR/invalid-iterator-chain.rs:31:40 | LL | println!("{}", vec![(), ()].iter().sum::()); - | ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call - | | - | value of type `i32` cannot be made by summing a `std::iter::Iterator` + | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator` | = help: the trait `Sum<&()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: @@ -161,12 +140,10 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `Vec` cannot be built from an iterator over elements of type `()` - --> $DIR/invalid-iterator-chain.rs:40:23 + --> $DIR/invalid-iterator-chain.rs:40:25 | LL | let g: Vec = f.collect(); - | ^ ------- required by a bound introduced by this call - | | - | value of type `Vec` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<()>` is not implemented for `Vec` = help: the trait `FromIterator` is implemented for `Vec` diff --git a/src/test/ui/lazy-type-alias-impl-trait/branches.stderr b/src/test/ui/lazy-type-alias-impl-trait/branches.stderr index 5a46027dd52..c66069c4d25 100644 --- a/src/test/ui/lazy-type-alias-impl-trait/branches.stderr +++ b/src/test/ui/lazy-type-alias-impl-trait/branches.stderr @@ -1,10 +1,8 @@ error[E0277]: a value of type `Bar` cannot be built from an iterator over elements of type `_` - --> $DIR/branches.rs:19:9 + --> $DIR/branches.rs:19:28 | LL | std::iter::empty().collect() - | ^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `Bar` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `Bar` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<_>` is not implemented for `Bar` note: required by a bound in `collect` diff --git a/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr b/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr index a4b4968b7d2..a92c3a6809e 100644 --- a/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr +++ b/src/test/ui/lazy-type-alias-impl-trait/recursion4.stderr @@ -1,10 +1,8 @@ error[E0277]: a value of type `Foo` cannot be built from an iterator over elements of type `_` - --> $DIR/recursion4.rs:10:9 + --> $DIR/recursion4.rs:10:28 | LL | x = std::iter::empty().collect(); - | ^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `Foo` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `Foo` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<_>` is not implemented for `Foo` note: required by a bound in `collect` @@ -14,12 +12,10 @@ LL | fn collect>(self) -> B | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect` error[E0277]: a value of type `impl Debug` cannot be built from an iterator over elements of type `_` - --> $DIR/recursion4.rs:19:9 + --> $DIR/recursion4.rs:19:28 | LL | x = std::iter::empty().collect(); - | ^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `impl Debug` cannot be built from `std::iter::Iterator` + | ^^^^^^^ value of type `impl Debug` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<_>` is not implemented for `impl Debug` note: required by a bound in `collect` diff --git a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr index 36748fae13c..c2515c40b1d 100644 --- a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr +++ b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr @@ -1,10 +1,8 @@ error[E0277]: `Foo` doesn't implement `Debug` - --> $DIR/method-help-unsatisfied-bound.rs:5:5 + --> $DIR/method-help-unsatisfied-bound.rs:5:7 | LL | a.unwrap(); - | ^ ------ required by a bound introduced by this call - | | - | `Foo` cannot be formatted using `{:?}` + | ^^^^^^ `Foo` cannot be formatted using `{:?}` | = help: the trait `Debug` is not implemented for `Foo` = note: add `#[derive(Debug)]` to `Foo` or manually `impl Debug for Foo` diff --git a/src/test/ui/not-clone-closure.stderr b/src/test/ui/not-clone-closure.stderr index f61ee661bb7..37d94cf0ebd 100644 --- a/src/test/ui/not-clone-closure.stderr +++ b/src/test/ui/not-clone-closure.stderr @@ -1,13 +1,11 @@ error[E0277]: the trait bound `S: Clone` is not satisfied in `[closure@$DIR/not-clone-closure.rs:7:17: 7:24]` - --> $DIR/not-clone-closure.rs:11:17 + --> $DIR/not-clone-closure.rs:11:23 | LL | let hello = move || { | ------- within this `[closure@$DIR/not-clone-closure.rs:7:17: 7:24]` ... LL | let hello = hello.clone(); - | ^^^^^ ----- required by a bound introduced by this call - | | - | within `[closure@$DIR/not-clone-closure.rs:7:17: 7:24]`, the trait `Clone` is not implemented for `S` + | ^^^^^ within `[closure@$DIR/not-clone-closure.rs:7:17: 7:24]`, the trait `Clone` is not implemented for `S` | note: required because it's used within this closure --> $DIR/not-clone-closure.rs:7:17 diff --git a/src/test/ui/on-unimplemented/sum.stderr b/src/test/ui/on-unimplemented/sum.stderr index c99f06da7a4..70706541ad6 100644 --- a/src/test/ui/on-unimplemented/sum.stderr +++ b/src/test/ui/on-unimplemented/sum.stderr @@ -1,10 +1,8 @@ error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()` - --> $DIR/sum.rs:4:5 + --> $DIR/sum.rs:4:25 | LL | vec![(), ()].iter().sum::(); - | ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call - | | - | value of type `i32` cannot be made by summing a `std::iter::Iterator` + | ^^^ value of type `i32` cannot be made by summing a `std::iter::Iterator` | = help: the trait `Sum<&()>` is not implemented for `i32` = help: the following other types implement trait `Sum`: @@ -24,12 +22,10 @@ LL | S: Sum, | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` error[E0277]: a value of type `i32` cannot be made by multiplying all elements of type `&()` from an iterator - --> $DIR/sum.rs:7:5 + --> $DIR/sum.rs:7:25 | LL | vec![(), ()].iter().product::(); - | ^^^^^^^^^^^^^^^^^^^ ------- required by a bound introduced by this call - | | - | value of type `i32` cannot be made by multiplying all elements from a `std::iter::Iterator` + | ^^^^^^^ value of type `i32` cannot be made by multiplying all elements from a `std::iter::Iterator` | = help: the trait `Product<&()>` is not implemented for `i32` = help: the following other types implement trait `Product`: diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr index c64930db9be..f9d0d1f7875 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `NonConstImpl: ~const ConstDefaultFn` is not satisfied - --> $DIR/const-default-method-bodies.rs:24:5 + --> $DIR/const-default-method-bodies.rs:24:18 | LL | NonConstImpl.a(); - | ^^^^^^^^^^^^ - required by a bound introduced by this call - | | - | the trait `~const ConstDefaultFn` is not implemented for `NonConstImpl` + | ^ the trait `~const ConstDefaultFn` is not implemented for `NonConstImpl` | note: the trait `ConstDefaultFn` is implemented for `NonConstImpl`, but that implementation is not `const` --> $DIR/const-default-method-bodies.rs:24:5 diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr index 925ae53e324..633b7cc255a 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `cross_crate::NonConst: ~const cross_crate::MyTrait` is not satisfied - --> $DIR/cross-crate.rs:17:5 + --> $DIR/cross-crate.rs:17:14 | LL | NonConst.func(); - | ^^^^^^^^ ---- required by a bound introduced by this call - | | - | the trait `~const cross_crate::MyTrait` is not implemented for `cross_crate::NonConst` + | ^^^^ the trait `~const cross_crate::MyTrait` is not implemented for `cross_crate::NonConst` | note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst`, but that implementation is not `const` --> $DIR/cross-crate.rs:17:5 diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr index 11db0c2b8f2..9e97d3f1137 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `cross_crate::NonConst: cross_crate::MyTrait` is not satisfied - --> $DIR/cross-crate.rs:17:5 + --> $DIR/cross-crate.rs:17:14 | LL | NonConst.func(); - | ^^^^^^^^ ---- required by a bound introduced by this call - | | - | the trait `~const cross_crate::MyTrait` is not implemented for `cross_crate::NonConst` + | ^^^^ the trait `~const cross_crate::MyTrait` is not implemented for `cross_crate::NonConst` | note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst`, but that implementation is not `const` --> $DIR/cross-crate.rs:17:5 diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr index c2c16921c2e..21ecddaffbb 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied - --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:9 + --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:12 | LL | ().a() - | ^^ - required by a bound introduced by this call - | | - | the trait `~const Tr` is not implemented for `()` + | ^ the trait `~const Tr` is not implemented for `()` | note: the trait `Tr` is implemented for `()`, but that implementation is not `const` --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:9 diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr index b52eb2c0332..13fc719f28c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:15:5 + --> $DIR/super-traits-fail-2.rs:15:7 | LL | x.a(); - | ^ - required by a bound introduced by this call - | | - | the trait `~const Foo` is not implemented for `T` + | ^ the trait `~const Foo` is not implemented for `T` | note: the trait `Foo` is implemented for `T`, but that implementation is not `const` --> $DIR/super-traits-fail-2.rs:15:5 diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr index b52eb2c0332..13fc719f28c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:15:5 + --> $DIR/super-traits-fail-2.rs:15:7 | LL | x.a(); - | ^ - required by a bound introduced by this call - | | - | the trait `~const Foo` is not implemented for `T` + | ^ the trait `~const Foo` is not implemented for `T` | note: the trait `Foo` is implemented for `T`, but that implementation is not `const` --> $DIR/super-traits-fail-2.rs:15:5 diff --git a/src/test/ui/suggestions/issue-71394-no-from-impl.stderr b/src/test/ui/suggestions/issue-71394-no-from-impl.stderr index 684db23e135..a5e6f5b5ffc 100644 --- a/src/test/ui/suggestions/issue-71394-no-from-impl.stderr +++ b/src/test/ui/suggestions/issue-71394-no-from-impl.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `&[i8]: From<&[u8]>` is not satisfied - --> $DIR/issue-71394-no-from-impl.rs:3:20 + --> $DIR/issue-71394-no-from-impl.rs:3:25 | LL | let _: &[i8] = data.into(); - | ^^^^ ---- required by a bound introduced by this call - | | - | the trait `From<&[u8]>` is not implemented for `&[i8]` + | ^^^^ the trait `From<&[u8]>` is not implemented for `&[i8]` | = help: the following other types implement trait `From`: <[T; LANES] as From>> diff --git a/src/test/ui/traits/issue-97576.stderr b/src/test/ui/traits/issue-97576.stderr index 146d38d076a..9062a0fab63 100644 --- a/src/test/ui/traits/issue-97576.stderr +++ b/src/test/ui/traits/issue-97576.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `String: From` is not satisfied - --> $DIR/issue-97576.rs:8:18 + --> $DIR/issue-97576.rs:8:22 | LL | bar: bar.into(), - | ^^^ ---- required by a bound introduced by this call - | | - | the trait `From` is not implemented for `String` + | ^^^^ the trait `From` is not implemented for `String` | = note: required for `impl ToString` to implement `Into` diff --git a/src/test/ui/unsized/issue-71659.stderr b/src/test/ui/unsized/issue-71659.stderr index 50060e53a49..d7b95f55769 100644 --- a/src/test/ui/unsized/issue-71659.stderr +++ b/src/test/ui/unsized/issue-71659.stderr @@ -1,10 +1,8 @@ error[E0277]: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied - --> $DIR/issue-71659.rs:30:13 + --> $DIR/issue-71659.rs:30:15 | LL | let x = x.cast::<[i32]>(); - | ^ ---- required by a bound introduced by this call - | | - | the trait `CastTo<[i32]>` is not implemented for `dyn Foo` + | ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Foo` | note: required by a bound in `Cast::cast` --> $DIR/issue-71659.rs:19:15 -- cgit 1.4.1-3-g733a5