Skip to content
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

unused_qualifications lint confused by pub use Foo::* #138770

Open
nnethercote opened this issue Mar 21, 2025 · 0 comments
Open

unused_qualifications lint confused by pub use Foo::* #138770

nnethercote opened this issue Mar 21, 2025 · 0 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unused_qualifications Lint: unused_qualifications needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nnethercote
Copy link
Contributor

I tried enabling unused_qualifications for the compiler itself. It mostly works, but gets confused by pub use Foo::* forms.

Here's an example from compiler/rustc_ast/src/token.rs, which has this:

pub use LitKind::*;

followed by this:

pub enum LitKind { 
    Bool, // AST only, must never appear in a `Token`
    Byte,
    Char,
    Integer, // e.g. `1`, `1u8`, `1f32`
    Float,   // e.g. `1.`, `1.0`, `1e3f32`
    Str,
    StrRaw(u8), // raw string delimited by `n` hash symbols
    ByteStr,
    ByteStrRaw(u8), // raw byte string delimited by `n` hash symbols
    CStr,
    CStrRaw(u8),
    Err(ErrorGuaranteed),
}   

It emits a bogus error for every variant of the enum. Here's one example:

error: unnecessary qualification
   --> compiler/rustc_ast/src/token.rs:160:10
    |
160 |   pub enum LitKind {
    |  __________^
161 | |     Bool, // AST only, must never appear in a `Token`
162 | |     Byte,
163 | |     Char,
164 | |     Integer, // e.g. `1`, `1u8`, `1f32`
    | |___________^
    |
help: remove the unnecessary path segments
    |
160 - pub enum LitKind {
161 -     Bool, // AST only, must never appear in a `Token`
162 -     Byte,
163 -     Char,
164 -     Integer, // e.g. `1`, `1u8`, `1f32`
160 + pub enum Integer, // e.g. `1`, `1u8`, `1f32`
    |

There is no qualification present, and the help suggestion is nonsense.

I was unable to reproduce this behaviour in a standalone test case.

@nnethercote nnethercote added the C-bug Category: This is a bug. label Mar 21, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 21, 2025
@lolbinarycat lolbinarycat added L-unused_qualifications Lint: unused_qualifications A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unused_qualifications Lint: unused_qualifications needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants