Skip to content

unused_qualification breaks code for older rust versions #129306

@EdJoPaTo

Description

@EdJoPaTo

Code

// Cargo.toml: a rust-version <= 1.79 (while being on 1.80 or nightly)

#![warn(unused_qualifications)]

let align = core::mem::align_of::<u128>();
dbg!(align);

Current output

warning: unnecessary qualification
 --> src/main.rs:9:17
  |
9 |     let align = core::mem::align_of::<u128>();
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(unused_qualifications, unused_imports)]
  |         ^^^^^^^^^^^^^^^^^^^^^
help: remove the unnecessary path segments
  |
9 -     let align = core::mem::align_of::<u128>();
9 +     let align = align_of::<u128>();
  |

Desired output

The lint should not be triggered as core::mem::align_of is only part of the prelude since 1.80 (see #123168)

Rationale and extra context

Adding use core::mem::align_of (or std::…) and using it that way will not trigger unused_imports (warn-by-default) on 1.80 which is somewhat weird. Applying the fixes for unused_qualifications changes the MSRV while unused_imports doesn't?

I somewhat expect this to be closed as won't fix as rustc itself doesn't care about cargo related settings?

Other cases

No response

Rust Version

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-unused_qualificationsLint: unused_qualificationsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions