diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-29 01:30:01 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-02 10:33:55 +0100 |
| commit | 8674efdb7c9d263caef8d282086a4243eae8df20 (patch) | |
| tree | 3dd62df510860da588ea8020fff68cae396733ff /src/test | |
| parent | cdd41ea5fc37d1ba879fd52743bde35fde4a89df (diff) | |
| download | rust-8674efdb7c9d263caef8d282086a4243eae8df20.tar.gz rust-8674efdb7c9d263caef8d282086a4243eae8df20.zip | |
parser: move restrictions re. `self` to `ast_validation`.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/invalid-self-argument/bare-fn-start.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/invalid-self-argument/bare-fn-start.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/parser/self-param-semantic-fail.rs | 64 | ||||
| -rw-r--r-- | src/test/ui/parser/self-param-semantic-fail.stderr | 220 | ||||
| -rw-r--r-- | src/test/ui/parser/self-param-syntactic-pass.rs | 66 |
5 files changed, 356 insertions, 6 deletions
diff --git a/src/test/ui/invalid-self-argument/bare-fn-start.rs b/src/test/ui/invalid-self-argument/bare-fn-start.rs index a003a01941b..8c92b7bc7c4 100644 --- a/src/test/ui/invalid-self-argument/bare-fn-start.rs +++ b/src/test/ui/invalid-self-argument/bare-fn-start.rs @@ -1,6 +1,6 @@ fn a(&self) { } -//~^ 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 +//~^ ERROR `self` parameter only allowed in associated `fn`s +//~| NOTE not semantically valid as function parameter +//~| NOTE associated `fn`s are those in `impl` or `trait` definitions fn main() { } diff --git a/src/test/ui/invalid-self-argument/bare-fn-start.stderr b/src/test/ui/invalid-self-argument/bare-fn-start.stderr index 23de6502094..59120a60a6d 100644 --- a/src/test/ui/invalid-self-argument/bare-fn-start.stderr +++ b/src/test/ui/invalid-self-argument/bare-fn-start.stderr @@ -1,10 +1,10 @@ -error: unexpected `self` parameter in function +error: `self` parameter only allowed in associated `fn`s --> $DIR/bare-fn-start.rs:1:6 | LL | fn a(&self) { } - | ^^^^^ not valid as function parameter + | ^^^^^ not semantically valid as function parameter | - = note: `self` is only valid as the first parameter of an associated function + = note: associated `fn`s are those in `impl` or `trait` definitions error: aborting due to previous error diff --git a/src/test/ui/parser/self-param-semantic-fail.rs b/src/test/ui/parser/self-param-semantic-fail.rs new file mode 100644 index 00000000000..773cf922b4d --- /dev/null +++ b/src/test/ui/parser/self-param-semantic-fail.rs @@ -0,0 +1,64 @@ +// This test ensures that `self` is semantically rejected +// in contexts with `FnDecl` but outside of associated `fn`s. +// FIXME(Centril): For now closures are an exception. + +fn main() {} + +fn free() { + fn f1(self) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f2(mut self) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f3(&self) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f4(&mut self) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f5<'a>(&'a self) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f6<'a>(&'a mut self) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f7(self: u8) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f8(mut self: u8) {} + //~^ ERROR `self` parameter only allowed in associated `fn`s +} + +extern { + fn f1(self); + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f2(mut self); + //~^ ERROR `self` parameter only allowed in associated `fn`s + //~| ERROR patterns aren't allowed in + fn f3(&self); + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f4(&mut self); + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f5<'a>(&'a self); + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f6<'a>(&'a mut self); + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f7(self: u8); + //~^ ERROR `self` parameter only allowed in associated `fn`s + fn f8(mut self: u8); + //~^ ERROR `self` parameter only allowed in associated `fn`s + //~| ERROR patterns aren't allowed in +} + +type X1 = fn(self); +//~^ ERROR `self` parameter only allowed in associated `fn`s +type X2 = fn(mut self); +//~^ ERROR `self` parameter only allowed in associated `fn`s +//~| ERROR patterns aren't allowed in +type X3 = fn(&self); +//~^ ERROR `self` parameter only allowed in associated `fn`s +type X4 = fn(&mut self); +//~^ ERROR `self` parameter only allowed in associated `fn`s +type X5 = for<'a> fn(&'a self); +//~^ ERROR `self` parameter only allowed in associated `fn`s +type X6 = for<'a> fn(&'a mut self); +//~^ ERROR `self` parameter only allowed in associated `fn`s +type X7 = fn(self: u8); +//~^ ERROR `self` parameter only allowed in associated `fn`s +type X8 = fn(mut self: u8); +//~^ ERROR `self` parameter only allowed in associated `fn`s +//~| ERROR patterns aren't allowed in diff --git a/src/test/ui/parser/self-param-semantic-fail.stderr b/src/test/ui/parser/self-param-semantic-fail.stderr new file mode 100644 index 00000000000..b45e4a5d26f --- /dev/null +++ b/src/test/ui/parser/self-param-semantic-fail.stderr @@ -0,0 +1,220 @@ +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:8:11 + | +LL | fn f1(self) {} + | ^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:10:11 + | +LL | fn f2(mut self) {} + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:12:11 + | +LL | fn f3(&self) {} + | ^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:14:11 + | +LL | fn f4(&mut self) {} + | ^^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:16:15 + | +LL | fn f5<'a>(&'a self) {} + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:18:15 + | +LL | fn f6<'a>(&'a mut self) {} + | ^^^^^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:20:11 + | +LL | fn f7(self: u8) {} + | ^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:22:11 + | +LL | fn f8(mut self: u8) {} + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:27:11 + | +LL | fn f1(self); + | ^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:29:11 + | +LL | fn f2(mut self); + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error[E0130]: patterns aren't allowed in foreign function declarations + --> $DIR/self-param-semantic-fail.rs:29:11 + | +LL | fn f2(mut self); + | ^^^^^^^^ pattern not allowed in foreign function + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:32:11 + | +LL | fn f3(&self); + | ^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:34:11 + | +LL | fn f4(&mut self); + | ^^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:36:15 + | +LL | fn f5<'a>(&'a self); + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:38:15 + | +LL | fn f6<'a>(&'a mut self); + | ^^^^^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:40:11 + | +LL | fn f7(self: u8); + | ^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:42:11 + | +LL | fn f8(mut self: u8); + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error[E0130]: patterns aren't allowed in foreign function declarations + --> $DIR/self-param-semantic-fail.rs:42:11 + | +LL | fn f8(mut self: u8); + | ^^^^^^^^ pattern not allowed in foreign function + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:47:14 + | +LL | type X1 = fn(self); + | ^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:49:14 + | +LL | type X2 = fn(mut self); + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error[E0561]: patterns aren't allowed in function pointer types + --> $DIR/self-param-semantic-fail.rs:49:14 + | +LL | type X2 = fn(mut self); + | ^^^^^^^^ + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:52:14 + | +LL | type X3 = fn(&self); + | ^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:54:14 + | +LL | type X4 = fn(&mut self); + | ^^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:56:22 + | +LL | type X5 = for<'a> fn(&'a self); + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:58:22 + | +LL | type X6 = for<'a> fn(&'a mut self); + | ^^^^^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:60:14 + | +LL | type X7 = fn(self: u8); + | ^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error: `self` parameter only allowed in associated `fn`s + --> $DIR/self-param-semantic-fail.rs:62:14 + | +LL | type X8 = fn(mut self: u8); + | ^^^^^^^^ not semantically valid as function parameter + | + = note: associated `fn`s are those in `impl` or `trait` definitions + +error[E0561]: patterns aren't allowed in function pointer types + --> $DIR/self-param-semantic-fail.rs:62:14 + | +LL | type X8 = fn(mut self: u8); + | ^^^^^^^^ + +error: aborting due to 28 previous errors + +Some errors have detailed explanations: E0130, E0561. +For more information about an error, try `rustc --explain E0130`. diff --git a/src/test/ui/parser/self-param-syntactic-pass.rs b/src/test/ui/parser/self-param-syntactic-pass.rs new file mode 100644 index 00000000000..9e215e6cdd4 --- /dev/null +++ b/src/test/ui/parser/self-param-syntactic-pass.rs @@ -0,0 +1,66 @@ +// This test ensures that `self` is syntactically accepted in all places an `FnDecl` is parsed. +// FIXME(Centril): For now closures are an exception. + +// check-pass + +fn main() {} + +#[cfg(FALSE)] +fn free() { + fn f(self) {} + fn f(mut self) {} + fn f(&self) {} + fn f(&mut self) {} + fn f(&'a self) {} + fn f(&'a mut self) {} + fn f(self: u8) {} + fn f(mut self: u8) {} +} + +#[cfg(FALSE)] +extern { + fn f(self); + fn f(mut self); + fn f(&self); + fn f(&mut self); + fn f(&'a self); + fn f(&'a mut self); + fn f(self: u8); + fn f(mut self: u8); +} + +#[cfg(FALSE)] +trait X { + fn f(self) {} + fn f(mut self) {} + fn f(&self) {} + fn f(&mut self) {} + fn f(&'a self) {} + fn f(&'a mut self) {} + fn f(self: u8) {} + fn f(mut self: u8) {} +} + +#[cfg(FALSE)] +impl X for Y { + fn f(self) {} + fn f(mut self) {} + fn f(&self) {} + fn f(&mut self) {} + fn f(&'a self) {} + fn f(&'a mut self) {} + fn f(self: u8) {} + fn f(mut self: u8) {} +} + +#[cfg(FALSE)] +impl X for Y { + type X = fn(self); + type X = fn(mut self); + type X = fn(&self); + type X = fn(&mut self); + type X = fn(&'a self); + type X = fn(&'a mut self); + type X = fn(self: u8); + type X = fn(mut self: u8); +} |
