@@ -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 verify_lints (
@@ -29,20 +30,41 @@ pub fn verify_lints(
29
30
let manifest_path = rel_cwd_manifest_path ( path, gctx) ;
30
31
let ws_path = rel_cwd_manifest_path ( ws_path, gctx) ;
31
32
33
+ let iter = LINTS
34
+ . iter ( )
35
+ . map ( |l| ( l. name , l. default_level , l. edition_lint_opts , l. feature_gate ) )
36
+ . chain (
37
+ LINT_GROUPS
38
+ . iter ( )
39
+ . map ( |g| ( g. name , g. default_level , g. edition_lint_opts , g. feature_gate ) ) ,
40
+ )
41
+ . collect :: < Vec < _ > > ( ) ;
32
42
for lint_name in pkg_lints. keys ( ) . chain ( ws_lints. keys ( ) ) {
33
- if let Some ( lint) = LINTS . iter ( ) . find ( |l| l. name == lint_name) {
34
- let ( _, reason) = lint. level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
35
- feature_gated_lint (
36
- lint,
37
- reason,
38
- manifest,
39
- & manifest_path,
40
- ws_contents,
41
- ws_document,
42
- & ws_path,
43
- & mut error_count,
44
- gctx,
45
- ) ?;
43
+ if let Some ( ( name, default_level, edition_lint_opts, feature_gate) ) =
44
+ iter. iter ( ) . find ( |( n, _, _, _) | n == & lint_name)
45
+ {
46
+ let ( _, reason, _) = level_priority (
47
+ name,
48
+ * default_level,
49
+ * edition_lint_opts,
50
+ pkg_lints,
51
+ ws_lints,
52
+ manifest. edition ( ) ,
53
+ ) ;
54
+ if let Some ( feature_gate) = feature_gate {
55
+ feature_gated_lint (
56
+ name,
57
+ feature_gate,
58
+ reason,
59
+ manifest,
60
+ & manifest_path,
61
+ ws_contents,
62
+ ws_document,
63
+ & ws_path,
64
+ & mut error_count,
65
+ gctx,
66
+ ) ?;
67
+ }
46
68
}
47
69
}
48
70
if error_count > 0 {
@@ -55,7 +77,8 @@ pub fn verify_lints(
55
77
}
56
78
57
79
fn feature_gated_lint (
58
- lint : & Lint ,
80
+ lint_name : & str ,
81
+ feature_gate : & Feature ,
59
82
reason : LintLevelReason ,
60
83
manifest : & Manifest ,
61
84
manifest_path : & str ,
@@ -65,14 +88,11 @@ fn feature_gated_lint(
65
88
error_count : & mut usize ,
66
89
gctx : & GlobalContext ,
67
90
) -> CargoResult < ( ) > {
68
- if lint
69
- . feature_gate
70
- . map_or ( false , |f| !manifest. unstable_features ( ) . is_enabled ( f) )
71
- {
72
- let dash_name = lint. name . replace ( "_" , "-" ) ;
91
+ if !manifest. unstable_features ( ) . is_enabled ( feature_gate) {
92
+ let dash_name = lint_name. replace ( "_" , "-" ) ;
73
93
let title = "verification of lint failed" ;
74
94
let label = "use of unstable lint that has not been enabled" ;
75
- let second_title = format ! ( "`cargo::{}` was inherited" , lint . name ) ;
95
+ let second_title = format ! ( "`cargo::{}` was inherited" , lint_name ) ;
76
96
let message = match reason {
77
97
LintLevelReason :: Package => {
78
98
let span = get_span (
@@ -82,7 +102,7 @@ fn feature_gated_lint(
82
102
)
83
103
. or ( get_span (
84
104
manifest. document ( ) ,
85
- & [ "lints" , "cargo" , lint . name ] ,
105
+ & [ "lints" , "cargo" , lint_name ] ,
86
106
false ,
87
107
) )
88
108
. unwrap ( ) ;
@@ -103,7 +123,7 @@ fn feature_gated_lint(
103
123
)
104
124
. or ( get_span (
105
125
ws_document,
106
- & [ "workspace" , "lints" , "cargo" , lint . name ] ,
126
+ & [ "workspace" , "lints" , "cargo" , lint_name ] ,
107
127
false ,
108
128
) )
109
129
. unwrap ( ) ;
0 commit comments