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

MSRV-aware std_instead_of_core #13158

Open
kpreid opened this issue Jul 25, 2024 · 1 comment
Open

MSRV-aware std_instead_of_core #13158

kpreid opened this issue Jul 25, 2024 · 1 comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@kpreid
Copy link
Contributor

kpreid commented Jul 25, 2024

Summary

Items sometimes move from std to core. For example, *UnwindSafe have moved, std::error::Error will move in Rust 1.81.0, and std::io::Error might someday.

When this happens, anyone who uses clippy from nightly or beta, or newer than their MSRV, will get lints they cannot satisfy. Therefore, it would be useful if std_instead_of_core, alloc_instead_of_core, and std_instead_of_alloc were MSRV-aware and only fired if the item in question is stable in core or alloc at the declared MSRV.

Lint Name

std_instead_of_core, alloc_instead_of_core, std_instead_of_alloc

Reproducer

I tried this code:

#![feature(custom_inner_attributes)]
#![warn(clippy::std_instead_of_core)]
#![clippy::msrv = "1.80.0"]

use std::error::Error;

I saw this happen:

warning: used import from `std` instead of `core`
 --> src/lib.rs:5:5
  |
5 | use std::error::Error;
  |     ^^^ help: consider importing the item from `core`: `core`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_core
note: the lint level is defined here
 --> src/lib.rs:2:9
  |
2 | #![warn(clippy::std_instead_of_core)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen: No warning

Version

rustc 1.82.0-nightly (c1a6199e9 2024-07-24)
binary: rustc
commit-hash: c1a6199e9d92bb785c17a6d7ffd8b8b552f79c10
commit-date: 2024-07-24
host: x86_64-apple-darwin
release: 1.82.0-nightly
LLVM version: 18.1.7

Additional Labels

@rustbot label -C-bug +C-enhancement

@kpreid kpreid added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 25, 2024
@rustbot rustbot added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed C-bug Category: Clippy is not doing the correct thing labels Jul 25, 2024
@kpreid
Copy link
Contributor Author

kpreid commented Jul 25, 2024

Previous related work: #9545 added checking if the proposed path was unstable.

bors added a commit that referenced this issue Jul 27, 2024
Make `std_instead_of_core` somewhat MSRV aware

For #13158, this catches some things e.g. `core::net` and the recently stable `core::error` but not things moved individually like `UnwindSafe`, as far as I can see the version for those isn't easily available

Beta nominating since ideally we'd get this change in the same version as `core::error` becomes stable

cc `@kpreid`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants