Email me

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-msrv

The [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.
Suspiciousgroup
warndefault level
nofixed by cargo clippy --fix
1.78.0added in Rust

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

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?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