@@ -12,6 +12,7 @@ use std::ops::Range;
12
12
use std:: path:: Path ;
13
13
use toml_edit:: ImDocument ;
14
14
15
+ const LINT_GROUPS : & [ LintGroup ] = & [ TEST_DUMMY_UNSTABLE ] ;
15
16
const LINTS : & [ Lint ] = & [ IM_A_TEAPOT , IMPLICIT_FEATURES , UNUSED_OPTIONAL_DEPENDENCY ] ;
16
17
17
18
pub fn analyze_cargo_lints_table (
@@ -33,11 +34,13 @@ pub fn analyze_cargo_lints_table(
33
34
. keys ( )
34
35
. chain ( ws_lints. map ( |l| l. keys ( ) ) . unwrap_or_default ( ) )
35
36
{
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
+ {
37
40
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,
41
44
pkg_lints,
42
45
ws_lints,
43
46
manifest. edition ( ) ,
@@ -49,9 +52,9 @@ pub fn analyze_cargo_lints_table(
49
52
}
50
53
51
54
// 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 {
53
56
verify_feature_enabled (
54
- lint . name ,
57
+ name,
55
58
feature_gate,
56
59
reason,
57
60
manifest,
@@ -74,6 +77,33 @@ pub fn analyze_cargo_lints_table(
74
77
}
75
78
}
76
79
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
+
77
107
fn verify_feature_enabled (
78
108
lint_name : & str ,
79
109
feature_gate : & Feature ,
@@ -224,13 +254,15 @@ pub struct LintGroup {
224
254
pub default_level : LintLevel ,
225
255
pub desc : & ' static str ,
226
256
pub edition_lint_opts : Option < ( Edition , LintLevel ) > ,
257
+ pub feature_gate : Option < & ' static Feature > ,
227
258
}
228
259
229
260
const TEST_DUMMY_UNSTABLE : LintGroup = LintGroup {
230
261
name : "test_dummy_unstable" ,
231
262
desc : "test_dummy_unstable is meant to only be used in tests" ,
232
263
default_level : LintLevel :: Allow ,
233
264
edition_lint_opts : None ,
265
+ feature_gate : Some ( Feature :: test_dummy_unstable ( ) ) ,
234
266
} ;
235
267
236
268
#[ derive( Copy , Clone , Debug ) ]
0 commit comments