about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-02-25 23:23:09 +0000
committerbors <bors@rust-lang.org>2019-02-25 23:23:09 +0000
commit55c173c8ae8bda689fd609f391ee5e2e5b1b6d44 (patch)
tree5ca60dab865a318838d231b43402536ebbb46954 /src/test
parent00aae71f503b1ab592f48de47dd30912f3858748 (diff)
parenteccc19996b1e6a38568544e0be3cfe971caa12eb (diff)
Auto merge of #57367 - petrochenkov:unrestab, r=Centril
Stabilize `unrestricted_attribute_tokens`

In accordance with a plan described in https://internals.rust-lang.org/t/unrestricted-attribute-tokens-feature-status/8561/3.

Delimited non-macro non-builtin attributes now support the same syntax as macro attributes:
```
PATH
PATH `(` TOKEN_STREAM `)`
PATH `[` TOKEN_STREAM `]`
PATH `{` TOKEN_STREAM `}`
```
Such attributes mostly serve as inert proc macro helpers or tool attributes.
To some extent these attributes are de-facto stable due to a hole in feature gate checking (feature gating is done too late - after macro expansion.)
So if macro *removes* such helper attributes during expansion (and it must remove them, unless it's a derive macro), then the code will work on stable.

Key-value non-macro non-builtin attributes are now restricted to bare minimum required to support what we support on stable - unsuffixed literals (https://github.com/rust-lang/rust/issues/34981).
```
PATH `=` LITERAL
```
(Key-value macro attributes are not supported at all right now.)
Crater run in https://github.com/rust-lang/rust/pull/57321 found no regressions for this change.
There are multiple possible ways to extend key-value attributes (https://github.com/rust-lang/rust/pull/57321#issuecomment-451574065), but I'd expect an RFC for that and it's not a pressing enough issue to block stabilization of delimited attributes.

Built-in attributes are still restricted to the "classic" meta-item syntax, nothing changes here.
https://github.com/rust-lang/rust/pull/57321 goes further and adds some additional restrictions (more consistent input checking) to built-in attributes.

Closes https://github.com/rust-lang/rust/issues/55208
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/proc-macro/derive-b.rs2
-rw-r--r--src/test/ui/attr-eq-token-tree.rs6
-rw-r--r--src/test/ui/attr-eq-token-tree.stderr8
-rw-r--r--src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs7
-rw-r--r--src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr20
-rw-r--r--src/test/ui/macros/macro-attribute.rs4
-rw-r--r--src/test/ui/macros/macro-attribute.stderr8
-rw-r--r--src/test/ui/malformed/malformed-interpolated.rs18
-rw-r--r--src/test/ui/malformed/malformed-interpolated.stderr31
-rw-r--r--src/test/ui/marker_trait_attr/marker-attribute-with-values.rs5
-rw-r--r--src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr12
-rw-r--r--src/test/ui/parser/attr-bad-meta-2.stderr4
-rw-r--r--src/test/ui/parser/attr-bad-meta.rs2
-rw-r--r--src/test/ui/parser/attr-bad-meta.stderr2
-rw-r--r--src/test/ui/proc-macro/proc-macro-attributes.rs1
-rw-r--r--src/test/ui/proc-macro/proc-macro-attributes.stderr16
-rw-r--r--src/test/ui/proc-macro/proc-macro-gates.rs2
-rw-r--r--src/test/ui/proc-macro/proc-macro-gates.stderr4
-rw-r--r--src/test/ui/unrestricted-attribute-tokens.rs4
19 files changed, 86 insertions, 70 deletions
diff --git a/src/test/run-pass/proc-macro/derive-b.rs b/src/test/run-pass/proc-macro/derive-b.rs
index af48cabca99..da67534364b 100644
--- a/src/test/run-pass/proc-macro/derive-b.rs
+++ b/src/test/run-pass/proc-macro/derive-b.rs
@@ -1,7 +1,5 @@
 // aux-build:derive-b.rs
 
-#![feature(unrestricted_attribute_tokens)]
-
 extern crate derive_b;
 
 #[derive(Debug, PartialEq, derive_b::B, Eq, Copy, Clone)]
diff --git a/src/test/ui/attr-eq-token-tree.rs b/src/test/ui/attr-eq-token-tree.rs
index f28f76db938..6aacb9d572a 100644
--- a/src/test/ui/attr-eq-token-tree.rs
+++ b/src/test/ui/attr-eq-token-tree.rs
@@ -1,6 +1,4 @@
-// compile-pass
+#![feature(custom_attribute)]
 
-#![feature(custom_attribute, unrestricted_attribute_tokens)]
-
-#[my_attr = !] // OK under feature gate
+#[my_attr = !] //~ ERROR unexpected token: `!`
 fn main() {}
diff --git a/src/test/ui/attr-eq-token-tree.stderr b/src/test/ui/attr-eq-token-tree.stderr
new file mode 100644
index 00000000000..57d6a4e0f16
--- /dev/null
+++ b/src/test/ui/attr-eq-token-tree.stderr
@@ -0,0 +1,8 @@
+error: unexpected token: `!`
+  --> $DIR/attr-eq-token-tree.rs:3:11
+   |
+LL | #[my_attr = !] //~ ERROR unexpected token: `!`
+   |           ^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs b/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs
deleted file mode 100644
index 181c8592c54..00000000000
--- a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-#![feature(custom_attribute)]
-
-#[my_attr(a b c d)]
-//~^ ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `b`
-//~| ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `c`
-//~| ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `d`
-fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr b/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr
deleted file mode 100644
index 1ddf2ff6d64..00000000000
--- a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr
+++ /dev/null
@@ -1,20 +0,0 @@
-error: expected one of `(`, `)`, `,`, `::`, or `=`, found `b`
-  --> $DIR/feature-gate-unrestricted-attribute-tokens.rs:3:13
-   |
-LL | #[my_attr(a b c d)]
-   |             ^ expected one of `(`, `)`, `,`, `::`, or `=` here
-
-error: expected one of `(`, `)`, `,`, `::`, or `=`, found `c`
-  --> $DIR/feature-gate-unrestricted-attribute-tokens.rs:3:15
-   |
-LL | #[my_attr(a b c d)]
-   |               ^ expected one of `(`, `)`, `,`, `::`, or `=` here
-
-error: expected one of `(`, `)`, `,`, `::`, or `=`, found `d`
-  --> $DIR/feature-gate-unrestricted-attribute-tokens.rs:3:17
-   |
-LL | #[my_attr(a b c d)]
-   |                 ^ expected one of `(`, `)`, `,`, `::`, or `=` here
-
-error: aborting due to 3 previous errors
-
diff --git a/src/test/ui/macros/macro-attribute.rs b/src/test/ui/macros/macro-attribute.rs
index 7ddac2745c5..f580dfa8e34 100644
--- a/src/test/ui/macros/macro-attribute.rs
+++ b/src/test/ui/macros/macro-attribute.rs
@@ -1,4 +1,2 @@
-#![feature(unrestricted_attribute_tokens)]
-
-#[doc = $not_there] //~ ERROR expected `]`, found `not_there`
+#[doc = $not_there] //~ ERROR unexpected token: `$`
 fn main() { }
diff --git a/src/test/ui/macros/macro-attribute.stderr b/src/test/ui/macros/macro-attribute.stderr
index fd4e7252d53..7314e483348 100644
--- a/src/test/ui/macros/macro-attribute.stderr
+++ b/src/test/ui/macros/macro-attribute.stderr
@@ -1,8 +1,8 @@
-error: expected `]`, found `not_there`
-  --> $DIR/macro-attribute.rs:3:10
+error: unexpected token: `$`
+  --> $DIR/macro-attribute.rs:1:7
    |
-LL | #[doc = $not_there] //~ ERROR expected `]`, found `not_there`
-   |          ^^^^^^^^^ expected `]`
+LL | #[doc = $not_there] //~ ERROR unexpected token: `$`
+   |       ^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/malformed/malformed-interpolated.rs b/src/test/ui/malformed/malformed-interpolated.rs
new file mode 100644
index 00000000000..e452435968b
--- /dev/null
+++ b/src/test/ui/malformed/malformed-interpolated.rs
@@ -0,0 +1,18 @@
+#![feature(custom_attribute)]
+
+macro_rules! check {
+    ($expr: expr) => (
+        #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes
+                           //~| ERROR unexpected token: `-0`
+                           //~| ERROR unexpected token: `0 + 0`
+        use main as _;
+    );
+}
+
+check!("0"); // OK
+check!(0); // OK
+check!(0u8); // ERROR, see above
+check!(-0); // ERROR, see above
+check!(0 + 0); // ERROR, see above
+
+fn main() {}
diff --git a/src/test/ui/malformed/malformed-interpolated.stderr b/src/test/ui/malformed/malformed-interpolated.stderr
new file mode 100644
index 00000000000..24aa590c4d9
--- /dev/null
+++ b/src/test/ui/malformed/malformed-interpolated.stderr
@@ -0,0 +1,31 @@
+error: suffixed literals are not allowed in attributes
+  --> $DIR/malformed-interpolated.rs:5:21
+   |
+LL |         #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes
+   |                     ^^^^^
+...
+LL | check!(0u8); // ERROR, see above
+   | ------------ in this macro invocation
+   |
+   = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.).
+
+error: unexpected token: `-0`
+  --> $DIR/malformed-interpolated.rs:5:19
+   |
+LL |         #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes
+   |                   ^
+...
+LL | check!(-0); // ERROR, see above
+   | ----------- in this macro invocation
+
+error: unexpected token: `0 + 0`
+  --> $DIR/malformed-interpolated.rs:5:19
+   |
+LL |         #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes
+   |                   ^
+...
+LL | check!(0 + 0); // ERROR, see above
+   | -------------- in this macro invocation
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs b/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs
index ea356d574f6..f8bcec78650 100644
--- a/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs
+++ b/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs
@@ -1,5 +1,4 @@
 #![feature(marker_trait_attr)]
-#![feature(unrestricted_attribute_tokens)]
 
 #[marker(always)]
 trait Marker1 {}
@@ -9,8 +8,8 @@ trait Marker1 {}
 trait Marker2 {}
 //~^^ ERROR attribute must be of the form
 
-#[marker(key = value)]
+#[marker(key = "value")]
 trait Marker3 {}
-//~^^ ERROR expected unsuffixed literal or identifier, found value
+//~^^ ERROR attribute must be of the form `#[marker]`
 
 fn main() {}
diff --git a/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr b/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr
index c683b393d84..2b31dcb4760 100644
--- a/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr
+++ b/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr
@@ -1,20 +1,20 @@
 error: attribute must be of the form `#[marker]`
-  --> $DIR/marker-attribute-with-values.rs:4:1
+  --> $DIR/marker-attribute-with-values.rs:3:1
    |
 LL | #[marker(always)]
    | ^^^^^^^^^^^^^^^^^
 
 error: attribute must be of the form `#[marker]`
-  --> $DIR/marker-attribute-with-values.rs:8:1
+  --> $DIR/marker-attribute-with-values.rs:7:1
    |
 LL | #[marker("never")]
    | ^^^^^^^^^^^^^^^^^^
 
-error: expected unsuffixed literal or identifier, found value
-  --> $DIR/marker-attribute-with-values.rs:12:10
+error: attribute must be of the form `#[marker]`
+  --> $DIR/marker-attribute-with-values.rs:11:1
    |
-LL | #[marker(key = value)]
-   |          ^^^
+LL | #[marker(key = "value")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/parser/attr-bad-meta-2.stderr b/src/test/ui/parser/attr-bad-meta-2.stderr
index ddc7a4b034b..36e566b5aa4 100644
--- a/src/test/ui/parser/attr-bad-meta-2.stderr
+++ b/src/test/ui/parser/attr-bad-meta-2.stderr
@@ -1,8 +1,8 @@
 error: unexpected token: `]`
-  --> $DIR/attr-bad-meta-2.rs:1:9
+  --> $DIR/attr-bad-meta-2.rs:1:8
    |
 LL | #[path =] //~ ERROR unexpected token: `]`
-   |         ^ unexpected token after this
+   |        ^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/attr-bad-meta.rs b/src/test/ui/parser/attr-bad-meta.rs
index 7fe54272491..8001977f5a3 100644
--- a/src/test/ui/parser/attr-bad-meta.rs
+++ b/src/test/ui/parser/attr-bad-meta.rs
@@ -1,4 +1,2 @@
-#![feature(unrestricted_attribute_tokens)]
-
 #[path*] //~ ERROR expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*`
 mod m {}
diff --git a/src/test/ui/parser/attr-bad-meta.stderr b/src/test/ui/parser/attr-bad-meta.stderr
index 7351702ec9d..693da95017d 100644
--- a/src/test/ui/parser/attr-bad-meta.stderr
+++ b/src/test/ui/parser/attr-bad-meta.stderr
@@ -1,5 +1,5 @@
 error: expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*`
-  --> $DIR/attr-bad-meta.rs:3:7
+  --> $DIR/attr-bad-meta.rs:1:7
    |
 LL | #[path*] //~ ERROR expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*`
    |       ^ expected one of `(`, `::`, `=`, `[`, `]`, or `{` here
diff --git a/src/test/ui/proc-macro/proc-macro-attributes.rs b/src/test/ui/proc-macro/proc-macro-attributes.rs
index 1cc824e943c..062053453ee 100644
--- a/src/test/ui/proc-macro/proc-macro-attributes.rs
+++ b/src/test/ui/proc-macro/proc-macro-attributes.rs
@@ -8,7 +8,6 @@ extern crate derive_b;
 #[B(D)] //~ ERROR `B` is ambiguous
 #[B(E = "foo")] //~ ERROR `B` is ambiguous
 #[B(arbitrary tokens)] //~ ERROR `B` is ambiguous
-                       //~^ ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `tokens`
 #[derive(B)]
 struct B;
 
diff --git a/src/test/ui/proc-macro/proc-macro-attributes.stderr b/src/test/ui/proc-macro/proc-macro-attributes.stderr
index 7ac44c9354d..a5ec787ac67 100644
--- a/src/test/ui/proc-macro/proc-macro-attributes.stderr
+++ b/src/test/ui/proc-macro/proc-macro-attributes.stderr
@@ -13,7 +13,7 @@ LL | #[B] //~ ERROR `B` is ambiguous
    |   ^ ambiguous name
    |
 note: `B` could refer to the derive helper attribute defined here
-  --> $DIR/proc-macro-attributes.rs:12:10
+  --> $DIR/proc-macro-attributes.rs:11:10
    |
 LL | #[derive(B)]
    |          ^
@@ -30,7 +30,7 @@ LL | #[B(D)] //~ ERROR `B` is ambiguous
    |   ^ ambiguous name
    |
 note: `B` could refer to the derive helper attribute defined here
-  --> $DIR/proc-macro-attributes.rs:12:10
+  --> $DIR/proc-macro-attributes.rs:11:10
    |
 LL | #[derive(B)]
    |          ^
@@ -47,7 +47,7 @@ LL | #[B(E = "foo")] //~ ERROR `B` is ambiguous
    |   ^ ambiguous name
    |
 note: `B` could refer to the derive helper attribute defined here
-  --> $DIR/proc-macro-attributes.rs:12:10
+  --> $DIR/proc-macro-attributes.rs:11:10
    |
 LL | #[derive(B)]
    |          ^
@@ -64,7 +64,7 @@ LL | #[B(arbitrary tokens)] //~ ERROR `B` is ambiguous
    |   ^ ambiguous name
    |
 note: `B` could refer to the derive helper attribute defined here
-  --> $DIR/proc-macro-attributes.rs:12:10
+  --> $DIR/proc-macro-attributes.rs:11:10
    |
 LL | #[derive(B)]
    |          ^
@@ -74,13 +74,7 @@ note: `B` could also refer to the derive macro imported here
 LL | #[macro_use]
    | ^^^^^^^^^^^^
 
-error: expected one of `(`, `)`, `,`, `::`, or `=`, found `tokens`
-  --> $DIR/proc-macro-attributes.rs:10:15
-   |
-LL | #[B(arbitrary tokens)] //~ ERROR `B` is ambiguous
-   |               ^^^^^^ expected one of `(`, `)`, `,`, `::`, or `=` here
-
-error: aborting due to 6 previous errors
+error: aborting due to 5 previous errors
 
 Some errors occurred: E0658, E0659.
 For more information about an error, try `rustc --explain E0658`.
diff --git a/src/test/ui/proc-macro/proc-macro-gates.rs b/src/test/ui/proc-macro/proc-macro-gates.rs
index b708f630314..af6bfa08aaa 100644
--- a/src/test/ui/proc-macro/proc-macro-gates.rs
+++ b/src/test/ui/proc-macro/proc-macro-gates.rs
@@ -19,7 +19,7 @@ mod _test2_inner {
           //~| ERROR: non-builtin inner attributes are unstable
 }
 
-#[a = y] //~ ERROR: must only be followed by a delimiter token
+#[a = "y"] //~ ERROR: must only be followed by a delimiter token
 fn _test3() {}
 
 fn attrs() {
diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr
index c0bc06d358d..abfcf09bfaf 100644
--- a/src/test/ui/proc-macro/proc-macro-gates.stderr
+++ b/src/test/ui/proc-macro/proc-macro-gates.stderr
@@ -33,8 +33,8 @@ LL |     #![a] //~ ERROR: custom attributes cannot be applied to modules
 error: custom attribute invocations must be of the form #[foo] or #[foo(..)], the macro name must only be followed by a delimiter token
   --> $DIR/proc-macro-gates.rs:22:1
    |
-LL | #[a = y] //~ ERROR: must only be followed by a delimiter token
-   | ^^^^^^^^
+LL | #[a = "y"] //~ ERROR: must only be followed by a delimiter token
+   | ^^^^^^^^^^
 
 error[E0658]: custom attributes cannot be applied to statements (see issue #54727)
   --> $DIR/proc-macro-gates.rs:31:5
diff --git a/src/test/ui/unrestricted-attribute-tokens.rs b/src/test/ui/unrestricted-attribute-tokens.rs
index 9d8ba03eca5..4798f7b396c 100644
--- a/src/test/ui/unrestricted-attribute-tokens.rs
+++ b/src/test/ui/unrestricted-attribute-tokens.rs
@@ -1,6 +1,8 @@
 // compile-pass
 
-#![feature(custom_attribute, unrestricted_attribute_tokens)]
+#![feature(custom_attribute)]
 
 #[my_attr(a b c d)]
+#[my_attr[a b c d]]
+#[my_attr{a b c d}]
 fn main() {}