diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index a92ed9cd3ae83..95d494cde4fd5 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -3204,11 +3204,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { continue; } - let item_was = if let CfgEntry::NameValue { value: Some(feature), .. } = cfg.0 { - errors::ItemWas::BehindFeature { feature, span: cfg.1 } - } else { - errors::ItemWas::CfgOut { span: cfg.1 } + let span = cfg.1; + let item_was = match cfg.0 { + CfgEntry::Bool(false, _) => errors::ItemWas::Disabled { span }, + CfgEntry::Any(ref any, _) if any.is_empty() => errors::ItemWas::Disabled { span }, + CfgEntry::NameValue { name: sym::feature, value: Some(name), .. } => { + errors::ItemWas::BehindCargoFeature { name, span } + } + CfgEntry::NameValue { name, value, .. } => { + errors::ItemWas::BehindFeature { name, value, span } + } + _ => errors::ItemWas::CfgOut { span }, }; + let note = errors::FoundItemConfigureOut { span: ident.span, item_was }; err.subdiagnostic(note); } diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 8c7bf61949a29..21470a46313a0 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1384,7 +1384,9 @@ pub(crate) struct FoundItemConfigureOut { } pub(crate) enum ItemWas { - BehindFeature { feature: Symbol, span: Span }, + BehindFeature { name: Symbol, value: Option, span: Span }, + BehindCargoFeature { name: Symbol, span: Span }, + Disabled { span: Span }, CfgOut { span: Span }, } @@ -1392,13 +1394,31 @@ impl Subdiagnostic for FoundItemConfigureOut { fn add_to_diag(self, diag: &mut Diag<'_, G>) { let mut multispan: MultiSpan = self.span.into(); match self.item_was { - ItemWas::BehindFeature { feature, span } => { - let value = feature.into_diag_arg(&mut None); - let msg = msg!("the item is gated behind the `{$feature}` feature") - .arg("feature", value) - .format(); + ItemWas::BehindFeature { name, value, span } => { + let name = name.into_diag_arg(&mut None); + let msg = match value { + Some(value) => { + let value = value.into_diag_arg(&mut None); + msg!("the item is gated behind `{$name} = \"{$value}\"`") + .arg("name", name) + .arg("value", value) + .format() + } + None => msg!("the item is gated behind `{$name}`").arg("name", name).format(), + }; multispan.push_span_label(span, msg); } + ItemWas::BehindCargoFeature { name, span } => { + multispan.push_span_label( + span, + msg!("the item is gated behind the `{$name}` feature") + .arg("name", name) + .format(), + ); + } + ItemWas::Disabled { span } => { + multispan.push_span_label(span, msg!("the item is disabled")) + } ItemWas::CfgOut { span } => { multispan.push_span_label(span, msg!("the item is gated here")); } diff --git a/tests/ui/cfg/both-true-false.stderr b/tests/ui/cfg/both-true-false.stderr index 76a5661f0873d..2953582e529fe 100644 --- a/tests/ui/cfg/both-true-false.stderr +++ b/tests/ui/cfg/both-true-false.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/both-true-false.rs:7:4 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | #[cfg(true)] LL | fn foo() {} | ^^^ @@ -16,7 +16,7 @@ note: found an item that was configured out --> $DIR/both-true-false.rs:11:4 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | fn foo() {} | ^^^ diff --git a/tests/ui/cfg/cfg-version/syntax.stderr b/tests/ui/cfg/cfg-version/syntax.stderr index 34ddfff3e8ef6..506e9b161102f 100644 --- a/tests/ui/cfg/cfg-version/syntax.stderr +++ b/tests/ui/cfg/cfg-version/syntax.stderr @@ -133,7 +133,7 @@ note: found an item that was configured out --> $DIR/syntax.rs:32:4 | LL | #[cfg(version = "1.43")] - | ---------------- the item is gated behind the `1.43` feature + | ---------------- the item is gated behind `version = "1.43"` LL | LL | fn key_value_form() {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/cfg/cmdline-false.stderr b/tests/ui/cfg/cmdline-false.stderr index 3d486803821fb..9e3805f6a5ab0 100644 --- a/tests/ui/cfg/cmdline-false.stderr +++ b/tests/ui/cfg/cmdline-false.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/cmdline-false.rs:5:4 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | fn foo() {} | ^^^ diff --git a/tests/ui/cfg/diagnostics-cross-crate.stderr b/tests/ui/cfg/diagnostics-cross-crate.stderr index 15e60cc43a3c9..7b518486e048d 100644 --- a/tests/ui/cfg/diagnostics-cross-crate.stderr +++ b/tests/ui/cfg/diagnostics-cross-crate.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ @@ -28,7 +28,7 @@ note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:3:12 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub fn uwu() {} | ^^^ @@ -56,7 +56,7 @@ note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:22:8 | LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] - | -------------------------------------------- the item is gated here + | -------------------------------------------- the item is gated behind `i_dont_exist_and_you_can_do_nothing_about_it` LL | pub fn vanished() {} | ^^^^^^^^ diff --git a/tests/ui/cfg/diagnostics-reexport-2.rs b/tests/ui/cfg/diagnostics-reexport-2.rs index bef8325170618..467ef080bfc11 100644 --- a/tests/ui/cfg/diagnostics-reexport-2.rs +++ b/tests/ui/cfg/diagnostics-reexport-2.rs @@ -2,11 +2,11 @@ mod original { #[cfg(false)] - //~^ NOTE the item is gated here - //~| NOTE the item is gated here - //~| NOTE the item is gated here - //~| NOTE the item is gated here - //~| NOTE the item is gated here + //~^ NOTE the item is disabled + //~| NOTE the item is disabled + //~| NOTE the item is disabled + //~| NOTE the item is disabled + //~| NOTE the item is disabled pub mod gated { //~^ NOTE found an item that was configured out //~| NOTE found an item that was configured out diff --git a/tests/ui/cfg/diagnostics-reexport-2.stderr b/tests/ui/cfg/diagnostics-reexport-2.stderr index a79c623856ff3..323f56827bb57 100644 --- a/tests/ui/cfg/diagnostics-reexport-2.stderr +++ b/tests/ui/cfg/diagnostics-reexport-2.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod gated { | ^^^^^ @@ -23,7 +23,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod gated { | ^^^^^ @@ -38,7 +38,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod gated { | ^^^^^ @@ -53,7 +53,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod gated { | ^^^^^ @@ -68,7 +68,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport-2.rs:10:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod gated { | ^^^^^ diff --git a/tests/ui/cfg/diagnostics-reexport.rs b/tests/ui/cfg/diagnostics-reexport.rs index c6a714fca718e..6f42076832dc8 100644 --- a/tests/ui/cfg/diagnostics-reexport.rs +++ b/tests/ui/cfg/diagnostics-reexport.rs @@ -4,7 +4,7 @@ pub mod inner { pub fn uwu() {} } - #[cfg(false)] //~ NOTE the item is gated here + #[cfg(false)] //~ NOTE the item is disabled pub use super::uwu; //~^ NOTE found an item that was configured out } @@ -14,7 +14,7 @@ pub use a::x; //~| NOTE no `x` in `a` mod a { - #[cfg(false)] //~ NOTE the item is gated here + #[cfg(false)] //~ NOTE the item is disabled pub fn x() {} //~^ NOTE found an item that was configured out } @@ -25,10 +25,10 @@ pub use b::{x, y}; //~| NOTE no `y` in `b` mod b { - #[cfg(false)] //~ NOTE the item is gated here + #[cfg(false)] //~ NOTE the item is disabled pub fn x() {} //~^ NOTE found an item that was configured out - #[cfg(false)] //~ NOTE the item is gated here + #[cfg(false)] //~ NOTE the item is disabled pub fn y() {} //~^ NOTE found an item that was configured out } diff --git a/tests/ui/cfg/diagnostics-reexport.stderr b/tests/ui/cfg/diagnostics-reexport.stderr index a3a6e13f475ba..eda8151a2706b 100644 --- a/tests/ui/cfg/diagnostics-reexport.stderr +++ b/tests/ui/cfg/diagnostics-reexport.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:18:12 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub fn x() {} | ^ @@ -24,14 +24,14 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:29:12 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub fn x() {} | ^ note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:32:12 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub fn y() {} | ^ @@ -45,7 +45,7 @@ note: found an item that was configured out --> $DIR/diagnostics-reexport.rs:8:20 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub use super::uwu; | ^^^ diff --git a/tests/ui/cfg/diagnostics-same-crate.rs b/tests/ui/cfg/diagnostics-same-crate.rs index 40babaa3d4c9a..203d4656f55ce 100644 --- a/tests/ui/cfg/diagnostics-same-crate.rs +++ b/tests/ui/cfg/diagnostics-same-crate.rs @@ -1,13 +1,13 @@ #![allow(unexpected_cfgs)] // since we want to recognize them as unexpected pub mod inner { - #[cfg(false)] //~ NOTE the item is gated here + #[cfg(false)] //~ NOTE the item is disabled pub fn uwu() {} //~^ NOTE found an item that was configured out - #[cfg(false)] //~ NOTE the item is gated here - //~^ NOTE the item is gated here - //~| NOTE the item is gated here + #[cfg(false)] //~ NOTE the item is disabled + //~^ NOTE the item is disabled + //~| NOTE the item is disabled pub mod doesnt_exist { //~^ NOTE found an item that was configured out //~| NOTE found an item that was configured out @@ -37,7 +37,7 @@ mod placeholder { //~| NOTE could not find `doesnt_exist` in `inner` } -#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] //~ NOTE the item is gated here +#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] //~ NOTE the item is gated behind `i_dont_exist_and_you_can_do_nothing_about_it` pub fn vanished() {} //~ NOTE found an item that was configured out fn main() { diff --git a/tests/ui/cfg/diagnostics-same-crate.stderr b/tests/ui/cfg/diagnostics-same-crate.stderr index c20542e19eaf3..be85c50fc3b30 100644 --- a/tests/ui/cfg/diagnostics-same-crate.stderr +++ b/tests/ui/cfg/diagnostics-same-crate.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:11:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ @@ -23,7 +23,7 @@ note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:11:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ @@ -38,7 +38,7 @@ note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:11:13 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled ... LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ @@ -53,7 +53,7 @@ note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:5:12 | LL | #[cfg(false)] - | ----- the item is gated here + | ----- the item is disabled LL | pub fn uwu() {} | ^^^ @@ -87,7 +87,7 @@ note: found an item that was configured out --> $DIR/diagnostics-same-crate.rs:41:8 | LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] - | -------------------------------------------- the item is gated here + | -------------------------------------------- the item is gated behind `i_dont_exist_and_you_can_do_nothing_about_it` LL | pub fn vanished() {} | ^^^^^^^^ diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs index 8e79ce8d1546f..47eb9277042f4 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.rs @@ -10,7 +10,7 @@ //! //! Added in . -#[cfg_attr(true, cfg_attr(true, cfg(false)))] //~ NOTE the item is gated here +#[cfg_attr(true, cfg_attr(true, cfg(false)))] //~ NOTE the item is disabled fn f() {} //~ NOTE found an item that was configured out fn main() { diff --git a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr index e93a5433d9791..b442e2f59dd28 100644 --- a/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr +++ b/tests/ui/cfg/nested-cfg-attr-conditional-compilation.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/nested-cfg-attr-conditional-compilation.rs:14:4 | LL | #[cfg_attr(true, cfg_attr(true, cfg(false)))] - | ----- the item is gated here + | ----- the item is disabled LL | fn f() {} | ^ diff --git a/tests/ui/conditional-compilation/cfg-empty-any-all.stderr b/tests/ui/conditional-compilation/cfg-empty-any-all.stderr index 1674f2def23a9..7627440b1e7bd 100644 --- a/tests/ui/conditional-compilation/cfg-empty-any-all.stderr +++ b/tests/ui/conditional-compilation/cfg-empty-any-all.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/cfg-empty-any-all.rs:4:8 | LL | #[cfg(any())] // Equivalent to cfg(false) - | -- the item is gated here + | -- the item is disabled LL | struct Disabled; | ^^^^^^^^ help: consider importing this unit variant diff --git a/tests/ui/conditional-compilation/test-cfg.rs b/tests/ui/conditional-compilation/test-cfg.rs index b3fff26a8fd45..0d6b1bc82eda3 100644 --- a/tests/ui/conditional-compilation/test-cfg.rs +++ b/tests/ui/conditional-compilation/test-cfg.rs @@ -1,10 +1,35 @@ //@ compile-flags: --cfg foo --check-cfg=cfg(foo,bar) +#![allow(unexpected_cfgs)] #[cfg(all(foo, bar))] // foo AND bar -//~^ NOTE the item is gated here +//~^ NOTE the item is gated behind `bar` fn foo() {} //~ NOTE found an item that was configured out +#[cfg(feature = "meow")] +//~^ NOTE the item is gated behind the `meow` feature +fn bar() {} //~ NOTE found an item that was configured out + +#[cfg(false)] +//~^ NOTE the item is disabled +fn baz() {} //~ NOTE found an item that was configured out + +#[cfg(any(bar))] +//~^ NOTE the item is gated here +fn quux() {} //~ NOTE found an item that was configured out + +#[cfg(any())] +//~^ NOTE the item is disabled +fn qsdf() {} //~ 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 + bar(); //~ ERROR cannot find function `bar` in this scope + //~^ NOTE not found in this scope + baz(); //~ ERROR cannot find function `baz` in this scope + //~^ NOTE not found in this scope + quux(); //~ ERROR cannot find function `quux` in this scope + //~^ NOTE not found in this scope + qsdf(); //~ ERROR cannot find function `qsdf` 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 379456f74b12f..4a18a07cdf06c 100644 --- a/tests/ui/conditional-compilation/test-cfg.stderr +++ b/tests/ui/conditional-compilation/test-cfg.stderr @@ -1,18 +1,78 @@ error[E0425]: cannot find function `foo` in this scope - --> $DIR/test-cfg.rs:8:5 + --> $DIR/test-cfg.rs:25:5 | LL | foo(); | ^^^ not found in this scope | note: found an item that was configured out - --> $DIR/test-cfg.rs:5:4 + --> $DIR/test-cfg.rs:6:4 | LL | #[cfg(all(foo, bar))] // foo AND bar - | --- the item is gated here + | --- the item is gated behind `bar` LL | LL | fn foo() {} | ^^^ -error: aborting due to 1 previous error +error[E0425]: cannot find function `bar` in this scope + --> $DIR/test-cfg.rs:27:5 + | +LL | bar(); + | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/test-cfg.rs:10:4 + | +LL | #[cfg(feature = "meow")] + | ---------------- the item is gated behind the `meow` feature +LL | +LL | fn bar() {} + | ^^^ + +error[E0425]: cannot find function `baz` in this scope + --> $DIR/test-cfg.rs:29:5 + | +LL | baz(); + | ^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/test-cfg.rs:14:4 + | +LL | #[cfg(false)] + | ----- the item is disabled +LL | +LL | fn baz() {} + | ^^^ + +error[E0425]: cannot find function `quux` in this scope + --> $DIR/test-cfg.rs:31:5 + | +LL | quux(); + | ^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/test-cfg.rs:18:4 + | +LL | #[cfg(any(bar))] + | ----- the item is gated here +LL | +LL | fn quux() {} + | ^^^^ + +error[E0425]: cannot find function `qsdf` in this scope + --> $DIR/test-cfg.rs:33:5 + | +LL | qsdf(); + | ^^^^ not found in this scope + | +note: found an item that was configured out + --> $DIR/test-cfg.rs:22:4 + | +LL | #[cfg(any())] + | -- the item is disabled +LL | +LL | fn qsdf() {} + | ^^^^ + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/macros/builtin-std-paths-fail.stderr b/tests/ui/macros/builtin-std-paths-fail.stderr index 247e3f172a3c7..c5419eb9546c4 100644 --- a/tests/ui/macros/builtin-std-paths-fail.stderr +++ b/tests/ui/macros/builtin-std-paths-fail.stderr @@ -105,7 +105,7 @@ LL | #[std::test] note: found an item that was configured out --> $SRC_DIR/std/src/lib.rs:LL:COL | - = note: the item is gated here + = note: the item is gated behind `test` error: aborting due to 16 previous errors diff --git a/tests/ui/macros/macro-inner-attributes.rs b/tests/ui/macros/macro-inner-attributes.rs index fc69f2e4cebe7..43ce6985f0bb6 100644 --- a/tests/ui/macros/macro-inner-attributes.rs +++ b/tests/ui/macros/macro-inner-attributes.rs @@ -5,7 +5,7 @@ macro_rules! test { ($nm:ident, $i:item) => (mod $nm { #![$a] $i }); } test!(a, //~ NOTE: found an item that was configured out - #[cfg(false)], //~ NOTE: the item is gated here + #[cfg(false)], //~ NOTE: the item is disabled pub fn bar() { }); test!(b, diff --git a/tests/ui/macros/macro-inner-attributes.stderr b/tests/ui/macros/macro-inner-attributes.stderr index 5523dda33c323..f6096cc53c894 100644 --- a/tests/ui/macros/macro-inner-attributes.stderr +++ b/tests/ui/macros/macro-inner-attributes.stderr @@ -10,7 +10,7 @@ note: found an item that was configured out LL | test!(a, | ^ LL | #[cfg(false)], - | ----- the item is gated here + | ----- the item is disabled help: there is a crate or module with a similar name | LL - a::bar(); diff --git a/tests/ui/macros/macro-outer-attributes.stderr b/tests/ui/macros/macro-outer-attributes.stderr index 52bde019c95fd..6755cda5e04ed 100644 --- a/tests/ui/macros/macro-outer-attributes.stderr +++ b/tests/ui/macros/macro-outer-attributes.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/macro-outer-attributes.rs:10:14 | LL | #[cfg(false)], - | ----- the item is gated here + | ----- the item is disabled LL | pub fn bar() { }); | ^^^ help: consider importing this function diff --git a/tests/ui/rustdoc/cfg-rustdoc.rs b/tests/ui/rustdoc/cfg-rustdoc.rs index 11c48d075520f..b49d77fd431c2 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.rs +++ b/tests/ui/rustdoc/cfg-rustdoc.rs @@ -1,4 +1,4 @@ -#[cfg(doc)] //~ NOTE the item is gated here +#[cfg(doc)] //~ NOTE the item is gated behind `doc` pub struct Foo; //~ NOTE found an item that was configured out fn main() { diff --git a/tests/ui/rustdoc/cfg-rustdoc.stderr b/tests/ui/rustdoc/cfg-rustdoc.stderr index 0e8a5dfea61e6..fae90793b6f09 100644 --- a/tests/ui/rustdoc/cfg-rustdoc.stderr +++ b/tests/ui/rustdoc/cfg-rustdoc.stderr @@ -8,7 +8,7 @@ note: found an item that was configured out --> $DIR/cfg-rustdoc.rs:2:12 | LL | #[cfg(doc)] - | --- the item is gated here + | --- the item is gated behind `doc` LL | pub struct Foo; | ^^^