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

incompatible_msrv fails to detect std::iter::repeat_n #14212

Open
akonradi-signal opened this issue Feb 13, 2025 · 3 comments · May be fixed by #14216
Open

incompatible_msrv fails to detect std::iter::repeat_n #14212

akonradi-signal opened this issue Feb 13, 2025 · 3 comments · May be fixed by #14216
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@akonradi-signal
Copy link

akonradi-signal commented Feb 13, 2025

Summary

std::iter::repeat_n was stabilized in Rust 1.82.0. Running clippy with an earlier MSRV does not detect the incompatible call.

Lint Name

incompatible_msrv

Reproducer

I tried this code:

#[clippy::msrv = "1.80.0"]
#[warn(clippy::incompatible_msrv)]
fn repeat_n() {
    let _ = std::iter::repeat_n((), 5);
}

I expected to see this happen: a warning about repeat_n not being stable until 1.82.0

Instead, this happened: nothing

Version

rustc 1.86.0-nightly (a9730c3b5 2025-02-05)
binary: rustc
commit-hash: a9730c3b5f84a001c052c60c97ed0765e9ceac04
commit-date: 2025-02-05
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
@akonradi-signal akonradi-signal added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Feb 13, 2025
@samueltardieu
Copy link
Contributor

samueltardieu commented Feb 13, 2025

I may be misunderstanding what you're saying, but using #[clippy::msrv = "1.80.0"] does mean "Do not suggest rewrites that would not be compatible with Rust 1.80.0". It does mean "Signal code invalid in Rust 1.80.0", as signaling invalid code is the job of the compiler, not the job of Clippy.

@akonradi-signal
Copy link
Author

akonradi-signal commented Feb 13, 2025

I'd expect a compiler version earlier than 1.82.0 to fail to compile the above code. I'd expect one later than 1.82.0 to compile it without any warnings since the function is defined. I would still expect clippy (1.82.0 and later) to warn about the use of repeat_n.

I filed this bug because when I tried the same formula with other recently-defined standard library functions, clippy complained as expected. I'd expect this code to produce 2 warnings:

#![warn(clippy::incompatible_msrv)]

#[clippy::msrv = "1.80"]
pub fn requires_rust_1_82() {
    let _ = std::iter::repeat_n((), 5);
}

#[clippy::msrv = "1.75"]
pub fn requires_rust_1_79() {
    let _ = std::path::absolute("asdf");
}

but running clippy on the playground only produces 1:

warning: current MSRV (Minimum Supported Rust Version) is `1.75.0` but this item is stable since `1.79.0`
  --> src/lib.rs:10:13
   |
10 |     let _ = std::path::absolute("asdf");
   |             ^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![warn(clippy::incompatible_msrv)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `playground` (lib) generated 1 warning

@samueltardieu
Copy link
Contributor

My bad, you are right. I overlooked the incompatible_msrv lint there.

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants