File tree 9 files changed +60
-30
lines changed
9 files changed +60
-30
lines changed Original file line number Diff line number Diff line change @@ -166,16 +166,18 @@ impl<'a> Resolver<'a> {
166
166
let self_is_available = self . self_value_is_available ( path[ 0 ] . ident . span , span) ;
167
167
match candidate {
168
168
AssocSuggestion :: Field => {
169
- err. span_suggestion (
170
- span,
171
- "try" ,
172
- format ! ( "self.{}" , path_str) ,
173
- Applicability :: MachineApplicable ,
174
- ) ;
175
- if !self_is_available {
176
- err. span_label ( span, format ! ( "`self` value is a keyword \
177
- only available in \
178
- methods with `self` parameter") ) ;
169
+ if self_is_available {
170
+ err. span_suggestion (
171
+ span,
172
+ "you might have meant to use the available field" ,
173
+ format ! ( "self.{}" , path_str) ,
174
+ Applicability :: MachineApplicable ,
175
+ ) ;
176
+ } else {
177
+ err. span_label (
178
+ span,
179
+ "a field by this name exists in `Self`" ,
180
+ ) ;
179
181
}
180
182
}
181
183
AssocSuggestion :: MethodWithSelf if self_is_available => {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ error[E0425]: cannot find value `meows` in this scope
2
2
--> $DIR/class-missing-self.rs:9:7
3
3
|
4
4
LL | meows += 1;
5
- | ^^^^^ help: try : `self.meows`
5
+ | ^^^^^ help: you might have meant to use the available field : `self.meows`
6
6
7
7
error[E0425]: cannot find function `sleep` in this scope
8
8
--> $DIR/class-missing-self.rs:10:7
Original file line number Diff line number Diff line change
1
+ struct A {
2
+ banana : u8 ,
3
+ }
4
+
5
+ impl A {
6
+ fn new ( peach : u8 ) -> A {
7
+ A {
8
+ banana : banana //~ ERROR cannot find value `banana` in this scope
9
+ }
10
+ }
11
+
12
+ fn foo ( & self , peach : u8 ) -> A {
13
+ A {
14
+ banana : banana //~ ERROR cannot find value `banana` in this scope
15
+ }
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ error[E0425]: cannot find value `banana` in this scope
2
+ --> $DIR/issue-60057.rs:8:21
3
+ |
4
+ LL | banana: banana
5
+ | ^^^^^^ a field by this name exists in `Self`
6
+
7
+ error[E0425]: cannot find value `banana` in this scope
8
+ --> $DIR/issue-60057.rs:14:21
9
+ |
10
+ LL | banana: banana
11
+ | ^^^^^^ help: you might have meant to use the available field: `self.banana`
12
+
13
+ error[E0601]: `main` function not found in crate `issue_60057`
14
+ |
15
+ = note: consider adding a `main` function to `$DIR/issue-60057.rs`
16
+
17
+ error: aborting due to 3 previous errors
18
+
19
+ Some errors occurred: E0425, E0601.
20
+ For more information about an error, try `rustc --explain E0425`.
Original file line number Diff line number Diff line change @@ -20,13 +20,13 @@ error[E0425]: cannot find value `x` in this scope
20
20
--> $DIR/issue-14254.rs:30:9
21
21
|
22
22
LL | x;
23
- | ^ help: try : `self.x`
23
+ | ^ help: you might have meant to use the available field : `self.x`
24
24
25
25
error[E0425]: cannot find value `y` in this scope
26
26
--> $DIR/issue-14254.rs:32:9
27
27
|
28
28
LL | y;
29
- | ^ help: try : `self.y`
29
+ | ^ help: you might have meant to use the available field : `self.y`
30
30
31
31
error[E0425]: cannot find value `a` in this scope
32
32
--> $DIR/issue-14254.rs:34:9
@@ -56,13 +56,13 @@ error[E0425]: cannot find value `x` in this scope
56
56
--> $DIR/issue-14254.rs:47:9
57
57
|
58
58
LL | x;
59
- | ^ help: try : `self.x`
59
+ | ^ help: you might have meant to use the available field : `self.x`
60
60
61
61
error[E0425]: cannot find value `y` in this scope
62
62
--> $DIR/issue-14254.rs:49:9
63
63
|
64
64
LL | y;
65
- | ^ help: try : `self.y`
65
+ | ^ help: you might have meant to use the available field : `self.y`
66
66
67
67
error[E0425]: cannot find value `a` in this scope
68
68
--> $DIR/issue-14254.rs:51:9
Original file line number Diff line number Diff line change @@ -20,10 +20,7 @@ error[E0425]: cannot find value `whiskers` in this scope
20
20
--> $DIR/issue-2356.rs:39:5
21
21
|
22
22
LL | whiskers -= other;
23
- | ^^^^^^^^
24
- | |
25
- | `self` value is a keyword only available in methods with `self` parameter
26
- | help: try: `self.whiskers`
23
+ | ^^^^^^^^ a field by this name exists in `Self`
27
24
28
25
error[E0425]: cannot find function `shave` in this scope
29
26
--> $DIR/issue-2356.rs:41:5
@@ -83,16 +80,13 @@ error[E0425]: cannot find value `whiskers` in this scope
83
80
--> $DIR/issue-2356.rs:79:5
84
81
|
85
82
LL | whiskers = 0;
86
- | ^^^^^^^^ help: try : `self.whiskers`
83
+ | ^^^^^^^^ help: you might have meant to use the available field : `self.whiskers`
87
84
88
85
error[E0425]: cannot find value `whiskers` in this scope
89
86
--> $DIR/issue-2356.rs:84:5
90
87
|
91
88
LL | whiskers = 4;
92
- | ^^^^^^^^
93
- | |
94
- | `self` value is a keyword only available in methods with `self` parameter
95
- | help: try: `self.whiskers`
89
+ | ^^^^^^^^ a field by this name exists in `Self`
96
90
97
91
error[E0425]: cannot find function `purr_louder` in this scope
98
92
--> $DIR/issue-2356.rs:86:5
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ error[E0425]: cannot find value `field` in this scope
14
14
--> $DIR/resolve-assoc-suggestions.rs:20:9
15
15
|
16
16
LL | field;
17
- | ^^^^^ help: try : `self.field`
17
+ | ^^^^^ help: you might have meant to use the available field : `self.field`
18
18
19
19
error[E0412]: cannot find type `Type` in this scope
20
20
--> $DIR/resolve-assoc-suggestions.rs:23:16
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ error[E0425]: cannot find value `field` in this scope
14
14
--> $DIR/resolve-speculative-adjustment.rs:23:9
15
15
|
16
16
LL | field;
17
- | ^^^^^ help: try : `self.field`
17
+ | ^^^^^ help: you might have meant to use the available field : `self.field`
18
18
19
19
error[E0425]: cannot find function `method` in this scope
20
20
--> $DIR/resolve-speculative-adjustment.rs:25:9
Original file line number Diff line number Diff line change @@ -2,10 +2,7 @@ error[E0425]: cannot find value `cx` in this scope
2
2
--> $DIR/unresolved_static_type_field.rs:9:11
3
3
|
4
4
LL | f(cx);
5
- | ^^
6
- | |
7
- | `self` value is a keyword only available in methods with `self` parameter
8
- | help: try: `self.cx`
5
+ | ^^ a field by this name exists in `Self`
9
6
10
7
error: aborting due to previous error
11
8
You can’t perform that action at this time.
0 commit comments