Skip to content

Avoid extra path trimming in method not found error #141512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tcx = self.tcx;
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
let mut ty_file = None;
let (mut ty_str, short_ty_str) =
let (ty_str, short_ty_str) =
if trait_missing_method && let ty::Dynamic(predicates, _, _) = rcvr_ty.kind() {
(predicates.to_string(), with_forced_trimmed_paths!(predicates.to_string()))
} else {
Expand Down Expand Up @@ -738,10 +738,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(within_macro_span, "due to this macro variable");
}

if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 {
ty_str = short_ty_str;
}

if rcvr_ty.references_error() {
err.downgrade_to_delayed_bug();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/crate-loading/multiple-dep-versions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in t
--> replaced
|
LL | Type.foo();
| ^^^ method not found in `Type`
| ^^^ method not found in `dep_2_reexport::Type`
|
note: there are multiple different versions of crate `dependency` in the dependency graph
--> replaced
Expand All @@ -63,7 +63,7 @@ error[E0599]: no function or associated item named `bar` found for struct `dep_2
--> replaced
|
LL | Type::bar();
| ^^^ function or associated item not found in `Type`
| ^^^ function or associated item not found in `dep_2_reexport::Type`
|
note: there are multiple different versions of crate `dependency` in the dependency graph
--> replaced
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/issue-43924.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error[E0599]: no function or associated item named `default` found for trait obj
--> $DIR/issue-43924.rs:14:39
|
LL | assert_eq!(<() as Foo<u32>>::Out::default().to_string(), "false");
| ^^^^^^^ function or associated item not found in `dyn ToString`
| ^^^^^^^ function or associated item not found in `(dyn ToString + 'static)`

error: aborting due to 2 previous errors

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/attributes/rustc_confusables.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ error[E0599]: no method named `foo` found for struct `rustc_confusables_across_c
--> $DIR/rustc_confusables.rs:15:7
|
LL | x.foo();
| ^^^ method not found in `BTreeSet`
| ^^^ method not found in `rustc_confusables_across_crate::BTreeSet`

error[E0599]: no method named `push` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
--> $DIR/rustc_confusables.rs:17:7
|
LL | x.push();
| ^^^^ method not found in `BTreeSet`
| ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet`
|
help: you might have meant to use `insert`
|
Expand All @@ -60,7 +60,7 @@ error[E0599]: no method named `test` found for struct `rustc_confusables_across_
--> $DIR/rustc_confusables.rs:20:7
|
LL | x.test();
| ^^^^ method not found in `BTreeSet`
| ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet`

error[E0599]: no method named `pulled` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
--> $DIR/rustc_confusables.rs:22:7
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/empty/empty-struct-braces-expr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ error[E0599]: no variant or associated item named `Empty3` found for enum `empty
--> $DIR/empty-struct-braces-expr.rs:25:19
|
LL | let xe3 = XE::Empty3;
| ^^^^^^ variant or associated item not found in `XE`
| ^^^^^^ variant or associated item not found in `empty_struct::XE`
|
help: there is a variant with a similar name
|
Expand All @@ -132,7 +132,7 @@ error[E0599]: no variant or associated item named `Empty3` found for enum `empty
--> $DIR/empty-struct-braces-expr.rs:26:19
|
LL | let xe3 = XE::Empty3();
| ^^^^^^ variant or associated item not found in `XE`
| ^^^^^^ variant or associated item not found in `empty_struct::XE`
|
help: there is a variant with a similar name
|
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/error-emitter/multiline-removal-suggestion.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/ui/functions-closures/fn-help-with-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0599]: no method named `bar` found for struct `Arc<{closure@$DIR/fn-help-
--> $DIR/fn-help-with-err.rs:19:10
|
LL | arc2.bar();
| ^^^ method not found in `Arc<{[email protected]:18:36}>`
| ^^^ method not found in `Arc<{closure@$DIR/fn-help-with-err.rs:18:36: 18:38}>`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `bar`, perhaps you need to implement it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0599]: the method `filterx` exists for struct `Map<Repeat, {[email protected]:113:27}>`, but its trait bounds were not satisfied
error[E0599]: the method `filterx` exists for struct `Map<Repeat, {closure@$DIR/hrtb-doesnt-borrow-self-1.rs:113:27: 113:34}>`, but its trait bounds were not satisfied
--> $DIR/hrtb-doesnt-borrow-self-1.rs:114:22
|
LL | pub struct Map<S, F> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, fn(&u64) -> &u64 {identity::<u64>}>, {[email protected]:109:30}>`, but its trait bounds were not satisfied
error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, {closure@$DIR/hrtb-doesnt-borrow-self-2.rs:109:30: 109:37}>`, but its trait bounds were not satisfied
--> $DIR/hrtb-doesnt-borrow-self-2.rs:110:24
|
LL | pub struct Filter<S, F> {
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/impl-trait/no-method-suggested-traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ error[E0599]: no method named `method2` found for struct `no_method_suggested_tr
--> $DIR/no-method-suggested-traits.rs:52:37
|
LL | no_method_suggested_traits::Foo.method2();
| ^^^^^^^ method not found in `Foo`
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
Expand All @@ -186,7 +186,7 @@ error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method
--> $DIR/no-method-suggested-traits.rs:54:71
|
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
| ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>`
| ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Foo>>`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
Expand All @@ -199,7 +199,7 @@ error[E0599]: no method named `method2` found for enum `no_method_suggested_trai
--> $DIR/no-method-suggested-traits.rs:56:40
|
LL | no_method_suggested_traits::Bar::X.method2();
| ^^^^^^^ method not found in `Bar`
| ^^^^^^^ method not found in `no_method_suggested_traits::Bar`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
Expand All @@ -212,7 +212,7 @@ error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method
--> $DIR/no-method-suggested-traits.rs:58:74
|
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
| ^^^^^^^ method not found in `Rc<&mut Box<&Bar>>`
| ^^^^^^^ method not found in `Rc<&mut Box<&no_method_suggested_traits::Bar>>`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
Expand Down Expand Up @@ -283,25 +283,25 @@ error[E0599]: no method named `method3` found for struct `no_method_suggested_tr
--> $DIR/no-method-suggested-traits.rs:73:37
|
LL | no_method_suggested_traits::Foo.method3();
| ^^^^^^^ method not found in `Foo`
| ^^^^^^^ method not found in `no_method_suggested_traits::Foo`

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

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

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

error: aborting due to 24 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-30123.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0599]: no function or associated item named `new_undirected` found for st
--> $DIR/issue-30123.rs:7:33
|
LL | let ug = Graph::<i32, i32>::new_undirected();
| ^^^^^^^^^^^^^^ function or associated item not found in `Graph<i32, i32>`
| ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
|
note: if you're trying to build a new `issue_30123_aux::Graph<i32, i32>`, consider using `issue_30123_aux::Graph::<N, E>::new` which returns `issue_30123_aux::Graph<_, _>`
--> $DIR/auxiliary/issue-30123-aux.rs:14:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-41880.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub struct Iterate<T, F> {
| ------------------------ method `iter` not found for this struct
...
LL | println!("{:?}", a.iter().take(10).collect::<Vec<usize>>());
| ^^^^ method not found in `Iterate<{integer}, {[email protected]:26:24}>`
| ^^^^ method not found in `Iterate<{integer}, {closure@$DIR/issue-41880.rs:26:24: 26:27}>`

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/macros/missing-writer.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ error[E0599]: cannot write into `&'static str`
--> $DIR/missing-writer.rs:5:12
|
LL | write!("{}_{}", x, y);
| -------^^^^^^^------- method not found in `&str`
| -------^^^^^^^------- method not found in `&'static str`
|
note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method
--> $DIR/missing-writer.rs:5:12
Expand All @@ -41,7 +41,7 @@ error[E0599]: cannot write into `&'static str`
--> $DIR/missing-writer.rs:11:14
|
LL | writeln!("{}_{}", x, y);
| ---------^^^^^^^------- method not found in `&str`
| ---------^^^^^^^------- method not found in `&'static str`
|
note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method
--> $DIR/missing-writer.rs:11:14
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/methods/issue-19521.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0599]: no method named `homura` found for reference `&'static str` in the
--> $DIR/issue-19521.rs:2:8
|
LL | "".homura()();
| ^^^^^^ method not found in `&str`
| ^^^^^^ method not found in `&'static str`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ error[E0599]: no method named `extend` found for struct `Map` in the current sco
--> $DIR/method-not-found-generic-arg-elision.rs:87:67
|
LL | v.iter().map(Box::new(|x| x * x) as Box<dyn Fn(&i32) -> i32>).extend(std::iter::once(100));
| ^^^^^^ method not found in `Map<Iter<'_, i32>, Box<dyn Fn(&i32) -> i32>>`
| ^^^^^^ method not found in `Map<std::slice::Iter<'_, i32>, Box<dyn for<'a> Fn(&'a i32) -> i32>>`

