Skip to content

Commit ce486d5

Browse files
committed
Use with_forced_trimmed_paths
1 parent 8d9ffa3 commit ce486d5

File tree

7 files changed

+64
-49
lines changed

7 files changed

+64
-49
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,12 +2394,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23942394
err.note("only the last element of a tuple may have a dynamically sized type");
23952395
}
23962396
ObligationCauseCode::ProjectionWf(data) => {
2397-
err.note(&format!("required so that the projection `{}` is well-formed", data,));
2397+
err.note(&format!("required so that the projection `{data}` is well-formed"));
23982398
}
23992399
ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
24002400
err.note(&format!(
2401-
"required so that reference `{}` does not outlive its referent",
2402-
ref_ty,
2401+
"required so that reference `{ref_ty}` does not outlive its referent"
24032402
));
24042403
}
24052404
ObligationCauseCode::ObjectTypeBound(object_ty, region) => {
@@ -2859,7 +2858,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
28592858
if ty.references_error() {
28602859
String::new()
28612860
} else {
2862-
format!("this tail expression is of type `{:?}`", ty)
2861+
let ty = with_forced_trimmed_paths!(self.ty_to_string(ty));
2862+
format!("this tail expression is of type `{ty}`")
28632863
},
28642864
);
28652865
}
@@ -2962,9 +2962,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29622962
));
29632963
if ocx.select_where_possible().is_empty() {
29642964
// `ty_var` now holds the type that `Item` is for `ExprTy`.
2965-
let assoc = self.tcx.def_path_str(proj.item_def_id);
29662965
let ty_var = self.resolve_vars_if_possible(ty_var);
2967-
assocs_in_this_method.push(Some((span, (assoc, ty_var))));
2966+
assocs_in_this_method
2967+
.push(Some((span, (proj.item_def_id, ty_var))));
29682968
} else {
29692969
// `<ExprTy as Iterator>` didn't select, so likely we've
29702970
// reached the end of the iterator chain, like the originating
@@ -2994,7 +2994,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29942994
// We want the type before deref coercions, otherwise we talk about `&[_]`
29952995
// instead of `Vec<_>`.
29962996
if let Some(ty) = typeck_results.expr_ty_opt(expr) {
2997-
let ty = self.resolve_vars_if_possible(ty);
2997+
let ty = with_forced_trimmed_paths!(self.ty_to_string(ty));
29982998
// Point at the root expression
29992999
// vec![1, 2, 3].iter().map(mapper).sum<i32>()
30003000
// ^^^^^^^^^^^^^
@@ -3021,7 +3021,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30213021
}
30223022
span_labels.push((
30233023
span,
3024-
format!("`{assoc}` is `{ty}` here"),
3024+
with_forced_trimmed_paths!(format!(
3025+
"`{}` is `{ty}` here",
3026+
self.tcx.def_path_str(assoc),
3027+
)),
30253028
));
30263029
}
30273030
break;
@@ -3031,6 +3034,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30313034
{
30323035
match (entry, prev_entry) {
30333036
(Some((span, (assoc, ty))), Some((_, (_, prev_ty)))) => {
3037+
let ty_str =
3038+
with_forced_trimmed_paths!(self.ty_to_string(ty));
3039+
3040+
let assoc = with_forced_trimmed_paths!(
3041+
self.tcx.def_path_str(assoc)
3042+
);
30343043
if ty != *prev_ty {
30353044
if type_diffs.iter().any(|diff| {
30363045
let Sorts(expected_found) = diff else { return false; };
@@ -3040,18 +3049,24 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
30403049
}
30413050
span_labels.push((
30423051
span,
3043-
format!("`{assoc}` changed to `{ty}` here"),
3052+
format!("`{assoc}` changed to `{ty_str}` here"),
30443053
));
30453054
} else {
30463055
span_labels.push((
30473056
span,
3048-
format!("`{assoc}` remains `{ty}` here"),
3057+
format!("`{assoc}` remains `{ty_str}` here"),
30493058
));
30503059
}
30513060
}
30523061
(Some((span, (assoc, ty))), None) => {
3053-
span_labels
3054-
.push((span, format!("`{assoc}` is `{ty}` here")));
3062+
span_labels.push((
3063+
span,
3064+
with_forced_trimmed_paths!(format!(
3065+
"`{}` is `{}` here",
3066+
self.tcx.def_path_str(assoc),
3067+
self.ty_to_string(ty),
3068+
)),
3069+
));
30553070
}
30563071
(None, Some(_)) | (None, None) => {}
30573072
}
@@ -3151,7 +3166,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31513166
}
31523167
ObligationCauseCode::OpaqueReturnType(expr_info) => {
31533168
if let Some((expr_ty, expr_span)) = expr_info {
3154-
let expr_ty = self.resolve_vars_if_possible(expr_ty);
3169+
let expr_ty = with_forced_trimmed_paths!(self.ty_to_string(expr_ty));
31553170
err.span_label(
31563171
expr_span,
31573172
format!("return type was inferred to be `{expr_ty}` here"),

src/test/ui/expr/malformed_closure/ruby_style_closure.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | let p = Some(45).and_then({
1414
LL | |
1515
LL | | |x| println!("doubling {}", x);
1616
LL | | Some(x * 2)
17-
| | ----------- this tail expression is of type `std::option::Option<_>`
17+
| | ----------- this tail expression is of type `Option<_>`
1818
LL | |
1919
LL | | });
2020
| |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`

src/test/ui/issues/issue-34334.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ LL | let sr: Vec<(u32, _, _) = vec![];
2929
| ------ this expression has type `Vec<(_, _, _)>`
3030
...
3131
LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect();
32-
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here
32+
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here
3333
| |
34-
| `std::iter::Iterator::Item` is `&(_, _, _)` here
34+
| `Iterator::Item` is `&(_, _, _)` here
3535
note: required by a bound in `collect`
3636
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
3737
|

src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types
1414
LL | let x1: &[f64] = &v;
1515
| -- this expression has type `&Vec<f64>`
1616
LL | let x2: Vec<f64> = x1.into_iter().collect();
17-
| ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here
17+
| ^^^^^^^^^^^ `Iterator::Item` is `&f64` here
1818
note: required by a bound in `collect`
1919
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
2020
|
@@ -38,7 +38,7 @@ LL | let x1: &[f64] = &v;
3838
| -- this expression has type `&Vec<f64>`
3939
...
4040
LL | let x3 = x1.into_iter().collect::<Vec<f64>>();
41-
| ^^^^^^^^^^^ `std::iter::Iterator::Item` is `&f64` here
41+
| ^^^^^^^^^^^ `Iterator::Item` is `&f64` here
4242
note: required by a bound in `collect`
4343
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
4444
|

src/test/ui/iterators/invalid-iterator-chain.stderr

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ note: the method call chain might not have had the expected associated types
1616
LL | let scores = vec![(0, 0)]
1717
| ------------ this expression has type `Vec<({integer}, {integer})>`
1818
LL | .iter()
19-
| ------ `std::iter::Iterator::Item` is `&({integer}, {integer})` here
19+
| ------ `Iterator::Item` is `&({integer}, {integer})` here
2020
LL | .map(|(a, b)| {
2121
| __________^
2222
LL | | a + b;
2323
LL | | });
24-
| |__________^ `std::iter::Iterator::Item` changed to `()` here
24+
| |__________^ `Iterator::Item` changed to `()` here
2525
note: required by a bound in `std::iter::Iterator::sum`
2626
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
2727
|
2828
LL | S: Sum<Self::Item>,
29-
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
29+
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
3030

3131
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()`
3232
--> $DIR/invalid-iterator-chain.rs:10:9
@@ -52,24 +52,24 @@ note: the method call chain might not have had the expected associated types
5252
LL | vec![0, 1]
5353
| ---------- this expression has type `Vec<{integer}>`
5454
LL | .iter()
55-
| ------ `std::iter::Iterator::Item` is `&{integer}` here
55+
| ------ `Iterator::Item` is `&{integer}` here
5656
LL | .map(|x| x * 2)
57-
| ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here
57+
| ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here
5858
LL | .map(|x| x as f64)
59-
| ----------------- `std::iter::Iterator::Item` changed to `f64` here
59+
| ----------------- `Iterator::Item` changed to `f64` here
6060
LL | .map(|x| x as i64)
61-
| ----------------- `std::iter::Iterator::Item` changed to `i64` here
61+
| ----------------- `Iterator::Item` changed to `i64` here
6262
LL | .filter(|x| *x > 0)
63-
| ------------------ `std::iter::Iterator::Item` remains `i64` here
63+
| ------------------ `Iterator::Item` remains `i64` here
6464
LL | .map(|x| { x + 1 })
65-
| ------------------ `std::iter::Iterator::Item` remains `i64` here
65+
| ------------------ `Iterator::Item` remains `i64` here
6666
LL | .map(|x| { x; })
67-
| ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here
67+
| ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here
6868
note: required by a bound in `std::iter::Iterator::sum`
6969
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
7070
|
7171
LL | S: Sum<Self::Item>,
72-
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
72+
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
7373

7474
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64`
7575
--> $DIR/invalid-iterator-chain.rs:22:9
@@ -94,20 +94,20 @@ note: the method call chain might not have had the expected associated types
9494
LL | vec![0, 1]
9595
| ---------- this expression has type `Vec<{integer}>`
9696
LL | .iter()
97-
| ------ `std::iter::Iterator::Item` is `&{integer}` here
97+
| ------ `Iterator::Item` is `&{integer}` here
9898
LL | .map(|x| x * 2)
99-
| ^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `{integer}` here
99+
| ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here
100100
LL | .map(|x| x as f64)
101-
| ^^^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `f64` here
101+
| ^^^^^^^^^^^^^^^^^ `Iterator::Item` changed to `f64` here
102102
LL | .filter(|x| *x > 0.0)
103-
| -------------------- `std::iter::Iterator::Item` remains `f64` here
103+
| -------------------- `Iterator::Item` remains `f64` here
104104
LL | .map(|x| { x + 1.0 })
105-
| -------------------- `std::iter::Iterator::Item` remains `f64` here
105+
| -------------------- `Iterator::Item` remains `f64` here
106106
note: required by a bound in `std::iter::Iterator::sum`
107107
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
108108
|
109109
LL | S: Sum<Self::Item>,
110-
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
110+
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
111111

112112
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()`
113113
--> $DIR/invalid-iterator-chain.rs:30:20
@@ -125,15 +125,15 @@ note: the method call chain might not have had the expected associated types
125125
--> $DIR/invalid-iterator-chain.rs:30:38
126126
|
127127
LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>());
128-
| ---------- ------ ^^^^^^^^^^^^^^^ `std::iter::Iterator::Item` changed to `()` here
128+
| ---------- ------ ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here
129129
| | |
130-
| | `std::iter::Iterator::Item` is `&{integer}` here
130+
| | `Iterator::Item` is `&{integer}` here
131131
| this expression has type `Vec<{integer}>`
132132
note: required by a bound in `std::iter::Iterator::sum`
133133
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
134134
|
135135
LL | S: Sum<Self::Item>,
136-
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
136+
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
137137

138138
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()`
139139
--> $DIR/invalid-iterator-chain.rs:31:20
@@ -151,14 +151,14 @@ note: the method call chain might not have had the expected associated types
151151
--> $DIR/invalid-iterator-chain.rs:31:33
152152
|
153153
LL | println!("{}", vec![(), ()].iter().sum::<i32>());
154-
| ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here
154+
| ------------ ^^^^^^ `Iterator::Item` is `&()` here
155155
| |
156156
| this expression has type `Vec<()>`
157157
note: required by a bound in `std::iter::Iterator::sum`
158158
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
159159
|
160160
LL | S: Sum<Self::Item>,
161-
| ^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::sum`
161+
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum`
162162

163163
error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over elements of type `()`
164164
--> $DIR/invalid-iterator-chain.rs:40:23
@@ -176,23 +176,23 @@ note: the method call chain might not have had the expected associated types
176176
LL | let a = vec![0];
177177
| ------- this expression has type `Vec<{integer}>`
178178
LL | let b = a.into_iter();
179-
| ----------- `std::iter::Iterator::Item` is `{integer}` here
179+
| ----------- `Iterator::Item` is `{integer}` here
180180
LL | let c = b.map(|x| x + 1);
181-
| -------------- `std::iter::Iterator::Item` remains `{integer}` here
181+
| -------------- `Iterator::Item` remains `{integer}` here
182182
LL | let d = c.filter(|x| *x > 10 );
183-
| -------------------- `std::iter::Iterator::Item` remains `{integer}` here
183+
| -------------------- `Iterator::Item` remains `{integer}` here
184184
LL | let e = d.map(|x| {
185185
| _______________^
186186
LL | | x + 1;
187187
LL | | });
188-
| |______^ `std::iter::Iterator::Item` changed to `()` here
188+
| |______^ `Iterator::Item` changed to `()` here
189189
LL | let f = e.filter(|_| false);
190-
| ----------------- `std::iter::Iterator::Item` remains `()` here
190+
| ----------------- `Iterator::Item` remains `()` here
191191
note: required by a bound in `collect`
192192
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
193193
|
194194
LL | fn collect<B: FromIterator<Self::Item>>(self) -> B
195-
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`
195+
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect`
196196

197197
error: aborting due to 6 previous errors
198198

src/test/ui/never_type/feature-gate-never_type_fallback.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | foo(panic!())
55
| --- ^^^^^^^^
66
| | |
77
| | the trait `T` is not implemented for `()`
8-
| | this tail expression is of type `_`
8+
| | this tail expression is of type `()`
99
| required by a bound introduced by this call
1010
|
1111
note: required by a bound in `foo`

src/test/ui/on-unimplemented/sum.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ note: the method call chain might not have had the expected associated types
1414
--> $DIR/sum.rs:4:18
1515
|
1616
LL | vec![(), ()].iter().sum::<i32>();
17-
| ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here
17+
| ------------ ^^^^^^ `Iterator::Item` is `&()` here
1818
| |
1919
| this expression has type `Vec<()>`
2020
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
3939
--> $DIR/sum.rs:7:18
4040
|
4141
LL | vec![(), ()].iter().product::<i32>();
42-
| ------------ ^^^^^^ `std::iter::Iterator::Item` is `&()` here
42+
| ------------ ^^^^^^ `Iterator::Item` is `&()` here
4343
| |
4444
| this expression has type `Vec<()>`
4545
note: required by a bound in `std::iter::Iterator::product`

0 commit comments

Comments
 (0)