parse associated statics.
This commit is contained in:
parent
1c2906ead3
commit
f8d2264463
21 changed files with 243 additions and 42 deletions
43
src/test/ui/parser/assoc-static-semantic-fail.rs
Normal file
43
src/test/ui/parser/assoc-static-semantic-fail.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Semantically, we do not allow e.g., `static X: u8 = 0;` as an associated item.
|
||||
|
||||
#![feature(specialization)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
struct S;
|
||||
impl S {
|
||||
static IA: u8 = 0;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
static IB: u8;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
default static IC: u8 = 0;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
pub(crate) default static ID: u8;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
}
|
||||
|
||||
trait T {
|
||||
static TA: u8 = 0;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
static TB: u8;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
default static TC: u8 = 0;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
//~| ERROR `default` is only allowed on items in
|
||||
pub(crate) default static TD: u8;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
//~| ERROR `default` is only allowed on items in
|
||||
//~| ERROR unnecessary visibility qualifier
|
||||
}
|
||||
|
||||
impl T for S {
|
||||
static TA: u8 = 0;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
static TB: u8;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
default static TC: u8 = 0;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
pub default static TD: u8;
|
||||
//~^ ERROR associated `static` items are not allowed
|
||||
//~| ERROR unnecessary visibility qualifier
|
||||
}
|
||||
99
src/test/ui/parser/assoc-static-semantic-fail.stderr
Normal file
99
src/test/ui/parser/assoc-static-semantic-fail.stderr
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:9:5
|
||||
|
|
||||
LL | static IA: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:11:5
|
||||
|
|
||||
LL | static IB: u8;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:13:5
|
||||
|
|
||||
LL | default static IC: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:15:5
|
||||
|
|
||||
LL | pub(crate) default static ID: u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:20:5
|
||||
|
|
||||
LL | static TA: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:22:5
|
||||
|
|
||||
LL | static TB: u8;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/assoc-static-semantic-fail.rs:24:5
|
||||
|
|
||||
LL | default static TC: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:24:5
|
||||
|
|
||||
LL | default static TC: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/assoc-static-semantic-fail.rs:27:5
|
||||
|
|
||||
LL | pub(crate) default static TD: u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0449]: unnecessary visibility qualifier
|
||||
--> $DIR/assoc-static-semantic-fail.rs:27:5
|
||||
|
|
||||
LL | pub(crate) default static TD: u8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:27:5
|
||||
|
|
||||
LL | pub(crate) default static TD: u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:34:5
|
||||
|
|
||||
LL | static TA: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:36:5
|
||||
|
|
||||
LL | static TB: u8;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:38:5
|
||||
|
|
||||
LL | default static TC: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0449]: unnecessary visibility qualifier
|
||||
--> $DIR/assoc-static-semantic-fail.rs:40:5
|
||||
|
|
||||
LL | pub default static TD: u8;
|
||||
| ^^^ `pub` not permitted here because it's implied
|
||||
|
||||
error: associated `static` items are not allowed
|
||||
--> $DIR/assoc-static-semantic-fail.rs:40:5
|
||||
|
|
||||
LL | pub default static TD: u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0449`.
|
||||
29
src/test/ui/parser/assoc-static-syntactic-pass.rs
Normal file
29
src/test/ui/parser/assoc-static-syntactic-pass.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Syntactically, we do allow e.g., `static X: u8 = 0;` as an associated item.
|
||||
|
||||
// check-pass
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
impl S {
|
||||
static IA: u8 = 0;
|
||||
static IB: u8;
|
||||
default static IC: u8 = 0;
|
||||
pub(crate) default static ID: u8;
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
trait T {
|
||||
static TA: u8 = 0;
|
||||
static TB: u8;
|
||||
default static TC: u8 = 0;
|
||||
pub(crate) default static TD: u8;
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
impl T for S {
|
||||
static TA: u8 = 0;
|
||||
static TB: u8;
|
||||
default static TC: u8 = 0;
|
||||
pub default static TD: u8;
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, `}`, or identifier, found `...`
|
||||
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, `}`, or identifier, found `...`
|
||||
--> $DIR/issue-32446.rs:4:11
|
||||
|
|
||||
LL | trait T { ... }
|
||||
| ^^^ expected one of 11 possible tokens
|
||||
| ^^^ expected one of 12 possible tokens
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `type`, `unsafe`, or identifier, found `}`
|
||||
error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `static`, `type`, `unsafe`, or identifier, found `}`
|
||||
--> $DIR/issue-41155.rs:5:1
|
||||
|
|
||||
LL | pub
|
||||
| - expected one of 9 possible tokens
|
||||
| - expected one of 10 possible tokens
|
||||
LL | }
|
||||
| ^ unexpected token
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or identifier, found `2`
|
||||
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, or identifier, found `2`
|
||||
--> $DIR/trait-non-item-macros.rs:2:19
|
||||
|
|
||||
LL | ($a:expr) => ($a)
|
||||
| ^^ expected one of 10 possible tokens
|
||||
| ^^ expected one of 11 possible tokens
|
||||
...
|
||||
LL | bah!(2);
|
||||
| -------- in this macro invocation
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
struct S;
|
||||
|
||||
impl S {
|
||||
//~^ ERROR missing `fn`, `type`, or `const` for associated-item declaration
|
||||
static fn f() {}
|
||||
//~^ ERROR expected identifier, found keyword `fn`
|
||||
//~| ERROR expected one of `:`, `;`, or `=`
|
||||
//~| ERROR missing type for `static` item
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
error: missing `fn`, `type`, or `const` for associated-item declaration
|
||||
--> $DIR/removed-syntax-static-fn.rs:3:9
|
||||
error: expected identifier, found keyword `fn`
|
||||
--> $DIR/removed-syntax-static-fn.rs:4:12
|
||||
|
|
||||
LL | impl S {
|
||||
| _________^
|
||||
LL | |
|
||||
LL | | static fn f() {}
|
||||
| |____^ missing `fn`, `type`, or `const`
|
||||
LL | static fn f() {}
|
||||
| ^^ expected identifier, found keyword
|
||||
|
||||
error: aborting due to previous error
|
||||
error: expected one of `:`, `;`, or `=`, found `f`
|
||||
--> $DIR/removed-syntax-static-fn.rs:4:15
|
||||
|
|
||||
LL | static fn f() {}
|
||||
| ^ expected one of `:`, `;`, or `=`
|
||||
|
||||
error: missing type for `static` item
|
||||
--> $DIR/removed-syntax-static-fn.rs:4:12
|
||||
|
|
||||
LL | static fn f() {}
|
||||
| ^^ help: provide a type for the item: `r#fn: <type>`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue