Skip to content

Commit

Permalink
Unrolled build for rust-lang#127662
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#127662 - estebank:gate-span, r=TaKO8Ki

When finding item gated behind a `cfg` flag, 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)]
   |     ^^^^^^^^^^^^^
```
  • Loading branch information
rust-timer committed Jul 19, 2024
2 parents 11e5724 + cf09cba commit 9731b7f
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 25 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_resolve/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
&& 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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/cfg/diagnostics-cross-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
27 changes: 23 additions & 4 deletions tests/ui/cfg/diagnostics-cross-crate.stderr
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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
Expand All @@ -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`
Expand All @@ -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`
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/cfg/diagnostics-reexport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod inner {
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
}
Expand All @@ -14,7 +14,7 @@ pub use a::x;
//~| 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
}
Expand All @@ -25,10 +25,10 @@ pub use b::{x, y};
//~| 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
}
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/cfg/diagnostics-reexport.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
9 changes: 5 additions & 4 deletions tests/ui/cfg/diagnostics-same-crate.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,7 +22,7 @@ pub mod inner {
}

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
}
Expand Down Expand Up @@ -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.
Expand Down
48 changes: 36 additions & 12 deletions tests/ui/cfg/diagnostics-same-crate.stderr
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/macros/builtin-std-paths-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/macros/macro-outer-attributes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9731b7f

Please sign in to comment.