@@ -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,18 +34,27 @@ 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
- let ( _, reason) = lint. level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
37
+ if let Some ( ( name, default_level, edition_lint_opts, feature_gate) ) =
38
+ find_lint_or_group ( lint_name)
39
+ {
40
+ let ( _, reason, _) = level_priority (
41
+ name,
42
+ * default_level,
43
+ * edition_lint_opts,
44
+ pkg_lints,
45
+ ws_lints,
46
+ manifest. edition ( ) ,
47
+ ) ;
38
48
39
49
// Only run analysis on user-specified lints
40
50
if !reason. is_user_specified ( ) {
41
51
continue ;
42
52
}
43
53
44
54
// Only run this on lints that are gated by a feature
45
- if let Some ( feature_gate) = lint . feature_gate {
55
+ if let Some ( feature_gate) = feature_gate {
46
56
verify_feature_enabled (
47
- lint . name ,
57
+ name,
48
58
feature_gate,
49
59
reason,
50
60
manifest,
@@ -67,6 +77,33 @@ pub fn analyze_cargo_lints_table(
67
77
}
68
78
}
69
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
+
70
107
fn verify_feature_enabled (
71
108
lint_name : & str ,
72
109
feature_gate : & Feature ,
@@ -217,13 +254,15 @@ pub struct LintGroup {
217
254
pub default_level : LintLevel ,
218
255
pub desc : & ' static str ,
219
256
pub edition_lint_opts : Option < ( Edition , LintLevel ) > ,
257
+ pub feature_gate : Option < & ' static Feature > ,
220
258
}
221
259
222
260
const TEST_DUMMY_UNSTABLE : LintGroup = LintGroup {
223
261
name : "test_dummy_unstable" ,
224
262
desc : "test_dummy_unstable is meant to only be used in tests" ,
225
263
default_level : LintLevel :: Allow ,
226
264
edition_lint_opts : None ,
265
+ feature_gate : Some ( Feature :: test_dummy_unstable ( ) ) ,
227
266
} ;
228
267
229
268
#[ derive( Copy , Clone , Debug ) ]
0 commit comments