@@ -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
397398const 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
405406pub 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
421422if ! 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
431433impl <'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
@@ -533,9 +547,9 @@ Before submitting your PR make sure you followed all of the basic requirements:
533547
534548## Adding configuration to a lint
535549
536- Clippy supports the configuration of lints values using a ` clippy.toml ` file in the workspace
550+ Clippy supports the configuration of lints values using a ` clippy.toml ` file in the workspace
537551directory. Adding a configuration to a lint can be useful for thresholds or to constrain some
538- behavior that can be seen as a false positive for some users. Adding a configuration is done
552+ behavior that can be seen as a false positive for some users. Adding a configuration is done
539553in the following steps:
540554
5415551 . Adding a new configuration entry to [ clippy_utils::conf] ( /clippy_utils/src/conf.rs )
@@ -544,10 +558,10 @@ in the following steps:
544558 /// Lint: LINT_NAME. <The configuration field doc comment>
545559 (configuration_ident , " configuration_value" : Type , DefaultValue ),
546560 ```
547- The configuration value and identifier should usually be the same . The doc comment will be
561+ The configuration value and identifier should usually be the same . The doc comment will be
548562 automatically added to the lint documentation .
5495632 . Adding the configuration value to the lint impl struct :
550- 1 . This first requires the definition of a lint impl struct . Lint impl structs are usually
564+ 1 . This first requires the definition of a lint impl struct . Lint impl structs are usually
551565 generated with the `declare_lint_pass! ` macro . This struct needs to be defined manually
552566 to add some kind of metadata to it :
553567 ```rust
@@ -564,7 +578,7 @@ in the following steps:
564578 LINT_NAME
565579 ]);
566580 ```
567-
581+
568582 2 . Next add the configuration value and a corresponding creation method like this :
569583 ```rust
570584 #[derive(Copy , Clone )]
@@ -584,7 +598,7 @@ in the following steps:
584598 ```
5855993 . Passing the configuration value to the lint impl struct :
586600
587- First find the struct construction in the [clippy_lints lib file ](/ clippy_lints / src / lib . rs).
601+ First find the struct construction in the [clippy_lints lib file ](/ clippy_lints / src / lib . rs).
588602 The configuration value is now cloned or copied into a local value that is then passed to the
589603 impl struct like this :
590604 ```rust
@@ -601,9 +615,9 @@ in the following steps:
601615
6026164 . Adding tests :
603617 1 . The default configured value can be tested like any normal lint in [`tests / ui `](/ tests / ui ).
604- 2 . The configuration itself will be tested separately in [`tests / ui - toml `](/ tests / ui - toml ).
605- Simply add a new subfolder with a fitting name . This folder contains a `clippy . toml` file
606- with the configuration value and a rust file that should be linted by Clippy . The test can
618+ 2 . The configuration itself will be tested separately in [`tests / ui - toml `](/ tests / ui - toml ).
619+ Simply add a new subfolder with a fitting name . This folder contains a `clippy . toml` file
620+ with the configuration value and a rust file that should be linted by Clippy . The test can
607621 otherwise be written as usual .
608622
609623## Cheatsheet
0 commit comments