about summary refs log tree commit diff
path: root/doc/adding_lints.md
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-26 21:25:19 +0000
committerbors <bors@rust-lang.org>2021-04-26 21:25:19 +0000
commitf33d86df4efda60f48b8fa3c1cc2d88e35000601 (patch)
tree26836a970f38c25cc6a0b422730abd6881aa4610 /doc/adding_lints.md
parenta362a4d1d0edb66aef186c1d27b28c60573078f4 (diff)
parent3a8e759d8a6250b77c37fd43a13aab34b82bbfbb (diff)
Auto merge of #7137 - camsteffen:msrv-mod, r=llogiq
Refactor MSRV aliases

changelog: Remove MSRV from `needless_question_mark` and change MSRV for `missing_const_for_fn` from 1.37.0 to 1.46.0.

First [mentioned on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Better.20MSRV.20testing.20idea/near/236215074).

* Moves MSRV constants into `clippy_utils::msrvs`. Now they are named to represent a stabilized feature flag or library item that is required for a lint's suggestion.
* `needless_question_mark` no longer has MSRV. Not needed since it does not suggest adding `?`.
* `missing_const_for_fn` MSRV was changed from 1.37.0 to 1.46.0. This seems to be a past mistake.
Diffstat (limited to 'doc/adding_lints.md')
-rw-r--r--doc/adding_lints.md24
1 files changed, 15 insertions, 9 deletions
diff --git a/doc/adding_lints.md b/doc/adding_lints.md
index 50f0d724016..d6cc6d0c2c7 100644
--- a/doc/adding_lints.md
+++ b/doc/adding_lints.md
@@ -390,17 +390,23 @@ pass.
 
 ## Specifying the lint's minimum supported Rust version (MSRV)
 
-Projects supporting older versions of Rust would need to disable a lint if it
-targets features present in later versions. Support for this can be added by
-specifying an MSRV in your lint like so,
+Sometimes a lint makes suggestions that require a certain version of Rust. For example, the `manual_strip` lint suggests
+using `str::strip_prefix` and `str::strip_suffix` which is only available after Rust 1.45. In such cases, you need to
+ensure that the MSRV configured for the project is >= the MSRV of the required Rust feature. If multiple features are
+required, just use the one with a lower MSRV.
+
+First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`](/clippy_utils/src/msrvs.rs). This can be
+accessed later as `msrvs::STR_STRIP_PREFIX`, for example.
 
 ```rust
-const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0);
+msrv_aliases! {
+    ..
+    1,45,0 { STR_STRIP_PREFIX }
+}
 ```
 
-The project's MSRV will also have to be an attribute in the lint so you'll have
-to add a struct and constructor for your lint. The project's MSRV needs to be
-passed when the lint is registered in `lib.rs`
+In order to access the project-configured MSRV, you need to have an `msrv` field in the LintPass struct, and a
+constructor to initialize the field. The `msrv` value is passed to the constructor in `clippy_lints/lib.rs`.
 
 ```rust
 pub struct ManualStrip {
@@ -415,11 +421,11 @@ impl ManualStrip {
 }
 ```
 
-The project's MSRV can then be matched against the lint's `msrv` in the LintPass
+The project's MSRV can then be matched against the feature MSRV in the LintPass
 using the `meets_msrv` utility function.
 
 ``` rust
-if !meets_msrv(self.msrv.as_ref(), &MANUAL_STRIP_MSRV) {
+if !meets_msrv(self.msrv.as_ref(), &msrvs::STR_STRIP_PREFIX) {
     return;
 }
 ```