Skip to content

Commit

Permalink
Make confusable suggestions verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 10, 2024
1 parent 75f7b55 commit d7868c4
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 43 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
// We found a method with the same number of arguments as the method
// call expression the user wrote.
err.span_suggestion(
err.span_suggestion_verbose(
span,
format!("there is {an} method with a similar name"),
similar_candidate.name,
Expand All @@ -1307,7 +1307,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
// We have fn call expression and the argument count match the associated
// function we found.
err.span_suggestion(
err.span_suggestion_verbose(
span,
format!(
"there is {an} {} with a similar name",
Expand All @@ -1328,7 +1328,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
} else if let Mode::Path = mode {
// We have an associated item syntax and we found something that isn't an fn.
err.span_suggestion(
err.span_suggestion_verbose(
span,
format!(
"there is {an} {} with a similar name",
Expand Down
30 changes: 18 additions & 12 deletions tests/ui/associated-item/associated-item-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ LL | enum Enum { Variant }
| --------- variant or associated item `mispellable` not found for this enum
...
LL | Enum::mispellable();
| ^^^^^^^^^^^
| |
| variant or associated item not found in `Enum`
| help: there is an associated function with a similar name: `misspellable`
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
|
help: there is an associated function with a similar name
|
LL | Enum::misspellable();
| ~~~~~~~~~~~~

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
Expand All @@ -17,10 +19,12 @@ LL | enum Enum { Variant }
| --------- variant or associated item `mispellable_trait` not found for this enum
...
LL | Enum::mispellable_trait();
| ^^^^^^^^^^^^^^^^^
| |
| variant or associated item not found in `Enum`
| help: there is an associated function with a similar name: `misspellable_trait`
| ^^^^^^^^^^^^^^^^^ variant or associated item not found in `Enum`
|
help: there is an associated function with a similar name
|
LL | Enum::misspellable_trait();
| ~~~~~~~~~~~~~~~~~~

error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:19:11
Expand All @@ -29,10 +33,12 @@ LL | enum Enum { Variant }
| --------- variant or associated item `MISPELLABLE` not found for this enum
...
LL | Enum::MISPELLABLE;
| ^^^^^^^^^^^
| |
| variant or associated item not found in `Enum`
| help: there is an associated constant with a similar name: `MISSPELLABLE`
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
|
help: there is an associated constant with a similar name
|
LL | Enum::MISSPELLABLE;
| ~~~~~~~~~~~~

error: aborting due to 3 previous errors

Expand Down
7 changes: 6 additions & 1 deletion tests/ui/attributes/rustc_confusables.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ error[E0599]: no method named `inser` found for struct `rustc_confusables_across
--> $DIR/rustc_confusables.rs:12:7
|
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
--> $DIR/rustc_confusables.rs:15:7
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/block-result/issue-3563.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ error[E0599]: no method named `b` found for reference `&Self` in the current sco
--> $DIR/issue-3563.rs:3:17
|
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

Expand Down
7 changes: 6 additions & 1 deletion tests/ui/methods/issues/issue-105732.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ error[E0599]: no method named `g` found for reference `&Self` in the current sco
--> $DIR/issue-105732.rs:10:14
|
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

Expand Down
7 changes: 6 additions & 1 deletion tests/ui/methods/method-not-found-but-doc-alias.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ LL | struct Foo;
| ---------- method `quux` not found for this struct
...
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

Expand Down
7 changes: 6 additions & 1 deletion tests/ui/object-pointer-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ LL | fn owned(self: Box<Self>);
| --------- the method might not be found because of this arbitrary self type
...
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
--> $DIR/object-pointer-types.rs:17:7
Expand Down
9 changes: 5 additions & 4 deletions tests/ui/parser/emoji-identifiers.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ LL | struct 👀;
| --------- function or associated item `full_of✨` not found for this struct
...
LL | 👀::full_of✨()
| ^^^^^^^^^
| |
| function or associated item not found in `👀`
| help: there is an associated function with a similar name: `full_of_✨`
| ^^^^^^^^^ function or associated item not found in `👀`
|
note: if you're trying to build a new `👀`, consider using `👀::full_of_✨` which returns `👀`
--> $DIR/emoji-identifiers.rs:4:5
|
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
--> $DIR/emoji-identifiers.rs:13:13
Expand Down
10 changes: 6 additions & 4 deletions tests/ui/resolve/typo-suggestion-mistyped-in-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ LL | struct Struct;
| ------------- function or associated item `fob` not found for this struct
...
LL | Struct::fob();
| ^^^
| |
| function or associated item not found in `Struct`
| help: there is an associated function with a similar name: `foo`
| ^^^ function or associated item not found in `Struct`
|
help: there is an associated function with a similar name
|
LL | Struct::foo();
| ~~~

error[E0433]: failed to resolve: use of undeclared type `Struc`
--> $DIR/typo-suggestion-mistyped-in-path.rs:27:5
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/rust-2018/trait-import-suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
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
--> $DIR/trait-import-suggestions.rs:30:18
Expand Down
12 changes: 10 additions & 2 deletions tests/ui/self/arbitrary_self_type_mut_difference.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
LL | Pin::new(&S).x();
| ^ help: there is a method with a similar name: `y`
| ^
|
note: method is available for `Pin<&mut S>`
--> $DIR/arbitrary_self_type_mut_difference.rs:6:5
|
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
--> $DIR/arbitrary_self_type_mut_difference.rs:12:22
|
LL | Pin::new(&mut S).y();
| ^ help: there is a method with a similar name: `x`
| ^
|
note: method is available for `Pin<&S>`
--> $DIR/arbitrary_self_type_mut_difference.rs:7:5
|
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

Expand Down
9 changes: 5 additions & 4 deletions tests/ui/suggestions/issue-109291.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ error[E0599]: no function or associated item named `forced_capture` found for st
--> $DIR/issue-109291.rs:2:65
|
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::forced_capture());
| ^^^^^^^^^^^^^^
| |
| function or associated item not found in `Backtrace`
| help: there is an associated function with a similar name: `force_capture`
| ^^^^^^^^^^^^^^ function or associated item not found in `Backtrace`
|
note: if you're trying to build a new `Backtrace` consider using one of the following associated functions:
Backtrace::capture
Backtrace::force_capture
Backtrace::disabled
Backtrace::create
--> $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

Expand Down
21 changes: 18 additions & 3 deletions tests/ui/suggestions/suggest-methods.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,34 @@ error[E0599]: no method named `is_emtpy` found for struct `String` in the curren
--> $DIR/suggest-methods.rs:22:15
|
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
--> $DIR/suggest-methods.rs:27:19
|
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
--> $DIR/suggest-methods.rs:30:19
|
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

Expand Down
30 changes: 25 additions & 5 deletions tests/ui/traits/trait-upcasting/subtrait-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,86 @@ error[E0599]: no method named `c` found for reference `&dyn Bar` in the current
--> $DIR/subtrait-method.rs:55:9
|
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
note: `Baz` defines an item `c`, perhaps you need to implement it
--> $DIR/subtrait-method.rs:27:1
|
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
--> $DIR/subtrait-method.rs:59:9
|
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
note: `Bar` defines an item `b`, perhaps you need to implement it
--> $DIR/subtrait-method.rs:17:1
|
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
--> $DIR/subtrait-method.rs:61:9
|
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
note: `Baz` defines an item `c`, perhaps you need to implement it
--> $DIR/subtrait-method.rs:27:1
|
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
--> $DIR/subtrait-method.rs:65:9
|
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
note: `Bar` defines an item `b`, perhaps you need to implement it
--> $DIR/subtrait-method.rs:17:1
|
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
--> $DIR/subtrait-method.rs:67:9
|
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
note: `Baz` defines an item `c`, perhaps you need to implement it
--> $DIR/subtrait-method.rs:27:1
|
LL | trait Baz: Bar {
| ^^^^^^^^^^^^^^
help: there is a method with a similar name
|
LL | foo.a();
| ~

error: aborting due to 5 previous errors

Expand Down

0 comments on commit d7868c4

Please sign in to comment.