Skip to content

Diagnostic doesn't mention cfg'ed out items if the unresolved path is simple (i.e., a single identifier) #132166

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
fmease opened this issue Oct 26, 2024 · 1 comment · May be fixed by #129183
Labels
A-cfg Area: `cfg` conditional compilation A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Oct 26, 2024

Given the following code, I would've expected rustc to mention the cfg'ed out item Struct:

#[cfg(flag)]
struct Struct;

fn main() { let _ = Struct; } //~ ERROR cannot find type `Struct` in this scope

but it doesn't:

error[E0425]: cannot find value `Struct` in this scope
 --> file.rs:4:21
  |
4 | fn main() { let _ = Struct; }
  |                     ^^^^^^ not found in this scope

Only if you slightly tweak the input by replacing the simple path Struct with a complex one like self::Struct or crate::Struct, the note "found an item that was configured out" will show up:

#[cfg(flag)]
struct Struct;

fn main() { let _ = self::Struct; }
error[E0425]: cannot find value `Struct` in module `self`
 --> file.rs:4:27
  |
4 | fn main() { let _ = self::Struct; }
  |                           ^^^^^^ not found in `self`
  |
note: found an item that was configured out
 --> file.rs:2:8
  |
2 | struct Struct;
  |        ^^^^^^
note: the item is gated here
 --> file.rs:1:1
  |
1 | #[cfg(flag)]
  | ^^^^^^^^^^^^

CC #109005. I don't know if that's intentional or not.

@fmease fmease added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 26, 2024
@fmease fmease linked a pull request Dec 10, 2024 that will close this issue
@joshka
Copy link
Contributor

joshka commented Dec 18, 2024

Possibly related enough to consider as part of this (if it's not already). #134448
(TLDR - cfg out derive macro and trait with the same path don't trigger this diagnostic)

@fmease fmease added the A-cfg Area: `cfg` conditional compilation label Dec 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-cfg Area: `cfg` conditional compilation A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants