-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 (#34981). ``` PATH `=` LITERAL ``` (Key-value macro attributes are not supported at all right now.) Crater run in #57321 found no regressions for this change. There are multiple possible ways to extend key-value attributes (#57321 (comment)), 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. #57321 goes further and adds some additional restrictions (more consistent input checking) to built-in attributes. Closes #55208
- Loading branch information
Showing
23 changed files
with
108 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
7 changes: 0 additions & 7 deletions
7
src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
#![feature(unrestricted_attribute_tokens)] | ||
|
||
#[doc = $not_there] //~ ERROR expected `]`, found `not_there` | ||
#[doc = $not_there] //~ ERROR unexpected token: `$` | ||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
#![feature(unrestricted_attribute_tokens)] | ||
|
||
#[path*] //~ ERROR expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*` | ||
mod m {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |