Files
rust/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.3 KiB
Rust
Raw Normal View History

2025-07-07 09:10:38 +02:00
#[cfg]
//~^ ERROR malformed `cfg` attribute
//~| NOTE expected this to be a list
//~| NOTE for more information, visit
2018-09-02 00:13:22 +03:00
struct S1;
2025-07-07 09:10:38 +02:00
#[cfg = 10]
//~^ ERROR malformed `cfg` attribute
//~| NOTE expected this to be a list
//~| NOTE for more information, visit
2018-09-02 00:13:22 +03:00
struct S2;
2025-07-07 09:10:38 +02:00
#[cfg()]
//~^ ERROR malformed `cfg` attribute
//~| NOTE expected a single argument here
//~| NOTE for more information, visit
2018-09-02 00:13:22 +03:00
struct S3;
2025-07-07 09:10:38 +02:00
#[cfg(a, b)]
//~^ ERROR malformed `cfg` attribute
//~| NOTE expected a single argument here
//~| NOTE for more information, visit
2018-09-02 00:13:22 +03:00
struct S4;
2025-07-07 09:10:38 +02:00
#[cfg("str")] //~ ERROR `cfg` predicate key must be an identifier
2018-09-02 00:13:22 +03:00
struct S5;
#[cfg(a::b)] //~ ERROR `cfg` predicate key must be an identifier
struct S6;
#[cfg(a())] //~ ERROR invalid predicate `a`
struct S7;
2025-07-07 09:10:38 +02:00
#[cfg(a = 10)] //~ ERROR malformed `cfg` attribute input
//~^ NOTE expected a string literal here
//~| NOTE for more information, visit
2018-09-02 00:13:22 +03:00
struct S8;
2025-07-07 09:10:38 +02:00
#[cfg(a = b"hi")] //~ ERROR malformed `cfg` attribute input
//~^ NOTE expected a normal string literal, not a byte string literal
2018-10-09 22:55:07 +08:00
struct S9;
macro_rules! generate_s10 {
2018-09-02 00:13:22 +03:00
($expr: expr) => {
#[cfg(feature = $expr)]
2025-07-31 15:38:44 +02:00
//~^ ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `expr` metavariable
2018-10-09 22:55:07 +08:00
struct S10;
2018-09-02 00:13:22 +03:00
}
}
2018-10-09 22:55:07 +08:00
generate_s10!(concat!("nonexistent"));
2025-07-07 09:10:38 +02:00
//~^ NOTE in this expansion of generate_s10!
fn main() {}