1
1
use std:: cmp;
2
2
3
3
use crate :: ich:: StableHashingContext ;
4
- use rustc_data_structures:: fx:: FxHashMap ;
4
+ use chalk_ir:: Substitution ;
5
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5
6
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
6
7
use rustc_errors:: { DiagnosticBuilder , DiagnosticId } ;
7
8
use rustc_hir:: HirId ;
@@ -28,6 +29,9 @@ pub enum LintLevelSource {
28
29
/// The provided `Level` is the level specified on the command line.
29
30
/// (The actual level may be lower due to `--cap-lints`.)
30
31
CommandLine ( Symbol , Level ) ,
32
+
33
+ /// Lint is being forced to warn no matter what.
34
+ ForceWarn ( Symbol ) ,
31
35
}
32
36
33
37
impl LintLevelSource {
@@ -36,6 +40,7 @@ impl LintLevelSource {
36
40
LintLevelSource :: Default => symbol:: kw:: Default ,
37
41
LintLevelSource :: Node ( name, _, _) => name,
38
42
LintLevelSource :: CommandLine ( name, _) => name,
43
+ LintLevelSource :: ForceWarn ( name) => name,
39
44
}
40
45
}
41
46
@@ -44,6 +49,7 @@ impl LintLevelSource {
44
49
LintLevelSource :: Default => DUMMY_SP ,
45
50
LintLevelSource :: Node ( _, span, _) => span,
46
51
LintLevelSource :: CommandLine ( _, _) => DUMMY_SP ,
52
+ LintLevelSource :: ForceWarn ( _) => DUMMY_SP ,
47
53
}
48
54
}
49
55
}
@@ -55,6 +61,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
55
61
pub struct LintLevelSets {
56
62
pub list : Vec < LintSet > ,
57
63
pub lint_cap : Level ,
64
+ pub force_warns : FxHashSet < String > ,
58
65
}
59
66
60
67
#[ derive( Debug ) ]
@@ -73,7 +80,11 @@ pub enum LintSet {
73
80
74
81
impl LintLevelSets {
75
82
pub fn new ( ) -> Self {
76
- LintLevelSets { list : Vec :: new ( ) , lint_cap : Level :: Forbid }
83
+ LintLevelSets {
84
+ list : Vec :: new ( ) ,
85
+ lint_cap : Level :: Forbid ,
86
+ force_warns : FxHashSet :: default ( ) ,
87
+ }
77
88
}
78
89
79
90
pub fn get_lint_level (
@@ -83,6 +94,11 @@ impl LintLevelSets {
83
94
aux : Option < & FxHashMap < LintId , LevelAndSource > > ,
84
95
sess : & Session ,
85
96
) -> LevelAndSource {
97
+ // Check whether we should always warn
98
+ if self . force_warns . contains ( lint. name ) {
99
+ return ( Level :: Warn , LintLevelSource :: ForceWarn ( Symbol :: intern ( lint. name ) ) ) ;
100
+ }
101
+
86
102
let ( level, mut src) = self . get_lint_id_level ( LintId :: of ( lint) , idx, aux) ;
87
103
88
104
// If `level` is none then we actually assume the default level for this
@@ -176,11 +192,11 @@ impl LintLevelMap {
176
192
impl < ' a > HashStable < StableHashingContext < ' a > > for LintLevelMap {
177
193
#[ inline]
178
194
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
179
- let LintLevelMap { ref sets, ref id_to_set } = * self ;
195
+ let LintLevelMap { ref sets, ref id_to_set, .. } = * self ;
180
196
181
197
id_to_set. hash_stable ( hcx, hasher) ;
182
198
183
- let LintLevelSets { ref list, lint_cap } = * sets;
199
+ let LintLevelSets { ref list, lint_cap, .. } = * sets;
184
200
185
201
lint_cap. hash_stable ( hcx, hasher) ;
186
202
@@ -346,6 +362,13 @@ pub fn struct_lint_level<'s, 'd>(
346
362
) ;
347
363
}
348
364
}
365
+ LintLevelSource :: ForceWarn ( _) => {
366
+ sess. diag_note_once (
367
+ & mut err,
368
+ DiagnosticMessageId :: from ( lint) ,
369
+ "Warning forced by `force-warns` commandline option" ,
370
+ ) ;
371
+ }
349
372
}
350
373
351
374
err. code ( DiagnosticId :: Lint { name, has_future_breakage } ) ;
0 commit comments