Skip to content

Commit 3b938f7

Browse files
committed
Trim paths in E0599
1 parent 4d4d478 commit 3b938f7

File tree

13 files changed

+46
-42
lines changed

13 files changed

+46
-42
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
2525
use rustc_middle::traits::util::supertraits;
2626
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
2727
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
28-
use rustc_middle::ty::print::with_crate_prefix;
28+
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
2929
use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitable};
3030
use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef};
3131
use rustc_span::symbol::{kw, sym, Ident};
@@ -270,7 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
270270
let tcx = self.tcx;
271271

272272
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
273-
let ty_str = self.ty_to_string(rcvr_ty);
273+
let ty_str = with_forced_trimmed_paths!(self.ty_to_string(rcvr_ty));
274274
let is_method = mode == Mode::MethodCall;
275275
let item_kind = if is_method {
276276
"method"
@@ -563,7 +563,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563563
let term = pred.skip_binder().term;
564564

565565
let obligation = format!("{} = {}", projection_ty, term);
566-
let quiet = format!("{} = {}", quiet_projection_ty, term);
566+
let quiet = with_forced_trimmed_paths!(format!(
567+
"{} = {}",
568+
quiet_projection_ty, term
569+
));
567570

568571
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
569572
Some((obligation, projection_ty.self_ty()))
@@ -573,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
573576
let self_ty = p.self_ty();
574577
let path = p.print_only_trait_path();
575578
let obligation = format!("{}: {}", self_ty, path);
576-
let quiet = format!("_: {}", path);
579+
let quiet = with_forced_trimmed_paths!(format!("_: {}", path));
577580
bound_span_label(self_ty, &obligation, &quiet);
578581
Some((obligation, self_ty))
579582
}
@@ -796,7 +799,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
796799
(None, None)
797800
};
798801
let primary_message = primary_message.unwrap_or_else(|| format!(
799-
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, but its trait bounds were not satisfied"
802+
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, \
803+
but its trait bounds were not satisfied"
800804
));
801805
err.set_primary_message(&primary_message);
802806
if let Some(label) = label {

src/test/ui/confuse-field-and-method/issue-33784.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `closure` found for reference `&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope
1+
error[E0599]: no method named `closure` found for reference `&Obj<[[email protected]:25:43]>` in the current scope
22
--> $DIR/issue-33784.rs:27:7
33
|
44
LL | p.closure();
@@ -9,7 +9,7 @@ help: to call the function stored in `closure`, surround the field access with p
99
LL | (p.closure)();
1010
| + +
1111

12-
error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope
12+
error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[[email protected]:25:43]>` in the current scope
1313
--> $DIR/issue-33784.rs:29:7
1414
|
1515
LL | q.fn_ptr();

src/test/ui/empty/empty-struct-braces-expr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ help: a unit struct with a similar name exists
100100
LL | let xe1 = XEmpty2();
101101
| ~~~~~~~
102102

103-
error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
103+
error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope
104104
--> $DIR/empty-struct-braces-expr.rs:25:19
105105
|
106106
LL | let xe3 = XE::Empty3;
107107
| ^^^^^^
108108
| |
109-
| variant or associated item not found in `empty_struct::XE`
109+
| variant or associated item not found in `XE`
110110
| help: there is a variant with a similar name: `XEmpty3`
111111

112-
error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
112+
error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope
113113
--> $DIR/empty-struct-braces-expr.rs:26:19
114114
|
115115
LL | let xe3 = XE::Empty3();
116116
| ^^^^^^
117117
| |
118-
| variant or associated item not found in `empty_struct::XE`
118+
| variant or associated item not found in `XE`
119119
| help: there is a variant with a similar name: `XEmpty3`
120120

121121
error[E0599]: no variant named `Empty1` found for enum `empty_struct::XE`

src/test/ui/functions-closures/fn-help-with-err.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ note: `Bar` defines an item `bar`, perhaps you need to implement it
1717
LL | trait Bar {
1818
| ^^^^^^^^^
1919

20-
error[E0599]: no method named `bar` found for struct `Arc<[closure@$DIR/fn-help-with-err.rs:22:36: 22:38]>` in the current scope
20+
error[E0599]: no method named `bar` found for struct `Arc<[[email protected]:22:36]>` in the current scope
2121
--> $DIR/fn-help-with-err.rs:23:10
2222
|
2323
LL | arc2.bar();
24-
| ^^^ method not found in `Arc<[closure@$DIR/fn-help-with-err.rs:22:36: 22:38]>`
24+
| ^^^ method not found in `Arc<[[email protected]:22:36]>`
2525
|
2626
= help: items from traits can only be used if the trait is implemented and in scope
2727
note: `Bar` defines an item `bar`, perhaps you need to implement it

src/test/ui/higher-rank-trait-bounds/issue-30786.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>`, but its trait bounds were not satisfied
1+
error[E0599]: the method `filterx` exists for struct `Map<Repeat, [[email protected]:117:27]>`, but its trait bounds were not satisfied
22
--> $DIR/issue-30786.rs:118:22
33
|
44
LL | pub struct Map<S, F> {
@@ -8,7 +8,7 @@ LL | pub struct Map<S, F> {
88
| doesn't satisfy `_: StreamExt`
99
...
1010
LL | let filter = map.filterx(|x: &_| true);
11-
| ^^^^^^^ method cannot be called due to unsatisfied trait bounds
11+
| ^^^^^^^ method cannot be called on `Map<Repeat, [[email protected]:117:27]>` due to unsatisfied trait bounds
1212
|
1313
note: the following trait bounds were not satisfied:
1414
`&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
@@ -19,7 +19,7 @@ note: the following trait bounds were not satisfied:
1919
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
2020
| --------- - ^^^^^^ unsatisfied trait bound introduced here
2121

22-
error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>`, but its trait bounds were not satisfied
22+
error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [[email protected]:129:30]>`, but its trait bounds were not satisfied
2323
--> $DIR/issue-30786.rs:130:24
2424
|
2525
LL | pub struct Filter<S, F> {

src/test/ui/impl-trait/no-method-suggested-traits.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
145145
LL | pub trait Bar {
146146
| ^^^^^^^^^^^^^
147147

148-
error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope
148+
error[E0599]: no method named `method2` found for struct `Foo` in the current scope
149149
--> $DIR/no-method-suggested-traits.rs:50:37
150150
|
151151
LL | no_method_suggested_traits::Foo.method2();
152-
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
152+
| ^^^^^^^ method not found in `Foo`
153153
|
154154
= help: items from traits can only be used if the trait is implemented and in scope
155155
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
@@ -158,11 +158,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
158158
LL | pub trait Bar {
159159
| ^^^^^^^^^^^^^
160160

161-
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope
161+
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Foo>>` in the current scope
162162
--> $DIR/no-method-suggested-traits.rs:52:71
163163
|
164164
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
165-
| ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Foo>>`
165+
| ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>`
166166
|
167167
= help: items from traits can only be used if the trait is implemented and in scope
168168
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
@@ -171,11 +171,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
171171
LL | pub trait Bar {
172172
| ^^^^^^^^^^^^^
173173

174-
error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope
174+
error[E0599]: no method named `method2` found for enum `Bar` in the current scope
175175
--> $DIR/no-method-suggested-traits.rs:54:40
176176
|
177177
LL | no_method_suggested_traits::Bar::X.method2();
178-
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
178+
| ^^^^^^^ method not found in `Bar`
179179
|
180180
= help: items from traits can only be used if the trait is implemented and in scope
181181
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
@@ -184,11 +184,11 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
184184
LL | pub trait Bar {
185185
| ^^^^^^^^^^^^^
186186

187-
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope
187+
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Bar>>` in the current scope
188188
--> $DIR/no-method-suggested-traits.rs:56:74
189189
|
190190
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
191-
| ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Bar>>`
191+
| ^^^^^^^ method not found in `Rc<&mut Box<&Bar>>`
192192
|
193193
= help: items from traits can only be used if the trait is implemented and in scope
194194
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
@@ -255,29 +255,29 @@ error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&usize>>`
255255
LL | std::rc::Rc::new(&mut Box::new(&1_usize)).method3();
256256
| ^^^^^^^ method not found in `Rc<&mut Box<&usize>>`
257257

258-
error[E0599]: no method named `method3` found for struct `no_method_suggested_traits::Foo` in the current scope
258+
error[E0599]: no method named `method3` found for struct `Foo` in the current scope
259259
--> $DIR/no-method-suggested-traits.rs:71:37
260260
|
261261
LL | no_method_suggested_traits::Foo.method3();
262-
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
262+
| ^^^^^^^ method not found in `Foo`
263263

264-
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope
264+
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Foo>>` in the current scope
265265
--> $DIR/no-method-suggested-traits.rs:72:71
266266
|
267267
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
268-
| ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Foo>>`
268+
| ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>`
269269

270-
error[E0599]: no method named `method3` found for enum `no_method_suggested_traits::Bar` in the current scope
270+
error[E0599]: no method named `method3` found for enum `Bar` in the current scope
271271
--> $DIR/no-method-suggested-traits.rs:74:40
272272
|
273273
LL | no_method_suggested_traits::Bar::X.method3();
274-
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
274+
| ^^^^^^^ method not found in `Bar`
275275

276-
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope
276+
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Bar>>` in the current scope
277277
--> $DIR/no-method-suggested-traits.rs:75:74
278278
|
279279
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();
280-
| ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Bar>>`
280+
| ^^^^^^^ method not found in `Rc<&mut Box<&Bar>>`
281281

282282
error: aborting due to 24 previous errors
283283

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0599]: no function or associated item named `new_undirected` found for struct `issue_30123_aux::Graph<i32, i32>` in the current scope
1+
error[E0599]: no function or associated item named `new_undirected` found for struct `Graph<i32, i32>` in the current scope
22
--> $DIR/issue-30123.rs:7:33
33
|
44
LL | let ug = Graph::<i32, i32>::new_undirected();
5-
| ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
5+
| ^^^^^^^^^^^^^^ function or associated item not found in `Graph<i32, i32>`
66
|
77
= note: the function or associated item was found for
88
- `issue_30123_aux::Graph<N, E, Undirected>`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LL | | })
2121
note: required by a bound in `cloned`
2222
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
2323

24-
error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>`, but its trait bounds were not satisfied
24+
error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut IntoIter<u8>, [[email protected]:7:21]>>`, but its trait bounds were not satisfied
2525
--> $DIR/issue-31173.rs:12:10
2626
|
2727
LL | .collect();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | pub struct Iterate<T, F> {
55
| ------------------------ method `iter` not found for this struct
66
...
77
LL | println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
8-
| ^^^^ method not found in `Iterate<{integer}, [closure@$DIR/issue-41880.rs:26:24: 26:27]>`
8+
| ^^^^ method not found in `Iterate<{integer}, [[email protected]:26:24]>`
99

1010
error: aborting due to previous error
1111

src/test/ui/methods/method-not-found-generic-arg-elision.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ error[E0599]: no method named `extend` found for struct `Map` in the current sco
2323
--> $DIR/method-not-found-generic-arg-elision.rs:87:29
2424
|
2525
LL | v.iter().map(|x| x * x).extend(std::iter::once(100));
26-
| ^^^^^^ method not found in `Map<std::slice::Iter<'_, i32>, [closure@$DIR/method-not-found-generic-arg-elision.rs:87:18: 87:21]>`
26+
| ^^^^^^ method not found in `Map<Iter<'_, i32>, [[email protected]:87:18]>`
2727

2828
error[E0599]: no method named `method` found for struct `Wrapper<bool>` in the current scope
2929
--> $DIR/method-not-found-generic-arg-elision.rs:90:13

src/test/ui/mismatched_types/issue-36053-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
1313
note: required by a bound in `filter`
1414
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1515

16-
error[E0599]: the method `count` exists for struct `Filter<Fuse<std::iter::Once<&str>>, [closure@$DIR/issue-36053-2.rs:7:39: 7:48]>`, but its trait bounds were not satisfied
16+
error[E0599]: the method `count` exists for struct `Filter<Fuse<Once<&str>>, [[email protected]:7:39]>`, but its trait bounds were not satisfied
1717
--> $DIR/issue-36053-2.rs:7:55
1818
|
1919
LL | once::<&str>("str").fuse().filter(|a: &str| true).count();

src/test/ui/suggestions/mut-borrow-needed-by-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ LL | let fp = BufWriter::new(fp);
2020
note: required by a bound in `BufWriter`
2121
--> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL
2222

23-
error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn std::io::Write>`, but its trait bounds were not satisfied
23+
error[E0599]: the method `write_fmt` exists for struct `BufWriter<&dyn Write>`, but its trait bounds were not satisfied
2424
--> $DIR/mut-borrow-needed-by-trait.rs:21:5
2525
|
2626
LL | writeln!(fp, "hello world").unwrap();
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `BufWriter<&dyn std::io::Write>` due to unsatisfied trait bounds
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `BufWriter<&dyn Write>` due to unsatisfied trait bounds
2828
--> $SRC_DIR/std/src/io/buffered/bufwriter.rs:LL:COL
2929
|
3030
= note: doesn't satisfy `BufWriter<&dyn std::io::Write>: std::io::Write`

src/test/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0599]: no method named `call` found for closure `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:29]` in the current scope
1+
error[E0599]: no method named `call` found for closure `[[email protected]:6:26]` in the current scope
22
--> $DIR/unboxed-closures-static-call-wrong-trait.rs:7:10
33
|
44
LL | mut_.call((0, ));
5-
| ^^^^ method not found in `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:29]`
5+
| ^^^^ method not found in `[[email protected]:6:26]`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)