-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Remember names of cfg
-ed out items to mention them in diagnostics
#109005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+599
−84
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
//! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`. | ||
use rustc_span::{def_id::DefId, symbol::Ident}; | ||
|
||
use crate::MetaItem; | ||
|
||
pub mod allocator; | ||
|
||
#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)] | ||
pub struct StrippedCfgItem<ModId = DefId> { | ||
pub parent_module: ModId, | ||
pub name: Ident, | ||
pub cfg: MetaItem, | ||
} | ||
|
||
impl<ModId> StrippedCfgItem<ModId> { | ||
pub fn map_mod_id<New>(self, f: impl FnOnce(ModId) -> New) -> StrippedCfgItem<New> { | ||
StrippedCfgItem { parent_module: f(self.parent_module), name: self.name, cfg: self.cfg } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pub mod inner { | ||
#[cfg(FALSE)] | ||
pub fn uwu() {} | ||
|
||
#[cfg(FALSE)] | ||
pub mod doesnt_exist { | ||
pub fn hello() {} | ||
} | ||
|
||
pub mod wrong { | ||
#[cfg(feature = "suggesting me fails the test!!")] | ||
pub fn meow() {} | ||
} | ||
|
||
pub mod right { | ||
#[cfg(feature = "what-a-cool-feature")] | ||
pub fn meow() {} | ||
} | ||
} | ||
|
||
#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] | ||
pub fn vanished() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// aux-build:cfged_out.rs | ||
|
||
extern crate cfged_out; | ||
|
||
fn main() { | ||
// There is no uwu at this path - no diagnostic. | ||
cfged_out::uwu(); //~ ERROR cannot find function | ||
//~^ NOTE not found in `cfged_out` | ||
|
||
// It does exist here - diagnostic. | ||
cfged_out::inner::uwu(); //~ ERROR cannot find function | ||
//~^ NOTE found an item that was configured out | ||
//~| NOTE not found in `cfged_out::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. | ||
// FIXME(Nilstrieb): Also add a note to the cfg diagnostic here | ||
cfged_out::inner::doesnt_exist::hello(); //~ ERROR failed to resolve | ||
//~^ NOTE could not find `doesnt_exist` in `inner` | ||
|
||
// It should find the one in the right module, not the wrong one. | ||
cfged_out::inner::right::meow(); //~ ERROR cannot find function | ||
//~^ NOTE found an item that was configured out | ||
//~| NOTE not found in `cfged_out::inner::right | ||
//~| NOTE the item is gated behind the `what-a-cool-feature` feature | ||
|
||
// Exists in the crate root - diagnostic. | ||
cfged_out::vanished(); //~ ERROR cannot find function | ||
//~^ NOTE found an item that was configured out | ||
//~| NOTE not found in `cfged_out` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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` | ||
|
||
error[E0425]: cannot find function `uwu` in crate `cfged_out` | ||
--> $DIR/diagnostics-cross-crate.rs:7:16 | ||
| | ||
LL | cfged_out::uwu(); | ||
| ^^^ not found in `cfged_out` | ||
|
||
error[E0425]: cannot find function `uwu` in module `cfged_out::inner` | ||
--> $DIR/diagnostics-cross-crate.rs:11:23 | ||
| | ||
LL | cfged_out::inner::uwu(); | ||
| ^^^ not found in `cfged_out::inner` | ||
| | ||
note: found an item that was configured out | ||
--> $DIR/auxiliary/cfged_out.rs:3:12 | ||
| | ||
LL | pub fn uwu() {} | ||
| ^^^ | ||
|
||
error[E0425]: cannot find function `meow` in module `cfged_out::inner::right` | ||
--> $DIR/diagnostics-cross-crate.rs:22:30 | ||
| | ||
LL | cfged_out::inner::right::meow(); | ||
| ^^^^ not found in `cfged_out::inner::right` | ||
| | ||
note: found an item that was configured out | ||
--> $DIR/auxiliary/cfged_out.rs:17:16 | ||
| | ||
LL | pub fn meow() {} | ||
| ^^^^ | ||
= note: the item is gated behind the `what-a-cool-feature` feature | ||
|
||
error[E0425]: cannot find function `vanished` in crate `cfged_out` | ||
--> $DIR/diagnostics-cross-crate.rs:28:16 | ||
| | ||
LL | cfged_out::vanished(); | ||
| ^^^^^^^^ not found in `cfged_out` | ||
| | ||
note: found an item that was configured out | ||
--> $DIR/auxiliary/cfged_out.rs:22:8 | ||
| | ||
LL | pub fn vanished() {} | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0425, E0433. | ||
For more information about an error, try `rustc --explain E0425`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pub mod inner { | ||
pub fn i_am_here() { | ||
#[cfg(feature = "another one that doesn't exist")] | ||
loop {} | ||
} | ||
} | ||
|
||
fn main() { | ||
inner::i_am_here(); | ||
// ensure that nothing bad happens when we are checking for cfgs | ||
inner::i_am_not(); //~ ERROR cannot find function | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0425]: cannot find function `i_am_not` in module `inner` | ||
--> $DIR/diagnostics-not-a-def.rs:11:12 | ||
| | ||
LL | inner::i_am_not(); | ||
| ^^^^^^^^ not found in `inner` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub mod inner { | ||
#[cfg(FALSE)] | ||
mod gone { | ||
pub fn uwu() {} | ||
} | ||
|
||
#[cfg(FALSE)] | ||
pub use super::uwu; | ||
//~^ NOTE found an item that was configured out | ||
} | ||
|
||
fn main() { | ||
// There is no uwu at this path - no diagnostic. | ||
inner::uwu(); //~ ERROR cannot find function | ||
//~^ NOTE not found in `inner` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0425]: cannot find function `uwu` in module `inner` | ||
--> $DIR/diagnostics-reexport.rs:14:12 | ||
| | ||
LL | inner::uwu(); | ||
| ^^^ not found in `inner` | ||
| | ||
note: found an item that was configured out | ||
--> $DIR/diagnostics-reexport.rs:8:20 | ||
| | ||
LL | pub use super::uwu; | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
pub mod inner { | ||
#[cfg(FALSE)] | ||
pub fn uwu() {} | ||
//~^ NOTE found an item that was configured out | ||
|
||
#[cfg(FALSE)] | ||
pub mod doesnt_exist { | ||
pub fn hello() {} | ||
} | ||
|
||
pub mod wrong { | ||
#[cfg(feature = "suggesting me fails the test!!")] | ||
pub fn meow() {} | ||
} | ||
|
||
pub mod right { | ||
#[cfg(feature = "what-a-cool-feature")] | ||
pub fn meow() {} | ||
//~^ NOTE found an item that was configured out | ||
} | ||
} | ||
|
||
#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)] | ||
pub fn vanished() {} | ||
|
||
fn main() { | ||
// There is no uwu at this path - no diagnostic. | ||
uwu(); //~ ERROR cannot find function | ||
//~^ NOTE not found in this scope | ||
|
||
// It does exist here - diagnostic. | ||
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. | ||
// FIXME(Nilstrieb): Also add a note to the cfg diagnostic here | ||
inner::doesnt_exist::hello(); //~ ERROR failed to resolve | ||
//~| NOTE could not find `doesnt_exist` in `inner` | ||
|
||
// 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. | ||
// Not that it matters much though, this is highly unlikely to confuse anyone. | ||
vanished(); //~ ERROR cannot find function | ||
//~^ NOTE not found in this scope | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` | ||
--> $DIR/diagnostics-same-crate.rs:38:12 | ||
| | ||
LL | inner::doesnt_exist::hello(); | ||
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` | ||
|
||
error[E0425]: cannot find function `uwu` in module `inner` | ||
--> $DIR/diagnostics-same-crate.rs:32:12 | ||
| | ||
LL | inner::uwu(); | ||
| ^^^ not found in `inner` | ||
| | ||
note: found an item that was configured out | ||
--> $DIR/diagnostics-same-crate.rs:3:12 | ||
| | ||
LL | pub fn uwu() {} | ||
| ^^^ | ||
|
||
error[E0425]: cannot find function `meow` in module `inner::right` | ||
--> $DIR/diagnostics-same-crate.rs:42:19 | ||
| | ||
LL | inner::right::meow(); | ||
| ^^^^ not found in `inner::right` | ||
| | ||
note: found an item that was configured out | ||
--> $DIR/diagnostics-same-crate.rs:18:16 | ||
| | ||
LL | pub fn meow() {} | ||
| ^^^^ | ||
= note: the item is gated behind the `what-a-cool-feature` feature | ||
|
||
error[E0425]: cannot find function `uwu` in this scope | ||
--> $DIR/diagnostics-same-crate.rs:28:5 | ||
| | ||
LL | uwu(); | ||
| ^^^ not found in this scope | ||
|
||
error[E0425]: cannot find function `vanished` in this scope | ||
--> $DIR/diagnostics-same-crate.rs:49:5 | ||
| | ||
LL | vanished(); | ||
| ^^^^^^^^ not found in this scope | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0425, E0433. | ||
For more information about an error, try `rustc --explain E0425`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.