Clippy lints / Suspicious
Clippy lint · Suspicious · checked with Clippy 0.1.99
clippy::incompatible_msrv: This lint checks that no function newer than the defined MSRV (minimum supported rust version) is used in the crate
What it meansThis lint checks that no function newer than the defined MSRV (minimum supported rust version) is used in the crate. It is in the suspicious group and warns by default.
Does it matter?
It would prevent the crate to be actually used with the specified MSRV.
Code that is most likely wrong or useless. Warns by default.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
// MSRV of 1.3.0
use std::thread::sleep;
use std::time::Duration;
// Sleep was defined in `1.4.0`.
sleep(Duration::new(1, 0));
Write this instead
//! This crate has a MSRV of 1.3.0, but we also have an optional feature
//! `sleep_well` which requires at least Rust 1.4.0.
// When the `sleep_well` feature is set, do not warn for functions available
// in Rust 1.4.0 and below.
#![cfg_attr(feature = "sleep_well", clippy::msrv = "1.4.0")]
use std::time::Duration;
#[cfg(feature = "sleep_well")]
fn sleep_for_some_time() {
std::thread::sleep(Duration::new(1, 0)); // Will not trigger the lint
}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::incompatible_msrv)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
incompatible_msrv = "allow"One run
cargo clippy -- -A clippy::incompatible-msrvThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Settings in clippy.toml
check-incompatible-msrv-in-tests: Whether to check MSRV compatibility in #[test] and #[cfg(test)] code.
Clippy's own documentation
What it does
This lint checks that no function newer than the defined MSRV (minimum supported rust version) is used in the crate.
Why is this bad?
It would prevent the crate to be actually used with the specified MSRV.
Example
// MSRV of 1.3.0
use std::thread::sleep;
use std::time::Duration;
// Sleep was defined in `1.4.0`.
sleep(Duration::new(1, 0));
To fix this problem, either increase your MSRV or use another item available in your current MSRV.
You can also locally change the MSRV that should be checked by Clippy,
for example if a feature in your crate (e.g., modern_compiler) should
allow you to use an item:
//! This crate has a MSRV of 1.3.0, but we also have an optional feature
//! `sleep_well` which requires at least Rust 1.4.0.
// When the `sleep_well` feature is set, do not warn for functions available
// in Rust 1.4.0 and below.
#![cfg_attr(feature = "sleep_well", clippy::msrv = "1.4.0")]
use std::time::Duration;
#[cfg(feature = "sleep_well")]
fn sleep_for_some_time() {
std::thread::sleep(Duration::new(1, 0)); // Will not trigger the lint
}
You can also increase the MSRV in tests, by using:
// Use a much higher MSRV for tests while keeping the main one low
#![cfg_attr(test, clippy::msrv = "1.85.0")]
#[test]
fn my_test() {
// The tests can use items introduced in Rust 1.85.0 and lower
// without triggering the `incompatible_msrv` lint.
}
Configuration
-
check-incompatible-msrv-in-tests: Whether to check MSRV compatibility in#[test]and#[cfg(test)]code.(default:
false)
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- forget_non_dropcall to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it
- four_forward_slashesthis item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
- from_raw_with_void_ptrChecks if we’re passing a c_void raw pointer to {Box,Rc,Arc,Weak}::from_raw(_)
- ineffective_open_optionsChecks if both .write(true) and .append(true) methods are called on a same OpenOptions
- infallible_try_frominfallible TryFrom impl; consider implementing From instead
- iter_out_of_boundsthis `.take()` call takes more items than the iterator will produce
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::forget_non_dropcall to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping itRead it next →Did this answer your question?