11use std:: cmp;
22
33use crate :: ich:: StableHashingContext ;
4- use rustc_data_structures:: fx:: FxHashMap ;
4+ use chalk_ir:: Substitution ;
5+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
56use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
67use rustc_errors:: { DiagnosticBuilder , DiagnosticId } ;
78use rustc_hir:: HirId ;
@@ -28,6 +29,9 @@ pub enum LintLevelSource {
2829 /// The provided `Level` is the level specified on the command line.
2930 /// (The actual level may be lower due to `--cap-lints`.)
3031 CommandLine ( Symbol , Level ) ,
32+
33+ /// Lint is being forced to warn no matter what.
34+ ForceWarn ( Symbol ) ,
3135}
3236
3337impl LintLevelSource {
@@ -36,6 +40,7 @@ impl LintLevelSource {
3640 LintLevelSource :: Default => symbol:: kw:: Default ,
3741 LintLevelSource :: Node ( name, _, _) => name,
3842 LintLevelSource :: CommandLine ( name, _) => name,
43+ LintLevelSource :: ForceWarn ( name) => name,
3944 }
4045 }
4146
@@ -44,6 +49,7 @@ impl LintLevelSource {
4449 LintLevelSource :: Default => DUMMY_SP ,
4550 LintLevelSource :: Node ( _, span, _) => span,
4651 LintLevelSource :: CommandLine ( _, _) => DUMMY_SP ,
52+ LintLevelSource :: ForceWarn ( _) => DUMMY_SP ,
4753 }
4854 }
4955}
@@ -55,6 +61,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
5561pub struct LintLevelSets {
5662 pub list : Vec < LintSet > ,
5763 pub lint_cap : Level ,
64+ pub force_warns : FxHashSet < String > ,
5865}
5966
6067#[ derive( Debug ) ]
@@ -73,7 +80,11 @@ pub enum LintSet {
7380
7481impl LintLevelSets {
7582 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+ }
7788 }
7889
7990 pub fn get_lint_level (
@@ -83,6 +94,11 @@ impl LintLevelSets {
8394 aux : Option < & FxHashMap < LintId , LevelAndSource > > ,
8495 sess : & Session ,
8596 ) -> 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+
86102 let ( level, mut src) = self . get_lint_id_level ( LintId :: of ( lint) , idx, aux) ;
87103
88104 // If `level` is none then we actually assume the default level for this
@@ -176,11 +192,11 @@ impl LintLevelMap {
176192impl < ' a > HashStable < StableHashingContext < ' a > > for LintLevelMap {
177193 #[ inline]
178194 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 ;
180196
181197 id_to_set. hash_stable ( hcx, hasher) ;
182198
183- let LintLevelSets { ref list, lint_cap } = * sets;
199+ let LintLevelSets { ref list, lint_cap, .. } = * sets;
184200
185201 lint_cap. hash_stable ( hcx, hasher) ;
186202
@@ -346,6 +362,13 @@ pub fn struct_lint_level<'s, 'd>(
346362 ) ;
347363 }
348364 }
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+ }
349372 }
350373
351374 err. code ( DiagnosticId :: Lint { name, has_future_breakage } ) ;
0 commit comments