1
Fork 0

Use with_forced_trimmed_paths

This commit is contained in:
Esteban Küber 2022-12-11 11:38:43 -08:00
parent 8d9ffa379e
commit ce486d538b
7 changed files with 64 additions and 49 deletions

View file

@ -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"); err.note("only the last element of a tuple may have a dynamically sized type");
} }
ObligationCauseCode::ProjectionWf(data) => { 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) => { ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
err.note(&format!( err.note(&format!(
"required so that reference `{}` does not outlive its referent", "required so that reference `{ref_ty}` does not outlive its referent"
ref_ty,
)); ));
} }
ObligationCauseCode::ObjectTypeBound(object_ty, region) => { ObligationCauseCode::ObjectTypeBound(object_ty, region) => {
@ -2859,7 +2858,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if ty.references_error() { if ty.references_error() {
String::new() String::new()
} else { } 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() { if ocx.select_where_possible().is_empty() {
// `ty_var` now holds the type that `Item` is for `ExprTy`. // `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); 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 { } else {
// `<ExprTy as Iterator>` didn't select, so likely we've // `<ExprTy as Iterator>` didn't select, so likely we've
// reached the end of the iterator chain, like the originating // 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 `&[_]` // We want the type before deref coercions, otherwise we talk about `&[_]`
// instead of `Vec<_>`. // instead of `Vec<_>`.
if let Some(ty) = typeck_results.expr_ty_opt(expr) { 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 // Point at the root expression
// vec![1, 2, 3].iter().map(mapper).sum<i32>() // vec![1, 2, 3].iter().map(mapper).sum<i32>()
// ^^^^^^^^^^^^^ // ^^^^^^^^^^^^^
@ -3021,7 +3021,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
span_labels.push(( span_labels.push((
span, span,
format!("`{assoc}` is `{ty}` here"), with_forced_trimmed_paths!(format!(
"`{}` is `{ty}` here",
self.tcx.def_path_str(assoc),
)),
)); ));
} }
break; break;
@ -3031,6 +3034,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
{ {
match (entry, prev_entry) { match (entry, prev_entry) {
(Some((span, (assoc, ty))), Some((_, (_, prev_ty)))) => { (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 ty != *prev_ty {
if type_diffs.iter().any(|diff| { if type_diffs.iter().any(|diff| {
let Sorts(expected_found) = diff else { return false; }; let Sorts(expected_found) = diff else { return false; };
@ -3040,18 +3049,24 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
span_labels.push(( span_labels.push((
span, span,
format!("`{assoc}` changed to `{ty}` here"), format!("`{assoc}` changed to `{ty_str}` here"),
)); ));
} else { } else {
span_labels.push(( span_labels.push((
span, span,
format!("`{assoc}` remains `{ty}` here"), format!("`{assoc}` remains `{ty_str}` here"),
)); ));
} }
} }
(Some((span, (assoc, ty))), None) => { (Some((span, (assoc, ty))), None) => {
span_labels span_labels.push((
.push((span, format!("`{assoc}` is `{ty}` here"))); span,
with_forced_trimmed_paths!(format!(
"`{}` is `{}` here",
self.tcx.def_path_str(assoc),
self.ty_to_string(ty),
)),
));
} }
(None, Some(_)) | (None, None) => {} (None, Some(_)) | (None, None) => {}
} }
@ -3151,7 +3166,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
ObligationCauseCode::OpaqueReturnType(expr_info) => { ObligationCauseCode::OpaqueReturnType(expr_info) => {
if let Some((expr_ty, expr_span)) = 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( err.span_label(
expr_span, expr_span,
format!("return type was inferred to be `{expr_ty}` here"), format!("return type was inferred to be `{expr_ty}` here"),

View file

@ -14,7 +14,7 @@ LL | let p = Some(45).and_then({
LL | | LL | |
LL | | |x| println!("doubling {}", x); LL | | |x| println!("doubling {}", x);
LL | | Some(x * 2) LL | | Some(x * 2)
| | ----------- this tail expression is of type `std::option::Option<_>` | | ----------- this tail expression is of type `Option<_>`
LL | | LL | |
LL | | }); LL | | });
| |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`

View file

@ -29,9 +29,9 @@ LL | let sr: Vec<(u32, _, _) = vec![];
| ------ this expression has type `Vec<(_, _, _)>` | ------ this expression has type `Vec<(_, _, _)>`
... ...
LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); 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` note: required by a bound in `collect`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |

View file

@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types
LL | let x1: &[f64] = &v; LL | let x1: &[f64] = &v;
| -- this expression has type `&Vec<f64>` | -- this expression has type `&Vec<f64>`
LL | let x2: Vec<f64> = x1.into_iter().collect(); LL | let x2: Vec<f64> = x1.into_iter().collect();
| ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here | ^^^^^^^^^^^ `Iterator::Item` is `&f64` here
note: required by a bound in `collect` note: required by a bound in `collect`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
@ -38,7 +38,7 @@ LL | let x1: &[f64] = &v;
| -- this expression has type `&Vec<f64>` | -- this expression has type `&Vec<f64>`
... ...
LL | let x3 = x1.into_iter().collect::<Vec<f64>>(); LL | let x3 = x1.into_iter().collect::<Vec<f64>>();
| ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here | ^^^^^^^^^^^ `Iterator::Item` is `&f64` here
note: required by a bound in `collect` note: required by a bound in `collect`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |

View file

@ -16,17 +16,17 @@ note: the method call chain might not have had the expected associated types
LL | let scores = vec![(0, 0)] LL | let scores = vec![(0, 0)]
| ------------ this expression has type `Vec<({integer}, {integer})>` | ------------ this expression has type `Vec<({integer}, {integer})>`
LL | .iter() LL | .iter()
| ------ `std::iter::Iterator::Item` is `&({integer}, {integer})` here | ------ `Iterator::Item` is `&({integer}, {integer})` here
LL | .map(|(a, b)| { LL | .map(|(a, b)| {
| __________^ | __________^
LL | | a + b; LL | | a + b;
LL | | }); LL | | });
| |__________^ `std::iter::Iterator::Item` changed to `()` here | |__________^ `Iterator::Item` changed to `()` here
note: required by a bound in `std::iter::Iterator::sum` note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
LL | S: Sum<Self::Item>, LL | S: Sum<Self::Item>,
| ^^^^^^^^^^^^^^^ 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 `()` 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 --> $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] LL | vec![0, 1]
| ---------- this expression has type `Vec<{integer}>` | ---------- this expression has type `Vec<{integer}>`
LL | .iter() LL | .iter()
| ------ `std::iter::Iterator::Item` is `&{integer}` here | ------ `Iterator::Item` is `&{integer}` here
LL | .map(|x| x * 2) 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) 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) 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) LL | .filter(|x| *x > 0)
| ------------------ `std::iter::Iterator::Item` remains `i64` here | ------------------ `Iterator::Item` remains `i64` here
LL | .map(|x| { x + 1 }) LL | .map(|x| { x + 1 })
| ------------------ `std::iter::Iterator::Item` remains `i64` here | ------------------ `Iterator::Item` remains `i64` here
LL | .map(|x| { x; }) 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` note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
LL | S: Sum<Self::Item>, LL | S: Sum<Self::Item>,
| ^^^^^^^^^^^^^^^ 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` 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 --> $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] LL | vec![0, 1]
| ---------- this expression has type `Vec<{integer}>` | ---------- this expression has type `Vec<{integer}>`
LL | .iter() LL | .iter()
| ------ `std::iter::Iterator::Item` is `&{integer}` here | ------ `Iterator::Item` is `&{integer}` here
LL | .map(|x| x * 2) 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) 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) LL | .filter(|x| *x > 0.0)
| -------------------- `std::iter::Iterator::Item` remains `f64` here | -------------------- `Iterator::Item` remains `f64` here
LL | .map(|x| { x + 1.0 }) 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` note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
LL | S: Sum<Self::Item>, LL | S: Sum<Self::Item>,
| ^^^^^^^^^^^^^^^ 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 `()` 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: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 --> $DIR/invalid-iterator-chain.rs:30:38
| |
LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
| ---------- ------ ^^^^^^^^^^^^^^^ `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}>` | this expression has type `Vec<{integer}>`
note: required by a bound in `std::iter::Iterator::sum` note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
LL | S: Sum<Self::Item>, LL | S: Sum<Self::Item>,
| ^^^^^^^^^^^^^^^ 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 `&()` 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: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 --> $DIR/invalid-iterator-chain.rs:31:33
| |
LL | println!("{}", vec![(), ()].iter().sum::<i32>()); LL | println!("{}", vec![(), ()].iter().sum::<i32>());
| ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here | ------------ ^^^^^^ `Iterator::Item` is `&()` here
| | | |
| this expression has type `Vec<()>` | this expression has type `Vec<()>`
note: required by a bound in `std::iter::Iterator::sum` note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
LL | S: Sum<Self::Item>, LL | S: Sum<Self::Item>,
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum` | ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over elements of type `()` error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over elements of type `()`
--> $DIR/invalid-iterator-chain.rs:40:23 --> $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]; LL | let a = vec![0];
| ------- this expression has type `Vec<{integer}>` | ------- this expression has type `Vec<{integer}>`
LL | let b = a.into_iter(); 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); 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 ); 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 | let e = d.map(|x| {
| _______________^ | _______________^
LL | | x + 1; LL | | x + 1;
LL | | }); LL | | });
| |______^ `std::iter::Iterator::Item` changed to `()` here | |______^ `Iterator::Item` changed to `()` here
LL | let f = e.filter(|_| false); LL | let f = e.filter(|_| false);
| ----------------- `std::iter::Iterator::Item` remains `()` here | ----------------- `Iterator::Item` remains `()` here
note: required by a bound in `collect` note: required by a bound in `collect`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
| |
LL | fn collect<B: FromIterator<Self::Item>>(self) -> B LL | fn collect<B: FromIterator<Self::Item>>(self) -> B
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect` | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View file

@ -5,7 +5,7 @@ LL | foo(panic!())
| --- ^^^^^^^^ | --- ^^^^^^^^
| | | | | |
| | the trait `T` is not implemented for `()` | | 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 | required by a bound introduced by this call
| |
note: required by a bound in `foo` note: required by a bound in `foo`

View file

@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types
--> $DIR/sum.rs:4:18 --> $DIR/sum.rs:4:18
| |
LL | vec![(), ()].iter().sum::<i32>(); LL | vec![(), ()].iter().sum::<i32>();
| ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here | ------------ ^^^^^^ `Iterator::Item` is `&()` here
| | | |
| this expression has type `Vec<()>` | this expression has type `Vec<()>`
note: required by a bound in `std::iter::Iterator::sum` 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 --> $DIR/sum.rs:7:18
| |
LL | vec![(), ()].iter().product::<i32>(); LL | vec![(), ()].iter().product::<i32>();
| ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here | ------------ ^^^^^^ `Iterator::Item` is `&()` here
| | | |
| this expression has type `Vec<()>` | this expression has type `Vec<()>`
note: required by a bound in `std::iter::Iterator::product` note: required by a bound in `std::iter::Iterator::product`