diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-15 01:50:26 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-15 20:57:12 +0100 |
| commit | f8d2264463162291f5cb3391c98d7bc95ec17d87 (patch) | |
| tree | 513c6f3eae554053189a205993fe56db960b6462 /src/test/ui/parser | |
| parent | 1c2906ead3825c013ac022249f1e1ee3a3b97c75 (diff) | |
| download | rust-f8d2264463162291f5cb3391c98d7bc95ec17d87.tar.gz rust-f8d2264463162291f5cb3391c98d7bc95ec17d87.zip | |
parse associated statics.
Diffstat (limited to 'src/test/ui/parser')
| -rw-r--r-- | src/test/ui/parser/assoc-static-semantic-fail.rs | 43 | ||||
| -rw-r--r-- | src/test/ui/parser/assoc-static-semantic-fail.stderr | 99 | ||||
| -rw-r--r-- | src/test/ui/parser/assoc-static-syntactic-pass.rs | 29 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-32446.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-41155.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/macro/trait-non-item-macros.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/removed-syntax-static-fn.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/removed-syntax-static-fn.stderr | 25 |
8 files changed, 197 insertions, 15 deletions
diff --git a/src/test/ui/parser/assoc-static-semantic-fail.rs b/src/test/ui/parser/assoc-static-semantic-fail.rs new file mode 100644 index 00000000000..cf3debd77cb --- /dev/null +++ b/src/test/ui/parser/assoc-static-semantic-fail.rs @@ -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 +} diff --git a/src/test/ui/parser/assoc-static-semantic-fail.stderr b/src/test/ui/parser/assoc-static-semantic-fail.stderr new file mode 100644 index 00000000000..d5a02c9bebc --- /dev/null +++ b/src/test/ui/parser/assoc-static-semantic-fail.stderr @@ -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`. diff --git a/src/test/ui/parser/assoc-static-syntactic-pass.rs b/src/test/ui/parser/assoc-static-syntactic-pass.rs new file mode 100644 index 00000000000..7f5b9f79335 --- /dev/null +++ b/src/test/ui/parser/assoc-static-syntactic-pass.rs @@ -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; +} diff --git a/src/test/ui/parser/issue-32446.stderr b/src/test/ui/parser/issue-32446.stderr index 25c1efe35ae..d25828da0b9 100644 --- a/src/test/ui/parser/issue-32446.stderr +++ b/src/test/ui/parser/issue-32446.stderr @@ -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 diff --git a/src/test/ui/parser/issue-41155.stderr b/src/test/ui/parser/issue-41155.stderr index 327bc65818f..a91ef6c67e8 100644 --- a/src/test/ui/parser/issue-41155.stderr +++ b/src/test/ui/parser/issue-41155.stderr @@ -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 diff --git a/src/test/ui/parser/macro/trait-non-item-macros.stderr b/src/test/ui/parser/macro/trait-non-item-macros.stderr index 9d05e85bcc0..c76b096a1eb 100644 --- a/src/test/ui/parser/macro/trait-non-item-macros.stderr +++ b/src/test/ui/parser/macro/trait-non-item-macros.stderr @@ -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 diff --git a/src/test/ui/parser/removed-syntax-static-fn.rs b/src/test/ui/parser/removed-syntax-static-fn.rs index 9e12222f3fd..cd643b874db 100644 --- a/src/test/ui/parser/removed-syntax-static-fn.rs +++ b/src/test/ui/parser/removed-syntax-static-fn.rs @@ -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() {} diff --git a/src/test/ui/parser/removed-syntax-static-fn.stderr b/src/test/ui/parser/removed-syntax-static-fn.stderr index 5edf88026fb..dc5625bdade 100644 --- a/src/test/ui/parser/removed-syntax-static-fn.stderr +++ b/src/test/ui/parser/removed-syntax-static-fn.stderr @@ -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 |
