Skip to content

Commit 6dd5331

Browse files
committed
Improve doc on how to add MSRV to a lint
1 parent f029a80 commit 6dd5331

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

doc/adding_lints.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,19 @@ pass.
388388
[`FnKind::Fn`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/visit/enum.FnKind.html#variant.Fn
389389
[ident]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Ident.html
390390

391-
## Specifying the lint's minimum supported Rust version (msrv)
391+
## 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 targets features
394-
present in later versions. Support for this can be added by specifying an msrv in your lint like so,
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,
395396

396397
```rust
397398
const MANUAL_STRIP_MSRV: RustcVersion = RustcVersion::new(1, 45, 0);
398399
```
399400

400-
The project's msrv will also have to be an attribute in the lint so you'll have to add a struct
401-
and constructor for your lint. The project's msrv needs to be passed when the lint is registered
402-
in `lib.rs`
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`
403404

404405
```rust
405406
pub struct ManualStrip {
@@ -414,18 +415,19 @@ impl ManualStrip {
414415
}
415416
```
416417

417-
The project's msrv can then be matched against the lint's msrv in the LintPass using the `meets_msrv` utility
418-
function.
418+
The project's MSRV can then be matched against the lint's `msrv` in the LintPass
419+
using the `meets_msrv` utility function.
419420

420421
``` rust
421422
if !meets_msrv(self.msrv.as_ref(), &MANUAL_STRIP_MSRV) {
422423
return;
423424
}
424425
```
425426

426-
The project's msrv can also be specified as an inner attribute, which overrides the value from
427-
`clippy.toml`. This can be accounted for using the `extract_msrv_attr!(LintContext)` macro and passing
428-
LateContext/EarlyContext.
427+
The project's MSRV can also be specified as an inner attribute, which overrides
428+
the value from `clippy.toml`. This can be accounted for using the
429+
`extract_msrv_attr!(LintContext)` macro and passing
430+
`LateContext`/`EarlyContext`.
429431

430432
```rust
431433
impl<'tcx> LateLintPass<'tcx> for ManualStrip {
@@ -436,8 +438,20 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
436438
}
437439
```
438440

439-
Once the msrv is added to the lint, a relevant test case should be added to `tests/ui/min_rust_version_attr.rs`
440-
which verifies that the lint isn't emitted if the project's msrv is lower.
441+
Once the `msrv` is added to the lint, a relevant test case should be added to
442+
`tests/ui/min_rust_version_attr.rs` which verifies that the lint isn't emitted
443+
if the project's MSRV is lower.
444+
445+
As a last step, the lint should be added to the lint documentation. This is done
446+
in `clippy_lints/src/utils/conf.rs`:
447+
448+
```rust
449+
define_Conf! {
450+
/// Lint: LIST, OF, LINTS, <THE_NEWLY_ADDED_LINT>. The minimum rust version that the project supports
451+
(msrv, "msrv": Option<String>, None),
452+
...
453+
}
454+
```
441455

442456
## Author lint
443457

0 commit comments

Comments
 (0)