Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) fn compile_fn(
context.clear();
context.func = codegened_func.func;

#[cfg(any())] // This is never true
#[cfg(false)]
let _clif_guard = {
use std::fmt::Write;

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl () {}
/// # pub unsafe fn malloc(_size: usize) -> *mut core::ffi::c_void { core::ptr::NonNull::dangling().as_ptr() }
/// # pub unsafe fn free(_ptr: *mut core::ffi::c_void) {}
/// # }
/// # #[cfg(any())]
/// # #[cfg(false)]
/// #[allow(unused_extern_crates)]
/// extern crate libc;
///
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/asm/naked-functions-inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub extern "C" fn inline_never() {
}

#[unsafe(naked)]
#[cfg_attr(all(), inline(never))]
#[cfg_attr(true, inline(never))]
//~^ ERROR [E0736]
pub extern "C" fn conditional_inline_never() {
naked_asm!("");
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/asm/naked-functions-inline.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ LL | #[inline(never)]
| ^^^^^^ the `inline` attribute is incompatible with `#[unsafe(naked)]`

error[E0736]: attribute incompatible with `#[unsafe(naked)]`
--> $DIR/naked-functions-inline.rs:33:19
--> $DIR/naked-functions-inline.rs:33:18
|
LL | #[unsafe(naked)]
| ---------------- function marked with `#[unsafe(naked)]` here
LL | #[cfg_attr(all(), inline(never))]
| ^^^^^^ the `inline` attribute is incompatible with `#[unsafe(naked)]`
LL | #[cfg_attr(true, inline(never))]
| ^^^^^^ the `inline` attribute is incompatible with `#[unsafe(naked)]`

error: aborting due to 4 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/unsafe/cfg-unsafe-attributes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ build-pass

#[cfg_attr(all(), unsafe(no_mangle))]
#[cfg_attr(true, unsafe(no_mangle))]
fn a() {}

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ edition: 2024

#[unsafe(cfg(any()))] //~ ERROR: is not an unsafe attribute
#[unsafe(cfg(false))] //~ ERROR: is not an unsafe attribute
fn a() {}

#[unsafe(cfg_attr(any(), allow(dead_code)))] //~ ERROR: is not an unsafe attribute
#[unsafe(cfg_attr(false, allow(dead_code)))] //~ ERROR: is not an unsafe attribute
fn b() {}

#[unsafe(test)] //~ ERROR: is not an unsafe attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
error: `cfg` is not an unsafe attribute
--> $DIR/extraneous-unsafe-attributes.rs:3:3
|
LL | #[unsafe(cfg(any()))]
LL | #[unsafe(cfg(false))]
| ^^^^^^ this is not an unsafe attribute
|
= note: extraneous unsafe is not allowed in attributes

error: `cfg_attr` is not an unsafe attribute
--> $DIR/extraneous-unsafe-attributes.rs:6:3
|
LL | #[unsafe(cfg_attr(any(), allow(dead_code)))]
LL | #[unsafe(cfg_attr(false, allow(dead_code)))]
| ^^^^^^ this is not an unsafe attribute
|
= note: extraneous unsafe is not allowed in attributes
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/unsafe/unsafe-attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn a() {}
#[unsafe(export_name = "foo")]
fn b() {}

#[cfg_attr(any(), unsafe(no_mangle))]
#[cfg_attr(false, unsafe(no_mangle))]
static VAR2: u32 = 1;

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/cfg/conditional-compilation-struct-11085.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Foo {
}

struct Foo2 {
#[cfg(all())]
#[cfg(true)]
foo: isize,
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cfg/conditional-compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ mod test_methods {
}
}

#[cfg(any())]
#[cfg(false)]
mod nonexistent_file; // Check that unconfigured non-inline modules are not loaded or parsed.
6 changes: 3 additions & 3 deletions tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
//! expansion works from outside to inside, eventually applying the innermost
//! conditional compilation directive.
//!
//! In this test, `cfg_attr(all(), cfg_attr(all(), cfg(false)))` should expand to:
//! 1. `cfg_attr(all(), cfg(false))` (outer cfg_attr applied)
//! In this test, `cfg_attr(true, cfg_attr(true, cfg(false)))` should expand to:
//! 1. `cfg_attr(true, cfg(false))` (outer cfg_attr applied)
//! 2. `cfg(false)` (inner cfg_attr applied)
//! 3. Function `f` is excluded from compilation
//!
//! Added in <https://github.com/rust-lang/rust/pull/34216>.

#[cfg_attr(all(), cfg_attr(all(), cfg(false)))] //~ NOTE the item is gated here
#[cfg_attr(true, cfg_attr(true, cfg(false)))] //~ NOTE the item is gated here
fn f() {} //~ NOTE found an item that was configured out

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ LL | f()
note: found an item that was configured out
--> $DIR/nested-cfg-attr-conditional-compilation.rs:14:4
|
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(false)))]
| ----- the item is gated here
LL | #[cfg_attr(true, cfg_attr(true, cfg(false)))]
| ----- the item is gated here
LL | fn f() {}
| ^

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coherence/coherence-cow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ revisions: re_a re_b re_c

