Skip to content

incompatible_msrv false negative: tests #14277

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

Closed
bryceberger opened this issue Feb 22, 2025 · 0 comments · Fixed by #14279
Closed

incompatible_msrv false negative: tests #14277

bryceberger opened this issue Feb 22, 2025 · 0 comments · Fixed by #14279
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

@bryceberger
Copy link
Contributor

Summary

I disagree with the resolution of #12257, and think that incompatible_msrv should apply to tests. Given the conflicting desires, I think it would make sense to provide a config option for this lint.

I would like something akin to the following:

# clippy.toml
check-incompatible-msrv-in-tests = true

Background: jj currently has an MSRV of 1.76. However, it's encouraged to use newer / nightly compilers during development, to take advantage of speed improvements / parallel frontend / etc. As such, they do not force a version using rust-toolchain.toml. A PRs that added a rust-toolchain.toml pin was closed under the assumption that incompatible_msrv would help with this (jj-vcs/jj#1913 (comment)).

#12257 makes the argument:

However, test-only code does not prevent the crate from being used with the specified MSRV, as a library. Tests are not compiled when a crate is used as a dependency.

However, tests are compiled when the tests are ran in CI. We would like to keep the CI pinned to MSRV, and do not want to have separate Build (MSRV) and Test (latest stable) CI jobs.

Lint Name

incompatible_msrv

Reproducer

# Cargo.toml
[package]
name = "repro"
edition = "2021"
rust-version = "1.76"
// src/lib.rs
#[test]
fn repro() {
    assert!(std::fs::exists("/").unwrap());
}
$ cargo clippy --tests
# no output...

Version

rustc 1.86.0-nightly (854f22563 2025-01-31)
binary: rustc
commit-hash: 854f22563c8daf92709fae18ee6aed52953835cd
commit-date: 2025-01-31
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
@bryceberger bryceberger 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 22, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 28, 2025
fixes #14277

changelog: [`incompatible_msrv`]: add config option
[`check-incompatible-msrv-in-tests`] to enable in `#[test]` and
`#[cfg(test)]` code.
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.

1 participant