-
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.
Auto merge of #53893 - petrochenkov:cfgexpr, r=pnkfelix
Validate syntax of `cfg` attributes Fixes #53298
- Loading branch information
Showing
13 changed files
with
180 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// compile-flags: --cfg a(b=c) | ||
// error-pattern: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`) | ||
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,3 @@ | ||
// compile-flags: --cfg a{b} | ||
// error-pattern: invalid `--cfg` argument: `a{b}` (expected `key` or `key="value"`) | ||
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,3 @@ | ||
// compile-flags: --cfg a::b | ||
// error-pattern: invalid `--cfg` argument: `a::b` (argument key must be an identifier) | ||
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,3 @@ | ||
// compile-flags: --cfg a(b) | ||
// error-pattern: invalid `--cfg` argument: `a(b)` (expected `key` or `key="value"`) | ||
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,3 @@ | ||
// compile-flags: --cfg a=10 | ||
// error-pattern: invalid `--cfg` argument: `a=10` (argument value must be a string) | ||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#[cfg] //~ ERROR `cfg` is not followed by parentheses | ||
struct S1; | ||
|
||
#[cfg = 10] //~ ERROR `cfg` is not followed by parentheses | ||
struct S2; | ||
|
||
#[cfg()] //~ ERROR `cfg` predicate is not specified | ||
struct S3; | ||
|
||
#[cfg(a, b)] //~ ERROR multiple `cfg` predicates are specified | ||
struct S4; | ||
|
||
#[cfg("str")] //~ ERROR `cfg` predicate key cannot be a literal | ||
struct S5; | ||
|
||
#[cfg(a::b)] //~ ERROR `cfg` predicate key must be an identifier | ||
struct S6; | ||
|
||
#[cfg(a())] //~ ERROR invalid predicate `a` | ||
struct S7; | ||
|
||
#[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string | ||
struct S8; | ||
|
||
macro_rules! generate_s9 { | ||
($expr: expr) => { | ||
#[cfg(feature = $expr)] //~ ERROR `cfg` is not a well-formed meta-item | ||
struct S9; | ||
} | ||
} | ||
|
||
generate_s9!(concat!("nonexistent")); |
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,60 @@ | ||
error: `cfg` is not followed by parentheses | ||
--> $DIR/cfg-attr-syntax-validation.rs:1:1 | ||
| | ||
LL | #[cfg] //~ ERROR `cfg` is not followed by parentheses | ||
| ^^^^^^ help: expected syntax is: `cfg(/* predicate */)` | ||
|
||
error: `cfg` is not followed by parentheses | ||
--> $DIR/cfg-attr-syntax-validation.rs:4:1 | ||
| | ||
LL | #[cfg = 10] //~ ERROR `cfg` is not followed by parentheses | ||
| ^^^^^^^^^^^ help: expected syntax is: `cfg(/* predicate */)` | ||
|
||
error: `cfg` predicate is not specified | ||
--> $DIR/cfg-attr-syntax-validation.rs:7:1 | ||
| | ||
LL | #[cfg()] //~ ERROR `cfg` predicate is not specified | ||
| ^^^^^^^^ | ||
|
||
error: multiple `cfg` predicates are specified | ||
--> $DIR/cfg-attr-syntax-validation.rs:10:10 | ||
| | ||
LL | #[cfg(a, b)] //~ ERROR multiple `cfg` predicates are specified | ||
| ^ | ||
|
||
error: `cfg` predicate key cannot be a literal | ||
--> $DIR/cfg-attr-syntax-validation.rs:13:7 | ||
| | ||
LL | #[cfg("str")] //~ ERROR `cfg` predicate key cannot be a literal | ||
| ^^^^^ | ||
|
||
error: `cfg` predicate key must be an identifier | ||
--> $DIR/cfg-attr-syntax-validation.rs:16:7 | ||
| | ||
LL | #[cfg(a::b)] //~ ERROR `cfg` predicate key must be an identifier | ||
| ^^^^ | ||
|
||
error[E0537]: invalid predicate `a` | ||
--> $DIR/cfg-attr-syntax-validation.rs:19:7 | ||
| | ||
LL | #[cfg(a())] //~ ERROR invalid predicate `a` | ||
| ^^^ | ||
|
||
error: literal in `cfg` predicate value must be a string | ||
--> $DIR/cfg-attr-syntax-validation.rs:22:11 | ||
| | ||
LL | #[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string | ||
| ^^ | ||
|
||
error: `cfg` is not a well-formed meta-item | ||
--> $DIR/cfg-attr-syntax-validation.rs:27:9 | ||
| | ||
LL | #[cfg(feature = $expr)] //~ ERROR `cfg` is not a well-formed meta-item | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: expected syntax is: `#[cfg(/* predicate */)]` | ||
... | ||
LL | generate_s9!(concat!("nonexistent")); | ||
| ------------------------------------- in this macro invocation | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0537`. |
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 was deleted.
Oops, something went wrong.