about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-12-11 11:38:43 -0800
committerEsteban Küber <esteban@kuber.com.ar>2022-12-11 11:38:43 -0800
commitce486d538b909658f72d6016dae758f075089d3c (patch)
treebd1acfadde5a9ff9847838d541ea7ca9c3bfa81c
parent8d9ffa379e2b6e0d8f4813c035daf6c567887c1e (diff)
downloadrust-ce486d538b909658f72d6016dae758f075089d3c.tar.gz
rust-ce486d538b909658f72d6016dae758f075089d3c.zip
Use `with_forced_trimmed_paths`
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs41
-rw-r--r--src/test/ui/expr/malformed_closure/ruby_style_closure.stderr2
-rw-r--r--src/test/ui/issues/issue-34334.stderr4
-rw-r--r--src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr4
-rw-r--r--src/test/ui/iterators/invalid-iterator-chain.stderr56
-rw-r--r--src/test/ui/never_type/feature-gate-never_type_fallback.stderr2
-rw-r--r--src/test/ui/on-unimplemented/sum.stderr4
7 files changed, 64 insertions, 49 deletions
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 {
                                     // `<ExprTy as Iterator>` 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<i32>()
                             // ^^^^^^^^^^^^^
@@ -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<f64>`
 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`
   --> $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>`
 ...
 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`
   --> $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<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 `()`
   --> $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<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`
   --> $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<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 `()`
   --> $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::<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}>`
 note: required by a bound in `std::iter::Iterator::sum`
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
    |
 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 `&()`
   --> $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::<i32>());
-   |                    ------------ ^^^^^^ `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<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 `()`
   --> $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<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
 
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::<i32>();
-   |     ------------ ^^^^^^ `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::<i32>();
-   |     ------------ ^^^^^^ `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`