diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-08-17 05:45:10 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-08-01 21:50:36 +0000 |
| commit | adcda6ca9a6d27c04399e3efe1c67fc6ff04d997 (patch) | |
| tree | 15c6ab8c0c8f03ff178999ee76e0865189e62288 /tests | |
| parent | e5e79f8bd428d0b8d26e8240d718b134ef297459 (diff) | |
| download | rust-adcda6ca9a6d27c04399e3efe1c67fc6ff04d997.tar.gz rust-adcda6ca9a6d27c04399e3efe1c67fc6ff04d997.zip | |
Detect more `cfg`d 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)))]
| ^^^^^^^^^^
```
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/cfg/both-true-false.stderr | 21 | ||||
| -rw-r--r-- | tests/ui/cfg/cfg-version/syntax.stderr | 110 | ||||
| -rw-r--r-- | tests/ui/cfg/cmdline-false.stderr | 11 | ||||
| -rw-r--r-- | tests/ui/cfg/diagnostics-reexport.rs | 6 | ||||
| -rw-r--r-- | tests/ui/cfg/diagnostics-reexport.stderr | 10 | ||||
| -rw-r--r-- | tests/ui/cfg/diagnostics-same-crate.rs | 12 | ||||
| -rw-r--r-- | tests/ui/cfg/diagnostics-same-crate.stderr | 17 | ||||
| -rw-r--r-- | tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs | 5 | ||||
| -rw-r--r-- | tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr | 11 | ||||
| -rw-r--r-- | tests/ui/conditional-compilation/test-cfg.rs | 4 | ||||
| -rw-r--r-- | tests/ui/conditional-compilation/test-cfg.stderr | 13 | ||||
| -rw-r--r-- | tests/ui/macros/macro-inner-attributes.stderr | 10 | ||||
| -rw-r--r-- | tests/ui/rustdoc/cfg-rustdoc.rs | 7 | ||||
| -rw-r--r-- | tests/ui/rustdoc/cfg-rustdoc.stderr | 11 |
14 files changed, 228 insertions, 20 deletions
diff --git a/tests/ui/cfg/both-true-false.stderr b/tests/ui/cfg/both-true-false.stderr index 1526cc2b707..8550444d179 100644 --- a/tests/ui/cfg/both-true-false.stderr +++ b/tests/ui/cfg/both-true-false.stderr @@ -3,6 +3,27 @@ error[E0425]: cannot find function `foo` in this scope | LL | foo(); | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/both-true-false.rs:6:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/both-true-false.rs:4:7 + | +LL | #[cfg(false)] + | ^^^^^ +note: found an item that was configured out + --> $DIR/both-true-false.rs:10:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/both-true-false.rs:9:7 + | +LL | #[cfg(false)] + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/cfg/cfg-version/syntax.stderr b/tests/ui/cfg/cfg-version/syntax.stderr index 188f6d7aa5d..4ec3e2de797 100644 --- a/tests/ui/cfg/cfg-version/syntax.stderr +++ b/tests/ui/cfg/cfg-version/syntax.stderr @@ -128,60 +128,170 @@ error[E0425]: cannot find function `key_value_form` in this scope | LL | key_value_form(); | ^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:32:4 + | +LL | fn key_value_form() {} + | ^^^^^^^^^^^^^^ +note: the item is gated behind the `1.43` feature + --> $DIR/syntax.rs:30:7 + | +LL | #[cfg(version = "1.43")] + | ^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `not_numbers_or_periods` in this scope --> $DIR/syntax.rs:143:5 | LL | not_numbers_or_periods(); | ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:53:4 + | +LL | fn not_numbers_or_periods() {} + | ^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:51:14 + | +LL | #[cfg(version("foo"))] + | ^^^^^^^ error[E0425]: cannot find function `complex_semver_with_metadata` in this scope --> $DIR/syntax.rs:144:5 | LL | complex_semver_with_metadata(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:57:4 + | +LL | fn complex_semver_with_metadata() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:55:14 + | +LL | #[cfg(version("1.20.0-stable"))] + | ^^^^^^^^^^^^^^^^^ error[E0425]: cannot find function `invalid_major_only` in this scope --> $DIR/syntax.rs:145:5 | LL | invalid_major_only(); | ^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:80:4 + | +LL | fn invalid_major_only() {} + | ^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:78:14 + | +LL | #[cfg(version("1"))] + | ^^^^^ error[E0425]: cannot find function `invalid_major_only_zero` in this scope --> $DIR/syntax.rs:146:5 | LL | invalid_major_only_zero(); | ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:84:4 + | +LL | fn invalid_major_only_zero() {} + | ^^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:82:14 + | +LL | #[cfg(version("0"))] + | ^^^^^ error[E0425]: cannot find function `invalid_major_only_negative` in this scope --> $DIR/syntax.rs:147:5 | LL | invalid_major_only_negative(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:97:4 + | +LL | fn invalid_major_only_negative() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:95:14 + | +LL | #[cfg(version("-1"))] + | ^^^^^^ error[E0425]: cannot find function `exceed_u16_major` in this scope --> $DIR/syntax.rs:148:5 | LL | exceed_u16_major(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:103:4 + | +LL | fn exceed_u16_major() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:101:14 + | +LL | #[cfg(version("65536"))] + | ^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_minor` in this scope --> $DIR/syntax.rs:149:5 | LL | exceed_u16_minor(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:107:4 + | +LL | fn exceed_u16_minor() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:105:14 + | +LL | #[cfg(version("1.65536.0"))] + | ^^^^^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_patch` in this scope --> $DIR/syntax.rs:150:5 | LL | exceed_u16_patch(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:111:4 + | +LL | fn exceed_u16_patch() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:109:14 + | +LL | #[cfg(version("1.0.65536"))] + | ^^^^^^^^^^^^^ error[E0425]: cannot find function `exceed_u16_mixed` in this scope --> $DIR/syntax.rs:151:5 | LL | exceed_u16_mixed(); | ^^^^^^^^^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/syntax.rs:115:4 + | +LL | fn exceed_u16_mixed() {} + | ^^^^^^^^^^^^^^^^ +note: the item is gated here + --> $DIR/syntax.rs:113:14 + | +LL | #[cfg(version("65536.0.65536"))] + | ^^^^^^^^^^^^^^^^^ error: aborting due to 14 previous errors; 14 warnings emitted diff --git a/tests/ui/cfg/cmdline-false.stderr b/tests/ui/cfg/cmdline-false.stderr index 5f57c754c40..da5eb0c892a 100644 --- a/tests/ui/cfg/cmdline-false.stderr +++ b/tests/ui/cfg/cmdline-false.stderr @@ -3,6 +3,17 @@ error[E0425]: cannot find function `foo` in this scope | LL | foo(); | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/cmdline-false.rs:5:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/cmdline-false.rs:4:7 + | +LL | #[cfg(false)] + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/cfg/diagnostics-reexport.rs b/tests/ui/cfg/diagnostics-reexport.rs index 56fac562238..bdb57df2f25 100644 --- a/tests/ui/cfg/diagnostics-reexport.rs +++ b/tests/ui/cfg/diagnostics-reexport.rs @@ -1,7 +1,7 @@ pub mod inner { - #[cfg(false)] + #[cfg(false)] //~ NOTE the item is gated here mod gone { - pub fn uwu() {} + pub fn uwu() {} //~ NOTE found an item that was configured out } #[cfg(false)] //~ NOTE the item is gated here @@ -34,7 +34,7 @@ mod b { } fn main() { - // There is no uwu at this path - no diagnostic. + // There is no uwu at this path, but there's one in a cgfd out sub-module, so we mention it. inner::uwu(); //~ ERROR cannot find function //~^ NOTE not found in `inner` } diff --git a/tests/ui/cfg/diagnostics-reexport.stderr b/tests/ui/cfg/diagnostics-reexport.stderr index bf1bbcba7e4..82412ed49c5 100644 --- a/tests/ui/cfg/diagnostics-reexport.stderr +++ b/tests/ui/cfg/diagnostics-reexport.stderr @@ -51,6 +51,16 @@ LL | inner::uwu(); | ^^^ not found in `inner` | note: found an item that was configured out + --> $DIR/diagnostics-reexport.rs:4:16 + | +LL | pub fn uwu() {} + | ^^^ +note: the item is gated here + --> $DIR/diagnostics-reexport.rs:2:11 + | +LL | #[cfg(false)] + | ^^^^^ +note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:8:20 | LL | pub use super::uwu; diff --git a/tests/ui/cfg/diagnostics-same-crate.rs b/tests/ui/cfg/diagnostics-same-crate.rs index 9153f20b296..29209d5f3ea 100644 --- a/tests/ui/cfg/diagnostics-same-crate.rs +++ b/tests/ui/cfg/diagnostics-same-crate.rs @@ -37,8 +37,8 @@ mod placeholder { //~| NOTE could not find `doesnt_exist` in `inner` } -#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] -pub fn vanished() {} +#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] //~ NOTE the item is gated here +pub fn vanished() {} //~ NOTE found an item that was configured out fn main() { // There is no uwu at this path - no diagnostic. @@ -49,8 +49,7 @@ fn main() { inner::uwu(); //~ ERROR cannot find function //~| NOTE not found in `inner` - // The module isn't found - we would like to get a diagnostic, but currently don't due to - // the awkward way the resolver diagnostics are currently implemented. + // The module isn't found - we get a diagnostic. inner::doesnt_exist::hello(); //~ ERROR failed to resolve //~| NOTE could not find `doesnt_exist` in `inner` @@ -58,9 +57,8 @@ fn main() { inner::right::meow(); //~ ERROR cannot find function //~| NOTE not found in `inner::right - // Exists in the crate root - we would generally want a diagnostic, - // but currently don't have one. - // Not that it matters much though, this is highly unlikely to confuse anyone. + // Exists in the crate root - we show a diagnostic because we treat "no module DefId" as "crate + // root DefId". vanished(); //~ ERROR cannot find function //~^ NOTE not found in this scope } diff --git a/tests/ui/cfg/diagnostics-same-crate.stderr b/tests/ui/cfg/diagnostics-same-crate.stderr index 121f25ca090..f6a6fe388c5 100644 --- a/tests/ui/cfg/diagnostics-same-crate.stderr +++ b/tests/ui/cfg/diagnostics-same-crate.stderr @@ -33,7 +33,7 @@ LL | #[cfg(false)] | ^^^^^ error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` - --> $DIR/diagnostics-same-crate.rs:54:12 + --> $DIR/diagnostics-same-crate.rs:53:12 | LL | inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` @@ -67,7 +67,7 @@ LL | #[cfg(false)] | ^^^^^ error[E0425]: cannot find function `meow` in module `inner::right` - --> $DIR/diagnostics-same-crate.rs:58:19 + --> $DIR/diagnostics-same-crate.rs:57:19 | LL | inner::right::meow(); | ^^^^ not found in `inner::right` @@ -90,10 +90,21 @@ LL | uwu(); | ^^^ not found in this scope error[E0425]: cannot find function `vanished` in this scope - --> $DIR/diagnostics-same-crate.rs:64:5 + --> $DIR/diagnostics-same-crate.rs:62:5 | LL | vanished(); | ^^^^^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/diagnostics-same-crate.rs:41:8 + | +LL | pub fn vanished() {} + | ^^^^^^^^ +note: the item is gated here + --> $DIR/diagnostics-same-crate.rs:40:7 + | +LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs index 7618e83a642..c5d86a27d52 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs @@ -10,9 +10,10 @@ //! //! Added in <https://github.com/rust-lang/rust/pull/34216>. -#[cfg_attr(all(), cfg_attr(all(), cfg(false)))] -fn f() {} +#[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 } diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr index ddb8ea1e13a..44a33adbc47 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr @@ -3,6 +3,17 @@ error[E0425]: cannot find function `f` in this scope | LL | f() | ^ not found in this scope + | +note: found an item that was configured out + --> $DIR/nested-cfg-attr-conditional-compilation.rs:14:4 + | +LL | fn f() {} + | ^ +note: the item is gated here + --> $DIR/nested-cfg-attr-conditional-compilation.rs:13:39 + | +LL | #[cfg_attr(all(), cfg_attr(all(), cfg(false)))] + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/conditional-compilation/test-cfg.rs b/tests/ui/conditional-compilation/test-cfg.rs index adbbc309be4..b3fff26a8fd 100644 --- a/tests/ui/conditional-compilation/test-cfg.rs +++ b/tests/ui/conditional-compilation/test-cfg.rs @@ -1,8 +1,10 @@ //@ compile-flags: --cfg foo --check-cfg=cfg(foo,bar) #[cfg(all(foo, bar))] // foo AND bar -fn foo() {} +//~^ NOTE the item is gated here +fn foo() {} //~ NOTE found an item that was configured out fn main() { foo(); //~ ERROR cannot find function `foo` in this scope + //~^ NOTE not found in this scope } diff --git a/tests/ui/conditional-compilation/test-cfg.stderr b/tests/ui/conditional-compilation/test-cfg.stderr index 9715f16acc2..1212074e417 100644 --- a/tests/ui/conditional-compilation/test-cfg.stderr +++ b/tests/ui/conditional-compilation/test-cfg.stderr @@ -1,8 +1,19 @@ error[E0425]: cannot find function `foo` in this scope - --> $DIR/test-cfg.rs:7:5 + --> $DIR/test-cfg.rs:8:5 | LL | foo(); | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/test-cfg.rs:5:4 + | +LL | fn foo() {} + | ^^^ +note: the item is gated here + --> $DIR/test-cfg.rs:3:16 + | +LL | #[cfg(all(foo, bar))] // foo AND bar + | ^^^ error: aborting due to 1 previous error diff --git a/tests/ui/macros/macro-inner-attributes.stderr b/tests/ui/macros/macro-inner-attributes.stderr index d74b64db5ac..cda53497f39 100644 --- a/tests/ui/macros/macro-inner-attributes.stderr +++ b/tests/ui/macros/macro-inner-attributes.stderr @@ -4,6 +4,16 @@ error[E0433]: failed to resolve: use of unresolved module or unlinked crate `a` LL | a::bar(); | ^ use of unresolved module or unlinked crate `a` | +note: found an item that was configured out + --> $DIR/macro-inner-attributes.rs:7:7 + | +LL | test!(a, + | ^ +note: the item is gated here + --> $DIR/macro-inner-attributes.rs:8:13 + | +LL | #[cfg(false)], + | ^^^^^ help: there is a crate or module with a similar name | LL - a::bar(); diff --git a/tests/ui/rustdoc/cfg-rustdoc.rs b/tests/ui/rustdoc/cfg-rustdoc.rs index dd8e1ed97c4..11c48d07552 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.rs +++ b/tests/ui/rustdoc/cfg-rustdoc.rs @@ -1,6 +1,7 @@ -#[cfg(doc)] -pub struct Foo; +#[cfg(doc)] //~ NOTE the item is gated here +pub struct Foo; //~ NOTE found an item that was configured out fn main() { - let f = Foo; //~ ERROR + let f = Foo; //~ ERROR cannot find value `Foo` in this scope + //~^ NOTE not found in this scope } diff --git a/tests/ui/rustdoc/cfg-rustdoc.stderr b/tests/ui/rustdoc/cfg-rustdoc.stderr index 340a8e22482..fd0fcfd01aa 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.stderr +++ b/tests/ui/rustdoc/cfg-rustdoc.stderr @@ -3,6 +3,17 @@ error[E0425]: cannot find value `Foo` in this scope | LL | let f = Foo; | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/cfg-rustdoc.rs:2:12 + | +LL | pub struct Foo; + | ^^^ +note: the item is gated here + --> $DIR/cfg-rustdoc.rs:1:7 + | +LL | #[cfg(doc)] + | ^^^ error: aborting due to 1 previous error |
