@@ -12,6 +12,7 @@ use std::ops::Range;
1212use std:: path:: Path ;
1313use toml_edit:: ImDocument ;
1414
15+ const LINT_GROUPS : & [ LintGroup ] = & [ TEST_DUMMY_UNSTABLE ] ;
1516const LINTS : & [ Lint ] = & [ IM_A_TEAPOT , IMPLICIT_FEATURES , UNUSED_OPTIONAL_DEPENDENCY ] ;
1617
1718pub fn analyze_cargo_lints_table (
@@ -33,11 +34,13 @@ pub fn analyze_cargo_lints_table(
3334 . keys ( )
3435 . chain ( ws_lints. map ( |l| l. keys ( ) ) . unwrap_or_default ( ) )
3536 {
36- if let Some ( lint) = LINTS . iter ( ) . find ( |l| l. name == lint_name) {
37+ if let Some ( ( name, default_level, edition_lint_opts, feature_gate) ) =
38+ find_lint_or_group ( lint_name)
39+ {
3740 let ( _, reason, _) = level_priority (
38- lint . name ,
39- lint . default_level ,
40- lint . edition_lint_opts ,
41+ name,
42+ * default_level,
43+ * edition_lint_opts,
4144 pkg_lints,
4245 ws_lints,
4346 manifest. edition ( ) ,
@@ -49,9 +52,9 @@ pub fn analyze_cargo_lints_table(
4952 }
5053
5154 // Only run this on lints that are gated by a feature
52- if let Some ( feature_gate) = lint . feature_gate {
55+ if let Some ( feature_gate) = feature_gate {
5356 verify_feature_enabled (
54- lint . name ,
57+ name,
5558 feature_gate,
5659 reason,
5760 manifest,
@@ -74,6 +77,33 @@ pub fn analyze_cargo_lints_table(
7477 }
7578}
7679
80+ fn find_lint_or_group < ' a > (
81+ name : & str ,
82+ ) -> Option < (
83+ & ' static str ,
84+ & LintLevel ,
85+ & Option < ( Edition , LintLevel ) > ,
86+ & Option < & ' static Feature > ,
87+ ) > {
88+ if let Some ( lint) = LINTS . iter ( ) . find ( |l| l. name == name) {
89+ Some ( (
90+ lint. name ,
91+ & lint. default_level ,
92+ & lint. edition_lint_opts ,
93+ & lint. feature_gate ,
94+ ) )
95+ } else if let Some ( group) = LINT_GROUPS . iter ( ) . find ( |g| g. name == name) {
96+ Some ( (
97+ group. name ,
98+ & group. default_level ,
99+ & group. edition_lint_opts ,
100+ & group. feature_gate ,
101+ ) )
102+ } else {
103+ None
104+ }
105+ }
106+
77107fn verify_feature_enabled (
78108 lint_name : & str ,
79109 feature_gate : & Feature ,
@@ -224,13 +254,15 @@ pub struct LintGroup {
224254 pub default_level : LintLevel ,
225255 pub desc : & ' static str ,
226256 pub edition_lint_opts : Option < ( Edition , LintLevel ) > ,
257+ pub feature_gate : Option < & ' static Feature > ,
227258}
228259
229260const TEST_DUMMY_UNSTABLE : LintGroup = LintGroup {
230261 name : "test_dummy_unstable" ,
231262 desc : "test_dummy_unstable is meant to only be used in tests" ,
232263 default_level : LintLevel :: Allow ,
233264 edition_lint_opts : None ,
265+ feature_gate : Some ( Feature :: test_dummy_unstable ( ) ) ,
234266} ;
235267
236268#[ derive( Copy , Clone , Debug ) ]
0 commit comments