add typo suggestions for all AssocSuggestion variants
This commit is contained in:
parent
42e9f2daf3
commit
39caed08ae
3 changed files with 105 additions and 5 deletions
|
|
@ -460,7 +460,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
} else {
|
||||
err.span_label(span, "a field by this name exists in `Self`");
|
||||
}
|
||||
self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span);
|
||||
}
|
||||
AssocSuggestion::MethodWithSelf if self_is_available => {
|
||||
err.span_suggestion(
|
||||
|
|
@ -482,6 +481,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
);
|
||||
}
|
||||
}
|
||||
self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span);
|
||||
return (err, candidates);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
struct Foo {
|
||||
struct A {
|
||||
config: String,
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
impl A {
|
||||
fn new(cofig: String) -> Self {
|
||||
Self { config } //~ Error cannot find value `config` in this scope
|
||||
}
|
||||
|
|
@ -16,4 +16,31 @@ impl Foo {
|
|||
}
|
||||
}
|
||||
|
||||
trait B {
|
||||
const BAR: u32 = 3;
|
||||
type Baz;
|
||||
fn bar(&self);
|
||||
fn baz(&self) {}
|
||||
fn bah() {}
|
||||
}
|
||||
|
||||
impl B for Box<isize> {
|
||||
type Baz = String;
|
||||
fn bar(&self) {
|
||||
// let baz = 3;
|
||||
baz();
|
||||
//~^ ERROR cannot find function `baz`
|
||||
bah;
|
||||
//~^ ERROR cannot find value `bah`
|
||||
BAR;
|
||||
//~^ ERROR cannot find value `BAR` in this scope
|
||||
let foo: Baz = "".to_string();
|
||||
//~^ ERROR cannot find type `Baz` in this scope
|
||||
}
|
||||
}
|
||||
|
||||
fn ba() {}
|
||||
const BARR: u32 = 3;
|
||||
type Bar = String;
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,79 @@ help: a local variable with a similar name exists
|
|||
LL | println!("{cofig}");
|
||||
| ~~~~~
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0425]: cannot find function `baz` in this scope
|
||||
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:31:9
|
||||
|
|
||||
LL | baz();
|
||||
| ^^^
|
||||
...
|
||||
LL | fn ba() {}
|
||||
| ------- similarly named function `ba` defined here
|
||||
|
|
||||
help: you might have meant to call the method
|
||||
|
|
||||
LL | self.baz();
|
||||
| ~~~~~~~~
|
||||
help: a function with a similar name exists
|
||||
|
|
||||
LL | ba();
|
||||
| ~~
|
||||
|
||||
For more information about this error, try `rustc --explain E0425`.
|
||||
error[E0425]: cannot find value `bah` in this scope
|
||||
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:33:9
|
||||
|
|
||||
LL | bah;
|
||||
| ^^^
|
||||
...
|
||||
LL | fn ba() {}
|
||||
| ------- similarly named function `ba` defined here
|
||||
|
|
||||
help: you might have meant to call the associated function
|
||||
|
|
||||
LL | Self::bah;
|
||||
| ~~~~~~~~~
|
||||
help: a function with a similar name exists
|
||||
|
|
||||
LL | ba;
|
||||
| ~~
|
||||
|
||||
error[E0425]: cannot find value `BAR` in this scope
|
||||
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:35:9
|
||||
|
|
||||
LL | BAR;
|
||||
| ^^^
|
||||
...
|
||||
LL | const BARR: u32 = 3;
|
||||
| -------------------- similarly named constant `BARR` defined here
|
||||
|
|
||||
help: you might have meant to use the associated `const`
|
||||
|
|
||||
LL | Self::BAR;
|
||||
| ~~~~~~~~~
|
||||
help: a constant with a similar name exists
|
||||
|
|
||||
LL | BARR;
|
||||
| ~~~~
|
||||
|
||||
error[E0412]: cannot find type `Baz` in this scope
|
||||
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:37:18
|
||||
|
|
||||
LL | let foo: Baz = "".to_string();
|
||||
| ^^^
|
||||
...
|
||||
LL | type Bar = String;
|
||||
| ------------------ similarly named type alias `Bar` defined here
|
||||
|
|
||||
help: you might have meant to use the associated type
|
||||
|
|
||||
LL | let foo: Self::Baz = "".to_string();
|
||||
| ~~~~~~~~~
|
||||
help: a type alias with a similar name exists
|
||||
|
|
||||
LL | let foo: Bar = "".to_string();
|
||||
| ~~~
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0412, E0425.
|
||||
For more information about an error, try `rustc --explain E0412`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue