Rollup merge of #60061 - estebank:field-sugg, r=davidtwco
Change suggestion of field when not in self context Fix #60057.
This commit is contained in:
commit
aa58242b28
@ -166,16 +166,18 @@ impl<'a> Resolver<'a> {
|
|||||||
let self_is_available = self.self_value_is_available(path[0].ident.span, span);
|
let self_is_available = self.self_value_is_available(path[0].ident.span, span);
|
||||||
match candidate {
|
match candidate {
|
||||||
AssocSuggestion::Field => {
|
AssocSuggestion::Field => {
|
||||||
err.span_suggestion(
|
if self_is_available {
|
||||||
span,
|
err.span_suggestion(
|
||||||
"try",
|
span,
|
||||||
format!("self.{}", path_str),
|
"you might have meant to use the available field",
|
||||||
Applicability::MachineApplicable,
|
format!("self.{}", path_str),
|
||||||
);
|
Applicability::MachineApplicable,
|
||||||
if !self_is_available {
|
);
|
||||||
err.span_label(span, format!("`self` value is a keyword \
|
} else {
|
||||||
only available in \
|
err.span_label(
|
||||||
methods with `self` parameter"));
|
span,
|
||||||
|
"a field by this name exists in `Self`",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssocSuggestion::MethodWithSelf if self_is_available => {
|
AssocSuggestion::MethodWithSelf if self_is_available => {
|
||||||
|
@ -2,7 +2,7 @@ error[E0425]: cannot find value `meows` in this scope
|
|||||||
--> $DIR/class-missing-self.rs:9:7
|
--> $DIR/class-missing-self.rs:9:7
|
||||||
|
|
|
|
||||||
LL | meows += 1;
|
LL | meows += 1;
|
||||||
| ^^^^^ help: try: `self.meows`
|
| ^^^^^ help: you might have meant to use the available field: `self.meows`
|
||||||
|
|
||||||
error[E0425]: cannot find function `sleep` in this scope
|
error[E0425]: cannot find function `sleep` in this scope
|
||||||
--> $DIR/class-missing-self.rs:10:7
|
--> $DIR/class-missing-self.rs:10:7
|
||||||
|
17
src/test/ui/issues/issue-60057.rs
Normal file
17
src/test/ui/issues/issue-60057.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
struct A {
|
||||||
|
banana: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl A {
|
||||||
|
fn new(peach: u8) -> A {
|
||||||
|
A {
|
||||||
|
banana: banana //~ ERROR cannot find value `banana` in this scope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo(&self, peach: u8) -> A {
|
||||||
|
A {
|
||||||
|
banana: banana //~ ERROR cannot find value `banana` in this scope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
src/test/ui/issues/issue-60057.stderr
Normal file
20
src/test/ui/issues/issue-60057.stderr
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
error[E0425]: cannot find value `banana` in this scope
|
||||||
|
--> $DIR/issue-60057.rs:8:21
|
||||||
|
|
|
||||||
|
LL | banana: banana
|
||||||
|
| ^^^^^^ a field by this name exists in `Self`
|
||||||
|
|
||||||
|
error[E0425]: cannot find value `banana` in this scope
|
||||||
|
--> $DIR/issue-60057.rs:14:21
|
||||||
|
|
|
||||||
|
LL | banana: banana
|
||||||
|
| ^^^^^^ help: you might have meant to use the available field: `self.banana`
|
||||||
|
|
||||||
|
error[E0601]: `main` function not found in crate `issue_60057`
|
||||||
|
|
|
||||||
|
= note: consider adding a `main` function to `$DIR/issue-60057.rs`
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0425, E0601.
|
||||||
|
For more information about an error, try `rustc --explain E0425`.
|
@ -20,13 +20,13 @@ error[E0425]: cannot find value `x` in this scope
|
|||||||
--> $DIR/issue-14254.rs:30:9
|
--> $DIR/issue-14254.rs:30:9
|
||||||
|
|
|
|
||||||
LL | x;
|
LL | x;
|
||||||
| ^ help: try: `self.x`
|
| ^ help: you might have meant to use the available field: `self.x`
|
||||||
|
|
||||||
error[E0425]: cannot find value `y` in this scope
|
error[E0425]: cannot find value `y` in this scope
|
||||||
--> $DIR/issue-14254.rs:32:9
|
--> $DIR/issue-14254.rs:32:9
|
||||||
|
|
|
|
||||||
LL | y;
|
LL | y;
|
||||||
| ^ help: try: `self.y`
|
| ^ help: you might have meant to use the available field: `self.y`
|
||||||
|
|
||||||
error[E0425]: cannot find value `a` in this scope
|
error[E0425]: cannot find value `a` in this scope
|
||||||
--> $DIR/issue-14254.rs:34:9
|
--> $DIR/issue-14254.rs:34:9
|
||||||
@ -56,13 +56,13 @@ error[E0425]: cannot find value `x` in this scope
|
|||||||
--> $DIR/issue-14254.rs:47:9
|
--> $DIR/issue-14254.rs:47:9
|
||||||
|
|
|
|
||||||
LL | x;
|
LL | x;
|
||||||
| ^ help: try: `self.x`
|
| ^ help: you might have meant to use the available field: `self.x`
|
||||||
|
|
||||||
error[E0425]: cannot find value `y` in this scope
|
error[E0425]: cannot find value `y` in this scope
|
||||||
--> $DIR/issue-14254.rs:49:9
|
--> $DIR/issue-14254.rs:49:9
|
||||||
|
|
|
|
||||||
LL | y;
|
LL | y;
|
||||||
| ^ help: try: `self.y`
|
| ^ help: you might have meant to use the available field: `self.y`
|
||||||
|
|
||||||
error[E0425]: cannot find value `a` in this scope
|
error[E0425]: cannot find value `a` in this scope
|
||||||
--> $DIR/issue-14254.rs:51:9
|
--> $DIR/issue-14254.rs:51:9
|
||||||
|
@ -20,10 +20,7 @@ error[E0425]: cannot find value `whiskers` in this scope
|
|||||||
--> $DIR/issue-2356.rs:39:5
|
--> $DIR/issue-2356.rs:39:5
|
||||||
|
|
|
|
||||||
LL | whiskers -= other;
|
LL | whiskers -= other;
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^ a field by this name exists in `Self`
|
||||||
| |
|
|
||||||
| `self` value is a keyword only available in methods with `self` parameter
|
|
||||||
| help: try: `self.whiskers`
|
|
||||||
|
|
||||||
error[E0425]: cannot find function `shave` in this scope
|
error[E0425]: cannot find function `shave` in this scope
|
||||||
--> $DIR/issue-2356.rs:41:5
|
--> $DIR/issue-2356.rs:41:5
|
||||||
@ -83,16 +80,13 @@ error[E0425]: cannot find value `whiskers` in this scope
|
|||||||
--> $DIR/issue-2356.rs:79:5
|
--> $DIR/issue-2356.rs:79:5
|
||||||
|
|
|
|
||||||
LL | whiskers = 0;
|
LL | whiskers = 0;
|
||||||
| ^^^^^^^^ help: try: `self.whiskers`
|
| ^^^^^^^^ help: you might have meant to use the available field: `self.whiskers`
|
||||||
|
|
||||||
error[E0425]: cannot find value `whiskers` in this scope
|
error[E0425]: cannot find value `whiskers` in this scope
|
||||||
--> $DIR/issue-2356.rs:84:5
|
--> $DIR/issue-2356.rs:84:5
|
||||||
|
|
|
|
||||||
LL | whiskers = 4;
|
LL | whiskers = 4;
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^ a field by this name exists in `Self`
|
||||||
| |
|
|
||||||
| `self` value is a keyword only available in methods with `self` parameter
|
|
||||||
| help: try: `self.whiskers`
|
|
||||||
|
|
||||||
error[E0425]: cannot find function `purr_louder` in this scope
|
error[E0425]: cannot find function `purr_louder` in this scope
|
||||||
--> $DIR/issue-2356.rs:86:5
|
--> $DIR/issue-2356.rs:86:5
|
||||||
|
@ -14,7 +14,7 @@ error[E0425]: cannot find value `field` in this scope
|
|||||||
--> $DIR/resolve-assoc-suggestions.rs:20:9
|
--> $DIR/resolve-assoc-suggestions.rs:20:9
|
||||||
|
|
|
|
||||||
LL | field;
|
LL | field;
|
||||||
| ^^^^^ help: try: `self.field`
|
| ^^^^^ help: you might have meant to use the available field: `self.field`
|
||||||
|
|
||||||
error[E0412]: cannot find type `Type` in this scope
|
error[E0412]: cannot find type `Type` in this scope
|
||||||
--> $DIR/resolve-assoc-suggestions.rs:23:16
|
--> $DIR/resolve-assoc-suggestions.rs:23:16
|
||||||
|
@ -14,7 +14,7 @@ error[E0425]: cannot find value `field` in this scope
|
|||||||
--> $DIR/resolve-speculative-adjustment.rs:23:9
|
--> $DIR/resolve-speculative-adjustment.rs:23:9
|
||||||
|
|
|
|
||||||
LL | field;
|
LL | field;
|
||||||
| ^^^^^ help: try: `self.field`
|
| ^^^^^ help: you might have meant to use the available field: `self.field`
|
||||||
|
|
||||||
error[E0425]: cannot find function `method` in this scope
|
error[E0425]: cannot find function `method` in this scope
|
||||||
--> $DIR/resolve-speculative-adjustment.rs:25:9
|
--> $DIR/resolve-speculative-adjustment.rs:25:9
|
||||||
|
@ -2,10 +2,7 @@ error[E0425]: cannot find value `cx` in this scope
|
|||||||
--> $DIR/unresolved_static_type_field.rs:9:11
|
--> $DIR/unresolved_static_type_field.rs:9:11
|
||||||
|
|
|
|
||||||
LL | f(cx);
|
LL | f(cx);
|
||||||
| ^^
|
| ^^ a field by this name exists in `Self`
|
||||||
| |
|
|
||||||
| `self` value is a keyword only available in methods with `self` parameter
|
|
||||||
| help: try: `self.cx`
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user