rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.79k stars 12.5k forks source link

`unused_qualification` breaks code for older rust versions #129306

Open EdJoPaTo opened 3 weeks ago

EdJoPaTo commented 3 weeks ago

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 https://github.com/rust-lang/rust/pull/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

ChayimFriedman2 commented 3 weeks ago

I don't think the Rust compiler considers the MSRV defined in Cargo.toml in any way (I think Clippy does, though).