When finding item gated behind a cfg
flat, point at it
Previously we would only mention that the item was gated out, and opportunisitically mention the feature flag name when possible. We now point to the place where the item was gated, which can be behind layers of macro indirection, or in different modules. ``` error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` --> $DIR/diagnostics-cross-crate.rs:18:23 | LL | cfged_out::inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` | note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ note: the item is gated here --> $DIR/auxiliary/cfged_out.rs:5:5 | LL | #[cfg(FALSE)] | ^^^^^^^^^^^^^ ```
This commit is contained in:
parent
5d76a13bbe
commit
cf09cba20c
@ -232,6 +232,8 @@ resolve_is_private =
|
||||
resolve_item_was_behind_feature =
|
||||
the item is gated behind the `{$feature}` feature
|
||||
|
||||
resolve_item_was_cfg_out = the item is gated here
|
||||
|
||||
resolve_items_in_traits_are_not_importable =
|
||||
items in traits are not importable
|
||||
|
||||
|
@ -2530,7 +2530,13 @@ pub(crate) fn find_cfg_stripped(
|
||||
&& let NestedMetaItem::MetaItem(meta_item) = &nested[0]
|
||||
&& let MetaItemKind::NameValue(feature_name) = &meta_item.kind
|
||||
{
|
||||
let note = errors::ItemWasBehindFeature { feature: feature_name.symbol };
|
||||
let note = errors::ItemWasBehindFeature {
|
||||
feature: feature_name.symbol,
|
||||
span: meta_item.span,
|
||||
};
|
||||
err.subdiagnostic(note);
|
||||
} else {
|
||||
let note = errors::ItemWasCfgOut { span: cfg.span };
|
||||
err.subdiagnostic(note);
|
||||
}
|
||||
}
|
||||
|
@ -1228,6 +1228,15 @@ pub(crate) struct FoundItemConfigureOut {
|
||||
#[note(resolve_item_was_behind_feature)]
|
||||
pub(crate) struct ItemWasBehindFeature {
|
||||
pub(crate) feature: Symbol,
|
||||
#[primary_span]
|
||||
pub(crate) span: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(resolve_item_was_cfg_out)]
|
||||
pub(crate) struct ItemWasCfgOut {
|
||||
#[primary_span]
|
||||
pub(crate) span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
@ -11,12 +11,14 @@ fn main() {
|
||||
cfged_out::inner::uwu(); //~ ERROR cannot find function
|
||||
//~^ NOTE found an item that was configured out
|
||||
//~| NOTE not found in `cfged_out::inner`
|
||||
//~| NOTE the item is gated here
|
||||
|
||||
// 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.
|
||||
cfged_out::inner::doesnt_exist::hello(); //~ ERROR failed to resolve
|
||||
//~^ NOTE could not find `doesnt_exist` in `inner`
|
||||
//~| NOTE found an item that was configured out
|
||||
//~| NOTE the item is gated here
|
||||
|
||||
// It should find the one in the right module, not the wrong one.
|
||||
cfged_out::inner::right::meow(); //~ ERROR cannot find function
|
||||
@ -28,4 +30,5 @@ fn main() {
|
||||
cfged_out::vanished(); //~ ERROR cannot find function
|
||||
//~^ NOTE found an item that was configured out
|
||||
//~| NOTE not found in `cfged_out`
|
||||
//~| NOTE the item is gated here
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
|
||||
--> $DIR/diagnostics-cross-crate.rs:17:23
|
||||
--> $DIR/diagnostics-cross-crate.rs:18:23
|
||||
|
|
||||
LL | cfged_out::inner::doesnt_exist::hello();
|
||||
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
||||
@ -9,6 +9,11 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub mod doesnt_exist {
|
||||
| ^^^^^^^^^^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/auxiliary/cfged_out.rs:5:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `uwu` in crate `cfged_out`
|
||||
--> $DIR/diagnostics-cross-crate.rs:7:16
|
||||
@ -27,9 +32,14 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn uwu() {}
|
||||
| ^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/auxiliary/cfged_out.rs:2:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `meow` in module `cfged_out::inner::right`
|
||||
--> $DIR/diagnostics-cross-crate.rs:22:30
|
||||
--> $DIR/diagnostics-cross-crate.rs:24:30
|
||||
|
|
||||
LL | cfged_out::inner::right::meow();
|
||||
| ^^^^ not found in `cfged_out::inner::right`
|
||||
@ -39,10 +49,14 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn meow() {}
|
||||
| ^^^^
|
||||
= note: the item is gated behind the `what-a-cool-feature` feature
|
||||
note: the item is gated behind the `what-a-cool-feature` feature
|
||||
--> $DIR/auxiliary/cfged_out.rs:16:15
|
||||
|
|
||||
LL | #[cfg(feature = "what-a-cool-feature")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `vanished` in crate `cfged_out`
|
||||
--> $DIR/diagnostics-cross-crate.rs:28:16
|
||||
--> $DIR/diagnostics-cross-crate.rs:30:16
|
||||
|
|
||||
LL | cfged_out::vanished();
|
||||
| ^^^^^^^^ not found in `cfged_out`
|
||||
@ -52,6 +66,11 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn vanished() {}
|
||||
| ^^^^^^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/auxiliary/cfged_out.rs:21:1
|
||||
|
|
||||
LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
@ -4,7 +4,7 @@ mod gone {
|
||||
pub fn uwu() {}
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
#[cfg(FALSE)] //~ NOTE the item is gated here
|
||||
pub use super::uwu;
|
||||
//~^ NOTE found an item that was configured out
|
||||
}
|
||||
@ -14,7 +14,7 @@ pub fn uwu() {}
|
||||
//~| NOTE no `x` in `a`
|
||||
|
||||
mod a {
|
||||
#[cfg(FALSE)]
|
||||
#[cfg(FALSE)] //~ NOTE the item is gated here
|
||||
pub fn x() {}
|
||||
//~^ NOTE found an item that was configured out
|
||||
}
|
||||
@ -25,10 +25,10 @@ pub fn x() {}
|
||||
//~| NOTE no `y` in `b`
|
||||
|
||||
mod b {
|
||||
#[cfg(FALSE)]
|
||||
#[cfg(FALSE)] //~ NOTE the item is gated here
|
||||
pub fn x() {}
|
||||
//~^ NOTE found an item that was configured out
|
||||
#[cfg(FALSE)]
|
||||
#[cfg(FALSE)] //~ NOTE the item is gated here
|
||||
pub fn y() {}
|
||||
//~^ NOTE found an item that was configured out
|
||||
}
|
||||
|
@ -9,6 +9,11 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn x() {}
|
||||
| ^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-reexport.rs:17:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0432]: unresolved imports `b::x`, `b::y`
|
||||
--> $DIR/diagnostics-reexport.rs:22:13
|
||||
@ -23,11 +28,21 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn x() {}
|
||||
| ^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-reexport.rs:28:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
note: found an item that was configured out
|
||||
--> $DIR/diagnostics-reexport.rs:32:12
|
||||
|
|
||||
LL | pub fn y() {}
|
||||
| ^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-reexport.rs:31:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `uwu` in module `inner`
|
||||
--> $DIR/diagnostics-reexport.rs:38:12
|
||||
@ -40,6 +55,11 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub use super::uwu;
|
||||
| ^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-reexport.rs:7:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
#![allow(unexpected_cfgs)] // since we want to recognize them as unexpected
|
||||
|
||||
pub mod inner {
|
||||
#[cfg(FALSE)]
|
||||
#[cfg(FALSE)] //~ NOTE the item is gated here
|
||||
pub fn uwu() {}
|
||||
//~^ NOTE found an item that was configured out
|
||||
|
||||
#[cfg(FALSE)]
|
||||
#[cfg(FALSE)] //~ NOTE the item is gated here
|
||||
//~^ NOTE the item is gated here
|
||||
//~| NOTE the item is gated here
|
||||
pub mod doesnt_exist {
|
||||
//~^ NOTE found an item that was configured out
|
||||
//~| NOTE found an item that was configured out
|
||||
@ -20,7 +22,7 @@ pub fn meow() {}
|
||||
}
|
||||
|
||||
pub mod right {
|
||||
#[cfg(feature = "what-a-cool-feature")]
|
||||
#[cfg(feature = "what-a-cool-feature")] //~ NOTE the item is gated behind the `what-a-cool-feature` feature
|
||||
pub fn meow() {}
|
||||
//~^ NOTE found an item that was configured out
|
||||
}
|
||||
@ -55,7 +57,6 @@ fn main() {
|
||||
// It should find the one in the right module, not the wrong one.
|
||||
inner::right::meow(); //~ ERROR cannot find function
|
||||
//~| NOTE not found in `inner::right
|
||||
//~| NOTE the item is gated behind the `what-a-cool-feature` feature
|
||||
|
||||
// Exists in the crate root - we would generally want a diagnostic,
|
||||
// but currently don't have one.
|
||||
|
@ -1,41 +1,56 @@
|
||||
error[E0432]: unresolved import `super::inner::doesnt_exist`
|
||||
--> $DIR/diagnostics-same-crate.rs:30:9
|
||||
--> $DIR/diagnostics-same-crate.rs:32:9
|
||||
|
|
||||
LL | use super::inner::doesnt_exist;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `doesnt_exist` in `inner`
|
||||
|
|
||||
note: found an item that was configured out
|
||||
--> $DIR/diagnostics-same-crate.rs:9:13
|
||||
--> $DIR/diagnostics-same-crate.rs:11:13
|
||||
|
|
||||
LL | pub mod doesnt_exist {
|
||||
| ^^^^^^^^^^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-same-crate.rs:8:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0432]: unresolved import `super::inner::doesnt_exist`
|
||||
--> $DIR/diagnostics-same-crate.rs:33:23
|
||||
--> $DIR/diagnostics-same-crate.rs:35:23
|
||||
|
|
||||
LL | use super::inner::doesnt_exist::hi;
|
||||
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
||||
|
|
||||
note: found an item that was configured out
|
||||
--> $DIR/diagnostics-same-crate.rs:9:13
|
||||
--> $DIR/diagnostics-same-crate.rs:11:13
|
||||
|
|
||||
LL | pub mod doesnt_exist {
|
||||
| ^^^^^^^^^^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-same-crate.rs:8:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
|
||||
--> $DIR/diagnostics-same-crate.rs:52:12
|
||||
--> $DIR/diagnostics-same-crate.rs:54:12
|
||||
|
|
||||
LL | inner::doesnt_exist::hello();
|
||||
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
||||
|
|
||||
note: found an item that was configured out
|
||||
--> $DIR/diagnostics-same-crate.rs:9:13
|
||||
--> $DIR/diagnostics-same-crate.rs:11:13
|
||||
|
|
||||
LL | pub mod doesnt_exist {
|
||||
| ^^^^^^^^^^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-same-crate.rs:8:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `uwu` in module `inner`
|
||||
--> $DIR/diagnostics-same-crate.rs:47:12
|
||||
--> $DIR/diagnostics-same-crate.rs:49:12
|
||||
|
|
||||
LL | inner::uwu();
|
||||
| ^^^ not found in `inner`
|
||||
@ -45,28 +60,37 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn uwu() {}
|
||||
| ^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/diagnostics-same-crate.rs:4:5
|
||||
|
|
||||
LL | #[cfg(FALSE)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `meow` in module `inner::right`
|
||||
--> $DIR/diagnostics-same-crate.rs:56:19
|
||||
--> $DIR/diagnostics-same-crate.rs:58:19
|
||||
|
|
||||
LL | inner::right::meow();
|
||||
| ^^^^ not found in `inner::right`
|
||||
|
|
||||
note: found an item that was configured out
|
||||
--> $DIR/diagnostics-same-crate.rs:24:16
|
||||
--> $DIR/diagnostics-same-crate.rs:26:16
|
||||
|
|
||||
LL | pub fn meow() {}
|
||||
| ^^^^
|
||||
= note: the item is gated behind the `what-a-cool-feature` feature
|
||||
note: the item is gated behind the `what-a-cool-feature` feature
|
||||
--> $DIR/diagnostics-same-crate.rs:25:15
|
||||
|
|
||||
LL | #[cfg(feature = "what-a-cool-feature")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `uwu` in this scope
|
||||
--> $DIR/diagnostics-same-crate.rs:43:5
|
||||
--> $DIR/diagnostics-same-crate.rs:45:5
|
||||
|
|
||||
LL | uwu();
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0425]: cannot find function `vanished` in this scope
|
||||
--> $DIR/diagnostics-same-crate.rs:63:5
|
||||
--> $DIR/diagnostics-same-crate.rs:64:5
|
||||
|
|
||||
LL | vanished();
|
||||
| ^^^^^^^^ not found in this scope
|
||||
|
@ -104,6 +104,8 @@ 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
|
||||
--> $SRC_DIR/std/src/lib.rs:LL:COL
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
@ -9,6 +9,17 @@ note: found an item that was configured out
|
||||
|
|
||||
LL | pub fn bar() { });
|
||||
| ^^^
|
||||
note: the item is gated here
|
||||
--> $DIR/macro-outer-attributes.rs:5:45
|
||||
|
|
||||
LL | $i:item) => (mod $nm { #[$a] $i }); }
|
||||
| ^^^^^
|
||||
LL |
|
||||
LL | / test!(a,
|
||||
LL | | #[cfg(FALSE)],
|
||||
LL | | pub fn bar() { });
|
||||
| |_______________________- in this macro invocation
|
||||
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: consider importing this function
|
||||
|
|
||||
LL + use b::bar;
|
||||
|
Loading…
Reference in New Issue
Block a user