@@ -226,13 +226,13 @@ store.register_early_pass(|| box foo_functions::FooFunctions);
226
226
```
227
227
228
228
As one may expect, there is a corresponding ` register_late_pass ` method
229
- available as well. Without a call to one of ` register_early_pass ` or
229
+ available as well. Without a call to one of ` register_early_pass ` or
230
230
` register_late_pass ` , the lint pass in question will not be run.
231
231
232
- One reason that ` cargo dev ` does not automate this step is that multiple lints
232
+ One reason that ` cargo dev ` does not automate this step is that multiple lints
233
233
can use the same lint pass, so registering the lint pass may already be done
234
234
when adding a new lint. Another reason that this step is not automated is that
235
- the order that the passes are registered determines the order the passes
235
+ the order that the passes are registered determines the order the passes
236
236
actually run, which in turn affects the order that any emitted lints are output
237
237
in.
238
238
@@ -380,6 +380,57 @@ pass.
380
380
[ `FnKind::Fn` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/visit/enum.FnKind.html#variant.Fn
381
381
[ ident ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Ident.html
382
382
383
+ ## Specifying the lint's minimum supported Rust version (msrv)
384
+
385
+ Projects supporting older versions of Rust would need to disable a lint if it targets features
386
+ present in later versions. Support for this can be added by specifying an msrv in your lint like so,
387
+
388
+ ``` rust
389
+ const MANUAL_STRIP_MSRV : RustcVersion = RustcVersion :: new (1 , 45 , 0 );
390
+ ```
391
+
392
+ The project's msrv will also have to be an attribute in the lint so you'll have to add a struct
393
+ and constructor for your lint. The project's msrv needs to be passed when the lint is registered
394
+ in ` lib.rs `
395
+
396
+ ``` rust
397
+ pub struct ManualStrip {
398
+ msrv : Option <RustcVersion >,
399
+ }
400
+
401
+ impl ManualStrip {
402
+ #[must_use]
403
+ pub fn new (msrv : Option <RustcVersion >) -> Self {
404
+ Self { msrv }
405
+ }
406
+ }
407
+ ```
408
+
409
+ The project's msrv can then be matched against the lint's msrv in the LintPass using the ` meets_msrv ` utility
410
+ function.
411
+
412
+ ``` rust
413
+ if ! meets_msrv (self . msrv. as_ref (), & MANUAL_STRIP_MSRV ) {
414
+ return ;
415
+ }
416
+ ```
417
+
418
+ The project's msrv can also be specified as an inner attribute, which overrides the value from
419
+ ` clippy.toml ` . This can be accounted for using the ` extract_msrv_attr!(LintContext) ` macro and passing
420
+ LateContext/EarlyContext.
421
+
422
+ ``` rust
423
+ impl <'tcx > LateLintPass <'tcx > for ManualStrip {
424
+ fn check_expr (& mut self , cx : & LateContext <'tcx >, expr : & 'tcx Expr <'_ >) {
425
+ ...
426
+ }
427
+ extract_msrv_attr! (LateContext );
428
+ }
429
+ ```
430
+
431
+ Once the msrv is added to the lint, a relevant test case should be added to ` tests/ui/min_rust_version_attr.rs `
432
+ which verifies that the lint isn't emitted if the project's msrv is lower.
433
+
383
434
## Author lint
384
435
385
436
If you have trouble implementing your lint, there is also the internal ` author `
0 commit comments