1
1
use crate :: core:: dependency:: DepKind ;
2
2
use crate :: core:: FeatureValue :: Dep ;
3
- use crate :: core:: { Edition , FeatureValue , Package } ;
3
+ use crate :: core:: { Edition , Feature , FeatureValue , Manifest , Package } ;
4
4
use crate :: util:: interning:: InternedString ;
5
5
use crate :: { CargoResult , GlobalContext } ;
6
6
use annotate_snippets:: { Level , Snippet } ;
@@ -13,10 +13,10 @@ use std::path::Path;
13
13
use toml_edit:: ImDocument ;
14
14
15
15
fn get_span ( document : & ImDocument < String > , path : & [ & str ] , get_value : bool ) -> Option < Range < usize > > {
16
- let mut table = document. as_item ( ) . as_table_like ( ) . unwrap ( ) ;
16
+ let mut table = document. as_item ( ) . as_table_like ( ) ? ;
17
17
let mut iter = path. into_iter ( ) . peekable ( ) ;
18
18
while let Some ( key) = iter. next ( ) {
19
- let ( key, item) = table. get_key_value ( key) . unwrap ( ) ;
19
+ let ( key, item) = table. get_key_value ( key) ? ;
20
20
if iter. peek ( ) . is_none ( ) {
21
21
return if get_value {
22
22
item. span ( )
@@ -82,6 +82,7 @@ pub struct Lint {
82
82
pub groups : & ' static [ LintGroup ] ,
83
83
pub default_level : LintLevel ,
84
84
pub edition_lint_opts : Option < ( Edition , LintLevel ) > ,
85
+ pub feature_gate : Option < & ' static Feature > ,
85
86
}
86
87
87
88
impl Lint {
@@ -121,6 +122,12 @@ impl Lint {
121
122
. map ( |( _, ( l, r, _) ) | ( l, r) )
122
123
. unwrap ( )
123
124
}
125
+
126
+ /// Returns true if the lint is feature gated and the feature is not enabled
127
+ fn is_feature_gated ( & self , manifest : & Manifest ) -> bool {
128
+ self . feature_gate
129
+ . map_or ( false , |f| !manifest. unstable_features ( ) . is_enabled ( f) )
130
+ }
124
131
}
125
132
126
133
#[ derive( Copy , Clone , Debug , PartialEq ) ]
@@ -164,7 +171,7 @@ impl From<TomlLintLevel> for LintLevel {
164
171
}
165
172
}
166
173
167
- #[ derive( Copy , Clone , Debug ) ]
174
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
168
175
pub enum LintLevelReason {
169
176
Default ,
170
177
Edition ( Edition ) ,
@@ -228,6 +235,7 @@ const IM_A_TEAPOT: Lint = Lint {
228
235
groups : & [ TEST_DUMMY_UNSTABLE ] ,
229
236
default_level : LintLevel :: Allow ,
230
237
edition_lint_opts : None ,
238
+ feature_gate : Some ( Feature :: test_dummy_unstable ( ) ) ,
231
239
} ;
232
240
233
241
pub fn check_im_a_teapot (
@@ -240,6 +248,11 @@ pub fn check_im_a_teapot(
240
248
) -> CargoResult < ( ) > {
241
249
let manifest = pkg. manifest ( ) ;
242
250
let ( lint_level, reason) = IM_A_TEAPOT . level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
251
+
252
+ if IM_A_TEAPOT . is_feature_gated ( manifest) {
253
+ return Ok ( ( ) ) ;
254
+ }
255
+
243
256
if lint_level == LintLevel :: Allow {
244
257
return Ok ( ( ) ) ;
245
258
}
@@ -295,6 +308,7 @@ const IMPLICIT_FEATURES: Lint = Lint {
295
308
groups : & [ ] ,
296
309
default_level : LintLevel :: Allow ,
297
310
edition_lint_opts : None ,
311
+ feature_gate : None ,
298
312
} ;
299
313
300
314
pub fn check_implicit_features (
@@ -373,6 +387,7 @@ const UNUSED_OPTIONAL_DEPENDENCY: Lint = Lint {
373
387
groups : & [ ] ,
374
388
default_level : LintLevel :: Warn ,
375
389
edition_lint_opts : None ,
390
+ feature_gate : None ,
376
391
} ;
377
392
378
393
pub fn unused_dependencies (
0 commit comments