Files
rust/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs
Esteban Küber adcda6ca9a Detect more cfgd out items in resolution errors
Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition.

```
error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^
```
2025-08-01 21:50:36 +00:00

20 lines
838 B
Rust

//! Test that nested `cfg_attr` attributes work correctly for conditional compilation.
//! This checks that `cfg_attr` can be arbitrarily deeply nested and that the
//! 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)
//! 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
fn f() {} //~ NOTE found an item that was configured out
fn main() {
f() //~ ERROR cannot find function `f` in this scope
//~^ NOTE not found in this scope
}