-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict value in key-value attributes to literals
- Loading branch information
1 parent
b57fe74
commit 8e1b5d8
Showing
11 changed files
with
87 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
// compile-pass | ||
|
||
#![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 | ||
|
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,4 @@ | ||
#![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:3: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,35 @@ | ||
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 | ||
| | ||
= help: try enabling `#![feature(unrestricted_attribute_tokens)]` | ||
|
||
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 | ||
| | ||
= help: try enabling `#![feature(unrestricted_attribute_tokens)]` | ||
|
||
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
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