@@ -256,6 +256,7 @@ pub struct LintGroup {
256
256
pub feature_gate : Option < & ' static Feature > ,
257
257
}
258
258
259
+ /// This lint group is only to be used for testing purposes
259
260
const TEST_DUMMY_UNSTABLE : LintGroup = LintGroup {
260
261
name : "test_dummy_unstable" ,
261
262
desc : "test_dummy_unstable is meant to only be used in tests" ,
@@ -272,6 +273,10 @@ pub struct Lint {
272
273
pub default_level : LintLevel ,
273
274
pub edition_lint_opts : Option < ( Edition , LintLevel ) > ,
274
275
pub feature_gate : Option < & ' static Feature > ,
276
+ /// This is a markdown formatted string that will be used when generating
277
+ /// the lint documentation. If docs is `None`, the lint will not be
278
+ /// documented.
279
+ pub docs : Option < & ' static str > ,
275
280
}
276
281
277
282
impl Lint {
@@ -420,13 +425,15 @@ fn level_priority(
420
425
}
421
426
}
422
427
428
+ /// This lint is only to be used for testing purposes
423
429
const IM_A_TEAPOT : Lint = Lint {
424
430
name : "im_a_teapot" ,
425
431
desc : "`im_a_teapot` is specified" ,
426
432
groups : & [ TEST_DUMMY_UNSTABLE ] ,
427
433
default_level : LintLevel :: Allow ,
428
434
edition_lint_opts : None ,
429
435
feature_gate : Some ( Feature :: test_dummy_unstable ( ) ) ,
436
+ docs : None ,
430
437
} ;
431
438
432
439
pub fn check_im_a_teapot (
@@ -476,26 +483,55 @@ pub fn check_im_a_teapot(
476
483
Ok ( ( ) )
477
484
}
478
485
479
- /// By default, cargo will treat any optional dependency as a [feature]. As of
480
- /// cargo 1.60, these can be disabled by declaring a feature that activates the
481
- /// optional dependency as `dep:<name>` (see [RFC #3143]).
482
- ///
483
- /// In the 2024 edition, `cargo` will stop exposing optional dependencies as
484
- /// features implicitly, requiring users to add `foo = ["dep:foo"]` if they
485
- /// still want it exposed.
486
- ///
487
- /// For more information, see [RFC #3491]
488
- ///
489
- /// [feature]: https://doc.rust-lang.org/cargo/reference/features.html
490
- /// [RFC #3143]: https://rust-lang.github.io/rfcs/3143-cargo-weak-namespaced-features.html
491
- /// [RFC #3491]: https://rust-lang.github.io/rfcs/3491-remove-implicit-features.html
492
486
const IMPLICIT_FEATURES : Lint = Lint {
493
487
name : "implicit_features" ,
494
488
desc : "implicit features for optional dependencies is deprecated and will be unavailable in the 2024 edition" ,
495
489
groups : & [ ] ,
496
490
default_level : LintLevel :: Allow ,
497
491
edition_lint_opts : None ,
498
492
feature_gate : None ,
493
+ docs : Some ( r#"
494
+ ### What it does
495
+ Checks for implicit features for optional dependencies
496
+
497
+ ### Why it is bad
498
+ By default, cargo will treat any optional dependency as a [feature]. As of
499
+ cargo 1.60, these can be disabled by declaring a feature that activates the
500
+ optional dependency as `dep:<name>` (see [RFC #3143]).
501
+
502
+ In the 2024 edition, `cargo` will stop exposing optional dependencies as
503
+ features implicitly, requiring users to add `foo = ["dep:foo"]` if they
504
+ still want it exposed.
505
+
506
+ For more information, see [RFC #3491]
507
+
508
+ ### Example
509
+ ```toml
510
+ edition = "2021"
511
+
512
+ [dependencies]
513
+ bar = { version = "0.1.0", optional = true }
514
+
515
+ [features]
516
+ # No explicit feature activation for `bar`
517
+ ```
518
+
519
+ Instead, the dependency should have an explicit feature:
520
+ ```toml
521
+ edition = "2021"
522
+
523
+ [dependencies]
524
+ bar = { version = "0.1.0", optional = true }
525
+
526
+ [features]
527
+ bar = ["dep:bar"]
528
+ ```
529
+
530
+ [feature]: https://doc.rust-lang.org/cargo/reference/features.html
531
+ [RFC #3143]: https://rust-lang.github.io/rfcs/3143-cargo-weak-namespaced-features.html
532
+ [RFC #3491]: https://rust-lang.github.io/rfcs/3491-remove-implicit-features.html
533
+ "#
534
+ ) ,
499
535
} ;
500
536
501
537
pub fn check_implicit_features (
@@ -575,6 +611,24 @@ const UNKNOWN_LINTS: Lint = Lint {
575
611
default_level : LintLevel :: Warn ,
576
612
edition_lint_opts : None ,
577
613
feature_gate : None ,
614
+ docs : Some (
615
+ r#"
616
+ ### What it does
617
+ Checks for unknown lints in the `[lints.cargo]` table
618
+
619
+ ### Why it is bad
620
+ - The lint name could be misspelled, leading to confusion as to why it is
621
+ not working as expected
622
+ - The unknown lint could end up causing an error if `cargo` decides to make
623
+ a lint with the same name in the future
624
+
625
+ ### Example
626
+ ```toml
627
+ [lints.cargo]
628
+ this-lint-does-not-exist = "warn"
629
+ ```
630
+ "# ,
631
+ ) ,
578
632
} ;
579
633
580
634
fn output_unknown_lints (
@@ -684,6 +738,43 @@ const UNUSED_OPTIONAL_DEPENDENCY: Lint = Lint {
684
738
default_level : LintLevel :: Warn ,
685
739
edition_lint_opts : None ,
686
740
feature_gate : None ,
741
+ docs : Some (
742
+ r#"
743
+ ### What it does
744
+ Checks for optional dependencies that are not activated by any feature
745
+
746
+ ### Why it is bad
747
+ Starting in the 2024 edition, `cargo` no longer implicitly creates features
748
+ for optional dependencies (see [RFC #3491]). This means that any optional
749
+ dependency not specified with `"dep:<name>"` in some feature is now unused.
750
+ This change may be surprising to users who have been using the implicit
751
+ features `cargo` has been creating for optional dependencies.
752
+
753
+ ### Example
754
+ ```toml
755
+ edition = "2024"
756
+
757
+ [dependencies]
758
+ bar = { version = "0.1.0", optional = true }
759
+
760
+ [features]
761
+ # No explicit feature activation for `bar`
762
+ ```
763
+
764
+ Instead, the dependency should be removed or activated in a feature:
765
+ ```toml
766
+ edition = "2024"
767
+
768
+ [dependencies]
769
+ bar = { version = "0.1.0", optional = true }
770
+
771
+ [features]
772
+ bar = ["dep:bar"]
773
+ ```
774
+
775
+ [RFC #3491]: https://rust-lang.github.io/rfcs/3491-remove-implicit-features.html
776
+ "# ,
777
+ ) ,
687
778
} ;
688
779
689
780
pub fn unused_dependencies (
0 commit comments