Skip to content

Commit

Permalink
Rollup merge of rust-lang#61087 - estebank:parsepalooza, r=Centril
Browse files Browse the repository at this point in the history
Tweak `self` arg not as first argument of a method diagnostic

Mention that `self` is only valid on "associated functions"
```
error: unexpected `self` argument in function
  --> $DIR/self-in-function-arg.rs:1:15
   |
LL | fn foo(x:i32, self: i32) -> i32 { self }
   |               ^^^^ not valid as function argument
   |
   = note: `self` is only valid as the first argument of an associated function
```

When it is a method, mention it must be first
```
error: unexpected `self` argument in function
  --> $DIR/trait-fn.rs:4:20
   |
LL |     fn c(foo: u32, self) {}
   |                    ^^^^ must be the first associated function argument
```

Move a bunch of error recovery methods to `diagnostics.rs` away from `parser.rs`.

Fix rust-lang#51547. CC rust-lang#60015.
  • Loading branch information
Centril committed May 26, 2019
2 parents f492693 + 4e68ddc commit 24cc368
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 566 deletions.
588 changes: 580 additions & 8 deletions src/libsyntax/parse/diagnostics.rs

Large diffs are not rendered by default.

587 changes: 43 additions & 544 deletions src/libsyntax/parse/parser.rs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/test/ui/invalid-self-argument/bare-fn-start.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn a(&self) { }
//~^ ERROR unexpected `self` argument in function
//~| NOTE `self` is only valid as the first argument of an associated function
//~^ ERROR unexpected `self` parameter in function
//~| NOTE not valid as function parameter
//~| NOTE `self` is only valid as the first parameter of an associated function

fn main() { }
8 changes: 5 additions & 3 deletions src/test/ui/invalid-self-argument/bare-fn-start.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error: unexpected `self` argument in function
--> $DIR/bare-fn-start.rs:1:7
error: unexpected `self` parameter in function
--> $DIR/bare-fn-start.rs:1:6
|
LL | fn a(&self) { }
| ^^^^ `self` is only valid as the first argument of an associated function
| ^^^^^ not valid as function parameter
|
= note: `self` is only valid as the first parameter of an associated function

error: aborting due to previous error

5 changes: 3 additions & 2 deletions src/test/ui/invalid-self-argument/bare-fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn b(foo: u32, &mut self) { }
//~^ ERROR unexpected `self` argument in function
//~| NOTE `self` is only valid as the first argument of an associated function
//~^ ERROR unexpected `self` parameter in function
//~| NOTE not valid as function parameter
//~| NOTE `self` is only valid as the first parameter of an associated function

fn main() { }
8 changes: 5 additions & 3 deletions src/test/ui/invalid-self-argument/bare-fn.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error: unexpected `self` argument in function
--> $DIR/bare-fn.rs:1:21
error: unexpected `self` parameter in function
--> $DIR/bare-fn.rs:1:16
|
LL | fn b(foo: u32, &mut self) { }
| ^^^^ `self` is only valid as the first argument of an associated function
| ^^^^^^^^^ not valid as function parameter
|
= note: `self` is only valid as the first parameter of an associated function

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/invalid-self-argument/trait-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ struct Foo {}

impl Foo {
fn c(foo: u32, self) {}
//~^ ERROR unexpected `self` argument in function
//~| NOTE `self` is only valid as the first argument of an associated function
//~^ ERROR unexpected `self` parameter in function
//~| NOTE must be the first associated function parameter

fn good(&mut self, foo: u32) {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/invalid-self-argument/trait-fn.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unexpected `self` argument in function
error: unexpected `self` parameter in function
--> $DIR/trait-fn.rs:4:20
|
LL | fn c(foo: u32, self) {}
| ^^^^ `self` is only valid as the first argument of an associated function
| ^^^^ must be the first associated function parameter

error: aborting due to previous error

3 changes: 3 additions & 0 deletions src/test/ui/parser/self-in-function-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn foo(x:i32, self: i32) -> i32 { self } //~ ERROR unexpected `self` parameter in function

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/parser/self-in-function-arg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: unexpected `self` parameter in function
--> $DIR/self-in-function-arg.rs:1:15
|
LL | fn foo(x:i32, self: i32) -> i32 { self }
| ^^^^ not valid as function parameter
|
= note: `self` is only valid as the first parameter of an associated function

error: aborting due to previous error

0 comments on commit 24cc368

Please sign in to comment.