Skip to content

Commit e6e0aff

Browse files
authored
Rollup merge of rust-lang#61087 - estebank:parsepalooza, r=Centril
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.
2 parents f1fd063 + 4e68ddc commit e6e0aff

File tree

10 files changed

+656
-566
lines changed

10 files changed

+656
-566
lines changed

src/libsyntax/parse/diagnostics.rs

+580-8
Large diffs are not rendered by default.

src/libsyntax/parse/parser.rs

+43-544
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fn a(&self) { }
2-
//~^ ERROR unexpected `self` argument in function
3-
//~| NOTE `self` is only valid as the first argument of an associated function
2+
//~^ ERROR unexpected `self` parameter in function
3+
//~| NOTE not valid as function parameter
4+
//~| NOTE `self` is only valid as the first parameter of an associated function
45

56
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: unexpected `self` argument in function
2-
--> $DIR/bare-fn-start.rs:1:7
1+
error: unexpected `self` parameter in function
2+
--> $DIR/bare-fn-start.rs:1:6
33
|
44
LL | fn a(&self) { }
5-
| ^^^^ `self` is only valid as the first argument of an associated function
5+
| ^^^^^ not valid as function parameter
6+
|
7+
= note: `self` is only valid as the first parameter of an associated function
68

79
error: aborting due to previous error
810

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fn b(foo: u32, &mut self) { }
2-
//~^ ERROR unexpected `self` argument in function
3-
//~| NOTE `self` is only valid as the first argument of an associated function
2+
//~^ ERROR unexpected `self` parameter in function
3+
//~| NOTE not valid as function parameter
4+
//~| NOTE `self` is only valid as the first parameter of an associated function
45

56
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: unexpected `self` argument in function
2-
--> $DIR/bare-fn.rs:1:21
1+
error: unexpected `self` parameter in function
2+
--> $DIR/bare-fn.rs:1:16
33
|
44
LL | fn b(foo: u32, &mut self) { }
5-
| ^^^^ `self` is only valid as the first argument of an associated function
5+
| ^^^^^^^^^ not valid as function parameter
6+
|
7+
= note: `self` is only valid as the first parameter of an associated function
68

79
error: aborting due to previous error
810

src/test/ui/invalid-self-argument/trait-fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ struct Foo {}
22

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

88
fn good(&mut self, foo: u32) {}
99
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unexpected `self` argument in function
1+
error: unexpected `self` parameter in function
22
--> $DIR/trait-fn.rs:4:20
33
|
44
LL | fn c(foo: u32, self) {}
5-
| ^^^^ `self` is only valid as the first argument of an associated function
5+
| ^^^^ must be the first associated function parameter
66

77
error: aborting due to previous error
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn foo(x:i32, self: i32) -> i32 { self } //~ ERROR unexpected `self` parameter in function
2+
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unexpected `self` parameter in function
2+
--> $DIR/self-in-function-arg.rs:1:15
3+
|
4+
LL | fn foo(x:i32, self: i32) -> i32 { self }
5+
| ^^^^ not valid as function parameter
6+
|
7+
= note: `self` is only valid as the first parameter of an associated function
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)