error[E0599]: no method named `method` found for struct `Wrapper<bool>` in the current scope
--> $DIR/method-not-found-generic-arg-elision.rs:90:13
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/methods/receiver-equality.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | struct B<T>(T);
| ----------- function or associated item `method` not found for this struct
...
LL | B::<for<'a> fn(&'a ())>::method(y);
| ^^^^^^ function or associated item not found in `B<fn(&())>`
| ^^^^^^ function or associated item not found in `B<for<'a> fn(&'a ())>`

error: aborting due to 1 previous error

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/methods/untrimmed-path-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Ensures that the path of the `Error` type is not trimmed
// to make it clear which Error type is meant.

fn main() {
meow().unknown(); //~ ERROR no method named `unknown` found
//~^ NOTE method not found in `Result<(), std::io::Error>`
}

fn meow() -> Result<(), std::io::Error> {
Ok(())
}
9 changes: 9 additions & 0 deletions tests/ui/methods/untrimmed-path-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0599]: no method named `unknown` found for enum `Result` in the current scope
--> $DIR/untrimmed-path-type.rs:5:11
|
LL | meow().unknown();
| ^^^^^^^ method not found in `Result<(), std::io::Error>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.
2 changes: 1 addition & 1 deletion tests/ui/mismatched_types/issue-36053-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ help: consider adjusting the signature so it borrows its argument
LL | once::<&str>("str").fuse().filter(|a: &&str| true).count();
| +

error[E0599]: the method `count` exists for struct `Filter<Fuse<Once<&str>>, {[email protected]:7:39}>`, but its trait bounds were not satisfied
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
--> $DIR/issue-36053-2.rs:7:55
|
LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/nll/issue-57362-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0599]: no function or associated item named `make_g` found for fn pointer
--> $DIR/issue-57362-2.rs:23:25
|
LL | let x = <fn (&())>::make_g();
| ^^^^^^ function or associated item not found in `fn(&())`
| ^^^^^^ function or associated item not found in `for<'a> fn(&'a ())`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `X` defines an item `make_g`, perhaps you need to implement it
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/nll/issue-57642-higher-ranked-subtype.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0599]: no function or associated item named `make_g` found for fn pointer
--> $DIR/issue-57642-higher-ranked-subtype.rs:31:25
|
LL | let x = <fn (&())>::make_g();
| ^^^^^^ function or associated item not found in `fn(&())`
| ^^^^^^ function or associated item not found in `for<'a> fn(&'a ())`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `X` defines an item `make_g`, perhaps you need to implement it
Expand All @@ -15,7 +15,7 @@ error[E0599]: no function or associated item named `make_f` found for fn pointer
--> $DIR/issue-57642-higher-ranked-subtype.rs:36:25
|
LL | let x = <fn (&())>::make_f();
| ^^^^^^ function or associated item not found in `fn(&())`
| ^^^^^^ function or associated item not found in `for<'a> fn(&'a ())`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Y` defines an item `make_f`, perhaps you need to implement it
Expand Down
Loading
Loading