about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-03-18 18:03:53 +0100
committerSamuel Tardieu <sam@rfc1149.net>2025-05-21 17:17:30 +0200
commit96ae10e2316d6f8836c4cd06ef80b80be03e8628 (patch)
treecb56a6bd78b1a38edbe860ff38925a3df871d08f
parentcadf98bb7d783e2ea3572446c3f80d3592ec5f86 (diff)
downloadrust-96ae10e2316d6f8836c4cd06ef80b80be03e8628.tar.gz
rust-96ae10e2316d6f8836c4cd06ef80b80be03e8628.zip
Document changing `clippy::msrv` with a feature gate
-rw-r--r--clippy_lints/src/incompatible_msrv.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/clippy_lints/src/incompatible_msrv.rs b/clippy_lints/src/incompatible_msrv.rs
index 5d0bd3e8ca3..523fc4efc59 100644
--- a/clippy_lints/src/incompatible_msrv.rs
+++ b/clippy_lints/src/incompatible_msrv.rs
@@ -33,6 +33,39 @@ declare_clippy_lint! {
     ///
     /// 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:
+    ///
+    /// ```no_run
+    /// //! 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:
+    ///
+    /// ```no_run
+    /// // 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.
+    /// }
+    /// ```
     #[clippy::version = "1.78.0"]
     pub INCOMPATIBLE_MSRV,
     suspicious,