Skip to content

Commit 3a8e759

Browse files
committed
Update MSRV contribution docs
1 parent 340b570 commit 3a8e759

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

doc/adding_lints.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,23 @@ pass.
390390

391391
## Specifying the lint's minimum supported Rust version (MSRV)
392392

393-
Projects supporting older versions of Rust would need to disable a lint if it
394-
targets features present in later versions. Support for this can be added by
395-
specifying an MSRV in your lint like so,
393+
Sometimes a lint makes suggestions that require a certain version of Rust. For example, the `manual_strip` lint suggests
394+
using `str::strip_prefix` and `str::strip_suffix` which is only available after Rust 1.45. In such cases, you need to
395+
ensure that the MSRV configured for the project is >= the MSRV of the required Rust feature. If multiple features are
396+
required, just use the one with a lower MSRV.
397+
398+
First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`](/clippy_utils/src/msrvs.rs). This can be
399+
accessed later as `msrvs::STR_STRIP_PREFIX`, for example.
396400

397401
```rust
398-
const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0);
402+
msrv_aliases! {
403+
..
404+
1,45,0 { STR_STRIP_PREFIX }
405+
}
399406
```
400407

401-
The project's MSRV will also have to be an attribute in the lint so you'll have
402-
to add a struct and constructor for your lint. The project's MSRV needs to be
403-
passed when the lint is registered in `lib.rs`
408+
In order to access the project-configured MSRV, you need to have an `msrv` field in the LintPass struct, and a
409+
constructor to initialize the field. The `msrv` value is passed to the constructor in `clippy_lints/lib.rs`.
404410

405411
```rust
406412
pub struct ManualStrip {
@@ -415,11 +421,11 @@ impl ManualStrip {
415421
}
416422
```
417423

418-
The project's MSRV can then be matched against the lint's `msrv` in the LintPass
424+
The project's MSRV can then be matched against the feature MSRV in the LintPass
419425
using the `meets_msrv` utility function.
420426

421427
``` rust
422-
if !meets_msrv(self.msrv.as_ref(), &MANUAL_STRIP_MSRV) {
428+
if !meets_msrv(self.msrv.as_ref(), &msrvs::STR_STRIP_PREFIX) {
423429
return;
424430
}
425431
```

0 commit comments

Comments
 (0)