File tree 3 files changed +42
-1
lines changed
compiler/rustc_parse/src/parser
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -2773,7 +2773,14 @@ impl<'a> Parser<'a> {
2773
2773
let snapshot = p. create_snapshot_for_diagnostic ( ) ;
2774
2774
let param = p. parse_param_general ( req_name, first_param) . or_else ( |e| {
2775
2775
let guar = e. emit ( ) ;
2776
- let lo = p. prev_token . span ;
2776
+ // When parsing a param failed, we should check to make the span of the param
2777
+ // not contain '(' before it.
2778
+ // For example when parsing `*mut Self` in function `fn oof(*mut Self)`.
2779
+ let lo = if let TokenKind :: OpenDelim ( Delimiter :: Parenthesis ) = p. prev_token . kind {
2780
+ p. prev_token . span . shrink_to_hi ( )
2781
+ } else {
2782
+ p. prev_token . span
2783
+ } ;
2777
2784
p. restore_snapshot ( snapshot) ;
2778
2785
// Skip every token until next possible arg or end.
2779
2786
p. eat_to_tokens ( & [ & token:: Comma , & token:: CloseDelim ( Delimiter :: Parenthesis ) ] ) ;
Original file line number Diff line number Diff line change
1
+ struct Thing {
2
+ state : u8 ,
3
+ }
4
+
5
+ impl Thing {
6
+ fn oof ( * mut Self ) { //~ ERROR expected parameter name, found `*`
7
+ self . state = 1 ;
8
+ //~^ ERROR expected value, found module `self`
9
+ }
10
+ }
11
+
12
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: expected parameter name, found `*`
2
+ --> $DIR/suggest-add-self-issue-128042.rs:6:12
3
+ |
4
+ LL | fn oof(*mut Self) {
5
+ | ^ expected parameter name
6
+
7
+ error[E0424]: expected value, found module `self`
8
+ --> $DIR/suggest-add-self-issue-128042.rs:7:9
9
+ |
10
+ LL | fn oof(*mut Self) {
11
+ | --- this function doesn't have a `self` parameter
12
+ LL | self.state = 1;
13
+ | ^^^^ `self` value is a keyword only available in methods with a `self` parameter
14
+ |
15
+ help: add a `self` receiver parameter to make the associated `fn` a method
16
+ |
17
+ LL | fn oof(&self, *mut Self) {
18
+ | ++++++
19
+
20
+ error: aborting due to 2 previous errors
21
+
22
+ For more information about this error, try `rustc --explain E0424`.
You can’t perform that action at this time.
0 commit comments