@@ -388,18 +388,19 @@ pass.
388
388
[ `FnKind::Fn` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/visit/enum.FnKind.html#variant.Fn
389
389
[ ident ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Ident.html
390
390
391
- ## Specifying the lint's minimum supported Rust version (msrv )
391
+ ## Specifying the lint's minimum supported Rust version (MSRV )
392
392
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,
395
396
396
397
``` rust
397
398
const MANUAL_STRIP_MSRV : RustcVersion = RustcVersion :: new (1 , 45 , 0 );
398
399
```
399
400
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 `
403
404
404
405
``` rust
405
406
pub struct ManualStrip {
@@ -414,18 +415,19 @@ impl ManualStrip {
414
415
}
415
416
```
416
417
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.
419
420
420
421
``` rust
421
422
if ! meets_msrv (self . msrv. as_ref (), & MANUAL_STRIP_MSRV ) {
422
423
return ;
423
424
}
424
425
```
425
426
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 ` .
429
431
430
432
``` rust
431
433
impl <'tcx > LateLintPass <'tcx > for ManualStrip {
@@ -436,8 +438,20 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
436
438
}
437
439
```
438
440
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
+ ```
441
455
442
456
## Author lint
443
457
@@ -533,9 +547,9 @@ Before submitting your PR make sure you followed all of the basic requirements:
533
547
534
548
## Adding configuration to a lint
535
549
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
537
551
directory. 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
539
553
in the following steps:
540
554
541
555
1 . Adding a new configuration entry to [ clippy_utils::conf] ( /clippy_utils/src/conf.rs )
@@ -544,10 +558,10 @@ in the following steps:
544
558
/// Lint: LINT_NAME. <The configuration field doc comment>
545
559
(configuration_ident , " configuration_value" : Type , DefaultValue ),
546
560
```
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
548
562
automatically added to the lint documentation .
549
563
2 . 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
551
565
generated with the `declare_lint_pass! ` macro . This struct needs to be defined manually
552
566
to add some kind of metadata to it :
553
567
```rust
@@ -564,7 +578,7 @@ in the following steps:
564
578
LINT_NAME
565
579
]);
566
580
```
567
-
581
+
568
582
2 . Next add the configuration value and a corresponding creation method like this :
569
583
```rust
570
584
#[derive(Copy , Clone )]
@@ -584,7 +598,7 @@ in the following steps:
584
598
```
585
599
3 . Passing the configuration value to the lint impl struct :
586
600
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).
588
602
The configuration value is now cloned or copied into a local value that is then passed to the
589
603
impl struct like this :
590
604
```rust
@@ -601,9 +615,9 @@ in the following steps:
601
615
602
616
4 . Adding tests :
603
617
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
607
621
otherwise be written as usual .
608
622
609
623
## Cheatsheet
0 commit comments