#![cfg_attr(any(), re_a, re_b, re_c)]
#![cfg_attr(false, re_a, re_b, re_c)]

//@ aux-build:coherence_lib.rs

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/conditional-compilation/cfg-attr-multi-false.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#![warn(unused_must_use)]

#[cfg_attr(any(), deprecated, must_use)]
#[cfg_attr(false, deprecated, must_use)]
struct Struct {}

impl Struct {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/conditional-compilation/cfg-attr-multi-true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#![warn(unused_must_use)]

#[cfg_attr(all(), deprecated, must_use)]
#[cfg_attr(true, deprecated, must_use)]
struct MustUseDeprecated {}

impl MustUseDeprecated { //~ warning: use of deprecated
Expand Down
22 changes: 11 additions & 11 deletions tests/ui/conditional-compilation/cfg-attr-parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@
struct NoConfigurationPredicate;

// Zero attributes, zero trailing comma (comma manatory here)
#[cfg_attr(all())] //~ error: expected `,`, found end of `cfg_attr`
#[cfg_attr(true)] //~ error: expected `,`, found end of `cfg_attr`
struct A0C0;

// Zero attributes, one trailing comma
#[cfg_attr(all(),)]
#[cfg_attr(true,)]
//~^ WARN `#[cfg_attr]` does not expand to any attributes
struct A0C1;

// Zero attributes, two trailing commas
#[cfg_attr(all(),,)] //~ ERROR expected identifier
#[cfg_attr(true,,)] //~ ERROR expected identifier
struct A0C2;

// One attribute, no trailing comma
#[cfg_attr(all(), must_use)] // Ok
#[cfg_attr(true, must_use)] // Ok
struct A1C0;

// One attribute, one trailing comma
#[cfg_attr(all(), must_use,)] // Ok
#[cfg_attr(true, must_use,)] // Ok
struct A1C1;

// One attribute, two trailing commas
#[cfg_attr(all(), must_use,,)] //~ ERROR expected identifier
#[cfg_attr(true, must_use,,)] //~ ERROR expected identifier
struct A1C2;

// Two attributes, no trailing comma
#[cfg_attr(all(), must_use, deprecated)] // Ok
#[cfg_attr(true, must_use, deprecated)] // Ok
struct A2C0;

// Two attributes, one trailing comma
#[cfg_attr(all(), must_use, deprecated,)] // Ok
#[cfg_attr(true, must_use, deprecated,)] // Ok
struct A2C1;

// Two attributes, two trailing commas
#[cfg_attr(all(), must_use, deprecated,,)] //~ ERROR expected identifier
#[cfg_attr(true, must_use, deprecated,,)] //~ ERROR expected identifier
struct A2C2;

// Wrong delimiter `[`
#[cfg_attr[all(),,]]
#[cfg_attr[true,,]]
//~^ ERROR wrong `cfg_attr` delimiters
//~| ERROR expected identifier, found `,`
struct BracketZero;

// Wrong delimiter `{`
#[cfg_attr{all(),,}]
#[cfg_attr{true,,}]
//~^ ERROR wrong `cfg_attr` delimiters
//~| ERROR expected identifier, found `,`
struct BraceZero;
Expand Down
80 changes: 40 additions & 40 deletions tests/ui/conditional-compilation/cfg-attr-parse.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,100 +10,100 @@ LL | #[cfg_attr()]
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

error: expected `,`, found end of `cfg_attr` input
--> $DIR/cfg-attr-parse.rs:8:17
--> $DIR/cfg-attr-parse.rs:8:16
|
LL | #[cfg_attr(all())]
| ----------------^-
| | |
| | expected `,`
LL | #[cfg_attr(true)]
| ---------------^-
| | |
| | expected `,`
| help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:17:18
--> $DIR/cfg-attr-parse.rs:17:17
|
LL | #[cfg_attr(all(),,)]
| -----------------^--
| | |
| | expected identifier
LL | #[cfg_attr(true,,)]
| ----------------^--
| | |
| | expected identifier
| help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:29:28
--> $DIR/cfg-attr-parse.rs:29:27
|
LL | #[cfg_attr(all(), must_use,,)]
| ---------------------------^--
| | |
| | expected identifier
LL | #[cfg_attr(true, must_use,,)]
| --------------------------^--
| | |
| | expected identifier
| help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:41:40
--> $DIR/cfg-attr-parse.rs:41:39
|
LL | #[cfg_attr(all(), must_use, deprecated,,)]
| ---------------------------------------^--
| | |
| | expected identifier
LL | #[cfg_attr(true, must_use, deprecated,,)]
| --------------------------------------^--
| | |
| | expected identifier
| help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

error: wrong `cfg_attr` delimiters
--> $DIR/cfg-attr-parse.rs:45:11
|
LL | #[cfg_attr[all(),,]]
| ^^^^^^^^^
LL | #[cfg_attr[true,,]]
| ^^^^^^^^
|
help: the delimiters should be `(` and `)`
|
LL - #[cfg_attr[all(),,]]
LL + #[cfg_attr(all(),,)]
LL - #[cfg_attr[true,,]]
LL + #[cfg_attr(true,,)]
|

error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:45:18
--> $DIR/cfg-attr-parse.rs:45:17
|
LL | #[cfg_attr[all(),,]]
| -----------------^--
| | |
| | expected identifier
LL | #[cfg_attr[true,,]]
| ----------------^--
| | |
| | expected identifier
| help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

error: wrong `cfg_attr` delimiters
--> $DIR/cfg-attr-parse.rs:51:11
|
LL | #[cfg_attr{all(),,}]
| ^^^^^^^^^
LL | #[cfg_attr{true,,}]
| ^^^^^^^^
|
help: the delimiters should be `(` and `)`
|
LL - #[cfg_attr{all(),,}]
LL + #[cfg_attr(all(),,)]
LL - #[cfg_attr{true,,}]
LL + #[cfg_attr(true,,)]
|

error: expected identifier, found `,`
--> $DIR/cfg-attr-parse.rs:51:18
--> $DIR/cfg-attr-parse.rs:51:17
|
LL | #[cfg_attr{all(),,}]
| -----------------^--
| | |
| | expected identifier
LL | #[cfg_attr{true,,}]
| ----------------^--
| | |
| | expected identifier
| help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>

warning: `#[cfg_attr]` does not expand to any attributes
--> $DIR/cfg-attr-parse.rs:12:1
|
LL | #[cfg_attr(all(),)]
| ^^^^^^^^^^^^^^^^^^^
LL | #[cfg_attr(true,)]
| ^^^^^^^^^^^^^^^^^^
|
= note: requested on the command line with `-W unused-attributes`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
macro_rules! foo {
() => {
#[cfg_attr(all(), unknown)]
#[cfg_attr(true, unknown)]
//~^ ERROR cannot find attribute `unknown` in this scope
fn foo() {}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: cannot find attribute `unknown` in this scope
--> $DIR/cfg-attr-unknown-attribute-macro-expansion.rs:3:27
--> $DIR/cfg-attr-unknown-attribute-macro-expansion.rs:3:26
|
LL | #[cfg_attr(all(), unknown)]
| ^^^^^^^
LL | #[cfg_attr(true, unknown)]
| ^^^^^^^
...
LL | foo!();
| ------ in this macro invocation
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/conditional-compilation/cfg-empty-any-all.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Test the behaviour of `cfg(any())` and `cfg(all())`
#[cfg(any())] // Equivalent to cfg(false)
struct Disabled;

#[cfg(all())] // Equivalent to cfg(true)
struct Enabled;

fn main() {
let _ = Disabled; //~ ERROR: cannot find value `Disabled`
let _ = Enabled; // ok
}
Loading
Loading