1
Fork 0

Make confusable suggestions verbose

This commit is contained in:
Esteban Küber 2024-02-10 03:37:08 +00:00
parent 385eea1d46
commit e1e4da2b0a
14 changed files with 126 additions and 43 deletions

View file

@ -1375,7 +1375,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
// We found a method with the same number of arguments as the method // We found a method with the same number of arguments as the method
// call expression the user wrote. // call expression the user wrote.
err.span_suggestion( err.span_suggestion_verbose(
span, span,
format!("there is {an} method with a similar name"), format!("there is {an} method with a similar name"),
similar_candidate.name, similar_candidate.name,
@ -1402,7 +1402,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
// We have fn call expression and the argument count match the associated // We have fn call expression and the argument count match the associated
// function we found. // function we found.
err.span_suggestion( err.span_suggestion_verbose(
span, span,
format!( format!(
"there is {an} {} with a similar name", "there is {an} {} with a similar name",
@ -1423,7 +1423,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} else if let Mode::Path = mode { } else if let Mode::Path = mode {
// We have an associated item syntax and we found something that isn't an fn. // We have an associated item syntax and we found something that isn't an fn.
err.span_suggestion( err.span_suggestion_verbose(
span, span,
format!( format!(
"there is {an} {} with a similar name", "there is {an} {} with a similar name",

View file

@ -5,10 +5,12 @@ LL | enum Enum { Variant }
| --------- variant or associated item `mispellable` not found for this enum | --------- variant or associated item `mispellable` not found for this enum
... ...
LL | Enum::mispellable(); LL | Enum::mispellable();
| ^^^^^^^^^^^ | ^^^^^^^^^^^ variant or associated item not found in `Enum`
| | |
| variant or associated item not found in `Enum` help: there is an associated function with a similar name
| help: there is an associated function with a similar name: `misspellable` |
LL | Enum::misspellable();
| ~~~~~~~~~~~~
error[E0599]: no variant or associated item named `mispellable_trait` found for enum `Enum` in the current scope error[E0599]: no variant or associated item named `mispellable_trait` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:18:11 --> $DIR/associated-item-enum.rs:18:11
@ -17,10 +19,12 @@ LL | enum Enum { Variant }
| --------- variant or associated item `mispellable_trait` not found for this enum | --------- variant or associated item `mispellable_trait` not found for this enum
... ...
LL | Enum::mispellable_trait(); LL | Enum::mispellable_trait();
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^ variant or associated item not found in `Enum`
| | |
| variant or associated item not found in `Enum` help: there is an associated function with a similar name
| help: there is an associated function with a similar name: `misspellable_trait` |
LL | Enum::misspellable_trait();
| ~~~~~~~~~~~~~~~~~~
error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `Enum` in the current scope error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:19:11 --> $DIR/associated-item-enum.rs:19:11
@ -29,10 +33,12 @@ LL | enum Enum { Variant }
| --------- variant or associated item `MISPELLABLE` not found for this enum | --------- variant or associated item `MISPELLABLE` not found for this enum
... ...
LL | Enum::MISPELLABLE; LL | Enum::MISPELLABLE;
| ^^^^^^^^^^^ | ^^^^^^^^^^^ variant or associated item not found in `Enum`
| | |
| variant or associated item not found in `Enum` help: there is an associated constant with a similar name
| help: there is an associated constant with a similar name: `MISSPELLABLE` |
LL | Enum::MISSPELLABLE;
| ~~~~~~~~~~~~
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -31,7 +31,12 @@ error[E0599]: no method named `inser` found for struct `rustc_confusables_across
--> $DIR/rustc_confusables.rs:12:7 --> $DIR/rustc_confusables.rs:12:7
| |
LL | x.inser(); LL | x.inser();
| ^^^^^ help: there is a method with a similar name: `insert` | ^^^^^
|
help: there is a method with a similar name
|
LL | x.insert();
| ~~~~~~
error[E0599]: no method named `foo` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope error[E0599]: no method named `foo` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
--> $DIR/rustc_confusables.rs:15:7 --> $DIR/rustc_confusables.rs:15:7

View file

@ -2,7 +2,12 @@ error[E0599]: no method named `b` found for reference `&Self` in the current sco
--> $DIR/issue-3563.rs:3:17 --> $DIR/issue-3563.rs:3:17
| |
LL | || self.b() LL | || self.b()
| ^ help: there is a method with a similar name: `a` | ^
|
help: there is a method with a similar name
|
LL | || self.a()
| ~
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -10,7 +10,12 @@ error[E0599]: no method named `g` found for reference `&Self` in the current sco
--> $DIR/issue-105732.rs:10:14 --> $DIR/issue-105732.rs:10:14
| |
LL | self.g(); LL | self.g();
| ^ help: there is a method with a similar name: `f` | ^
|
help: there is a method with a similar name
|
LL | self.f();
| ~
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -5,7 +5,12 @@ LL | struct Foo;
| ---------- method `quux` not found for this struct | ---------- method `quux` not found for this struct
... ...
LL | Foo.quux(); LL | Foo.quux();
| ^^^^ help: there is a method with a similar name: `bar` | ^^^^
|
help: there is a method with a similar name
|
LL | Foo.bar();
| ~~~
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -5,7 +5,12 @@ LL | fn owned(self: Box<Self>);
| --------- the method might not be found because of this arbitrary self type | --------- the method might not be found because of this arbitrary self type
... ...
LL | x.owned(); LL | x.owned();
| ^^^^^ help: there is a method with a similar name: `to_owned` | ^^^^^
|
help: there is a method with a similar name
|
LL | x.to_owned();
| ~~~~~~~~
error[E0599]: no method named `owned` found for mutable reference `&mut dyn Foo` in the current scope error[E0599]: no method named `owned` found for mutable reference `&mut dyn Foo` in the current scope
--> $DIR/object-pointer-types.rs:17:7 --> $DIR/object-pointer-types.rs:17:7

View file

@ -71,16 +71,17 @@ LL | struct 👀;
| --------- function or associated item `full_of✨` not found for this struct | --------- function or associated item `full_of✨` not found for this struct
... ...
LL | 👀::full_of✨() LL | 👀::full_of✨()
| ^^^^^^^^^ | ^^^^^^^^^ function or associated item not found in `👀`
| |
| function or associated item not found in `👀`
| help: there is an associated function with a similar name: `full_of_✨`
| |
note: if you're trying to build a new `👀`, consider using `👀::full_of_✨` which returns `👀` note: if you're trying to build a new `👀`, consider using `👀::full_of_✨` which returns `👀`
--> $DIR/emoji-identifiers.rs:4:5 --> $DIR/emoji-identifiers.rs:4:5
| |
LL | fn full_of_✨() -> 👀 { LL | fn full_of_✨() -> 👀 {
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
help: there is an associated function with a similar name
|
LL | 👀::full_of_✨()
| ~~~~~~~~~~
error[E0425]: cannot find function `i_like_to_😄_a_lot` in this scope error[E0425]: cannot find function `i_like_to_😄_a_lot` in this scope
--> $DIR/emoji-identifiers.rs:13:13 --> $DIR/emoji-identifiers.rs:13:13

View file

@ -14,10 +14,12 @@ LL | struct Struct;
| ------------- function or associated item `fob` not found for this struct | ------------- function or associated item `fob` not found for this struct
... ...
LL | Struct::fob(); LL | Struct::fob();
| ^^^ | ^^^ function or associated item not found in `Struct`
| | |
| function or associated item not found in `Struct` help: there is an associated function with a similar name
| help: there is an associated function with a similar name: `foo` |
LL | Struct::foo();
| ~~~
error[E0433]: failed to resolve: use of undeclared type `Struc` error[E0433]: failed to resolve: use of undeclared type `Struc`
--> $DIR/typo-suggestion-mistyped-in-path.rs:27:5 --> $DIR/typo-suggestion-mistyped-in-path.rs:27:5

View file

@ -40,7 +40,12 @@ error[E0599]: no method named `baz` found for type `u32` in the current scope
--> $DIR/trait-import-suggestions.rs:29:7 --> $DIR/trait-import-suggestions.rs:29:7
| |
LL | x.baz(); LL | x.baz();
| ^^^ help: there is a method with a similar name: `bar` | ^^^
|
help: there is a method with a similar name
|
LL | x.bar();
| ~~~
error[E0599]: no function or associated item named `from_str` found for type `u32` in the current scope error[E0599]: no function or associated item named `from_str` found for type `u32` in the current scope
--> $DIR/trait-import-suggestions.rs:30:18 --> $DIR/trait-import-suggestions.rs:30:18

View file

@ -2,25 +2,33 @@ error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scop
--> $DIR/arbitrary_self_type_mut_difference.rs:11:18 --> $DIR/arbitrary_self_type_mut_difference.rs:11:18
| |
LL | Pin::new(&S).x(); LL | Pin::new(&S).x();
| ^ help: there is a method with a similar name: `y` | ^
| |
note: method is available for `Pin<&mut S>` note: method is available for `Pin<&mut S>`
--> $DIR/arbitrary_self_type_mut_difference.rs:6:5 --> $DIR/arbitrary_self_type_mut_difference.rs:6:5
| |
LL | fn x(self: Pin<&mut Self>) {} LL | fn x(self: Pin<&mut Self>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | Pin::new(&S).y();
| ~
error[E0599]: no method named `y` found for struct `Pin<&mut S>` in the current scope error[E0599]: no method named `y` found for struct `Pin<&mut S>` in the current scope
--> $DIR/arbitrary_self_type_mut_difference.rs:12:22 --> $DIR/arbitrary_self_type_mut_difference.rs:12:22
| |
LL | Pin::new(&mut S).y(); LL | Pin::new(&mut S).y();
| ^ help: there is a method with a similar name: `x` | ^
| |
note: method is available for `Pin<&S>` note: method is available for `Pin<&S>`
--> $DIR/arbitrary_self_type_mut_difference.rs:7:5 --> $DIR/arbitrary_self_type_mut_difference.rs:7:5
| |
LL | fn y(self: Pin<&Self>) {} LL | fn y(self: Pin<&Self>) {}
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | Pin::new(&mut S).x();
| ~
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -2,10 +2,7 @@ error[E0599]: no function or associated item named `forced_capture` found for st
--> $DIR/issue-109291.rs:2:65 --> $DIR/issue-109291.rs:2:65
| |
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture()); LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^ function or associated item not found in `Backtrace`
| |
| function or associated item not found in `Backtrace`
| help: there is an associated function with a similar name: `force_capture`
| |
note: if you're trying to build a new `Backtrace` consider using one of the following associated functions: note: if you're trying to build a new `Backtrace` consider using one of the following associated functions:
Backtrace::capture Backtrace::capture
@ -13,6 +10,10 @@ note: if you're trying to build a new `Backtrace` consider using one of the foll
Backtrace::disabled Backtrace::disabled
Backtrace::create Backtrace::create
--> $SRC_DIR/std/src/backtrace.rs:LL:COL --> $SRC_DIR/std/src/backtrace.rs:LL:COL
help: there is an associated function with a similar name
|
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::force_capture());
| ~~~~~~~~~~~~~
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -17,19 +17,34 @@ error[E0599]: no method named `is_emtpy` found for struct `String` in the curren
--> $DIR/suggest-methods.rs:22:15 --> $DIR/suggest-methods.rs:22:15
| |
LL | let _ = s.is_emtpy(); LL | let _ = s.is_emtpy();
| ^^^^^^^^ help: there is a method with a similar name: `is_empty` | ^^^^^^^^
|
help: there is a method with a similar name
|
LL | let _ = s.is_empty();
| ~~~~~~~~
error[E0599]: no method named `count_eos` found for type `u32` in the current scope error[E0599]: no method named `count_eos` found for type `u32` in the current scope
--> $DIR/suggest-methods.rs:27:19 --> $DIR/suggest-methods.rs:27:19
| |
LL | let _ = 63u32.count_eos(); LL | let _ = 63u32.count_eos();
| ^^^^^^^^^ help: there is a method with a similar name: `count_zeros` | ^^^^^^^^^
|
help: there is a method with a similar name
|
LL | let _ = 63u32.count_zeros();
| ~~~~~~~~~~~
error[E0599]: no method named `count_o` found for type `u32` in the current scope error[E0599]: no method named `count_o` found for type `u32` in the current scope
--> $DIR/suggest-methods.rs:30:19 --> $DIR/suggest-methods.rs:30:19
| |
LL | let _ = 63u32.count_o(); LL | let _ = 63u32.count_o();
| ^^^^^^^ help: there is a method with a similar name: `count_ones` | ^^^^^^^
|
help: there is a method with a similar name
|
LL | let _ = 63u32.count_ones();
| ~~~~~~~~~~
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -2,7 +2,7 @@ error[E0599]: no method named `c` found for reference `&dyn Bar` in the current
--> $DIR/subtrait-method.rs:55:9 --> $DIR/subtrait-method.rs:55:9
| |
LL | bar.c(); LL | bar.c();
| ^ help: there is a method with a similar name: `a` | ^
| |
= help: items from traits can only be used if the trait is implemented and in scope = help: items from traits can only be used if the trait is implemented and in scope
note: `Baz` defines an item `c`, perhaps you need to implement it note: `Baz` defines an item `c`, perhaps you need to implement it
@ -10,12 +10,16 @@ note: `Baz` defines an item `c`, perhaps you need to implement it
| |
LL | trait Baz: Bar { LL | trait Baz: Bar {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | bar.a();
| ~
error[E0599]: no method named `b` found for reference `&dyn Foo` in the current scope error[E0599]: no method named `b` found for reference `&dyn Foo` in the current scope
--> $DIR/subtrait-method.rs:59:9 --> $DIR/subtrait-method.rs:59:9
| |
LL | foo.b(); LL | foo.b();
| ^ help: there is a method with a similar name: `a` | ^
| |
= help: items from traits can only be used if the trait is implemented and in scope = help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `b`, perhaps you need to implement it note: `Bar` defines an item `b`, perhaps you need to implement it
@ -23,12 +27,16 @@ note: `Bar` defines an item `b`, perhaps you need to implement it
| |
LL | trait Bar: Foo { LL | trait Bar: Foo {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | foo.a();
| ~
error[E0599]: no method named `c` found for reference `&dyn Foo` in the current scope error[E0599]: no method named `c` found for reference `&dyn Foo` in the current scope
--> $DIR/subtrait-method.rs:61:9 --> $DIR/subtrait-method.rs:61:9
| |
LL | foo.c(); LL | foo.c();
| ^ help: there is a method with a similar name: `a` | ^
| |
= help: items from traits can only be used if the trait is implemented and in scope = help: items from traits can only be used if the trait is implemented and in scope
note: `Baz` defines an item `c`, perhaps you need to implement it note: `Baz` defines an item `c`, perhaps you need to implement it
@ -36,12 +44,16 @@ note: `Baz` defines an item `c`, perhaps you need to implement it
| |
LL | trait Baz: Bar { LL | trait Baz: Bar {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | foo.a();
| ~
error[E0599]: no method named `b` found for reference `&dyn Foo` in the current scope error[E0599]: no method named `b` found for reference `&dyn Foo` in the current scope
--> $DIR/subtrait-method.rs:65:9 --> $DIR/subtrait-method.rs:65:9
| |
LL | foo.b(); LL | foo.b();
| ^ help: there is a method with a similar name: `a` | ^
| |
= help: items from traits can only be used if the trait is implemented and in scope = help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `b`, perhaps you need to implement it note: `Bar` defines an item `b`, perhaps you need to implement it
@ -49,12 +61,16 @@ note: `Bar` defines an item `b`, perhaps you need to implement it
| |
LL | trait Bar: Foo { LL | trait Bar: Foo {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | foo.a();
| ~
error[E0599]: no method named `c` found for reference `&dyn Foo` in the current scope error[E0599]: no method named `c` found for reference `&dyn Foo` in the current scope
--> $DIR/subtrait-method.rs:67:9 --> $DIR/subtrait-method.rs:67:9
| |
LL | foo.c(); LL | foo.c();
| ^ help: there is a method with a similar name: `a` | ^
| |
= help: items from traits can only be used if the trait is implemented and in scope = help: items from traits can only be used if the trait is implemented and in scope
note: `Baz` defines an item `c`, perhaps you need to implement it note: `Baz` defines an item `c`, perhaps you need to implement it
@ -62,6 +78,10 @@ note: `Baz` defines an item `c`, perhaps you need to implement it
| |
LL | trait Baz: Bar { LL | trait Baz: Bar {
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | foo.a();
| ~
error: aborting due to 5 previous errors error: aborting due to 5 previous errors