11use std:: cmp;
22
33use crate :: ich:: StableHashingContext ;
4+ use crate :: lint;
45use crate :: lint:: context:: { CheckLintNameResult , LintStore } ;
5- use crate :: lint:: { self , LintSource } ;
66use rustc_data_structures:: fx:: FxHashMap ;
77use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
88use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
@@ -11,13 +11,30 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
1111use rustc_session:: Session ;
1212use rustc_span:: source_map:: MultiSpan ;
1313use rustc_span:: symbol:: { sym, Symbol } ;
14+ use rustc_span:: Span ;
1415use syntax:: ast;
1516use syntax:: attr;
1617use syntax:: print:: pprust;
1718use syntax:: sess:: feature_err;
1819
1920use rustc_error_codes:: * ;
2021
22+ /// How a lint level was set.
23+ #[ derive( Clone , Copy , PartialEq , Eq , HashStable ) ]
24+ pub enum LintSource {
25+ /// Lint is at the default level as declared
26+ /// in rustc or a plugin.
27+ Default ,
28+
29+ /// Lint level was set by an attribute.
30+ Node ( Symbol , Span , Option < Symbol > /* RFC 2383 reason */ ) ,
31+
32+ /// Lint level was set by a command-line flag.
33+ CommandLine ( Symbol ) ,
34+ }
35+
36+ pub type LevelSource = ( Level , LintSource ) ;
37+
2138pub struct LintLevelSets {
2239 list : Vec < LintSet > ,
2340 lint_cap : Level ,
@@ -27,27 +44,27 @@ enum LintSet {
2744 CommandLine {
2845 // -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
2946 // flag.
30- specs : FxHashMap < LintId , ( Level , LintSource ) > ,
47+ specs : FxHashMap < LintId , LevelSource > ,
3148 } ,
3249
3350 Node {
34- specs : FxHashMap < LintId , ( Level , LintSource ) > ,
51+ specs : FxHashMap < LintId , LevelSource > ,
3552 parent : u32 ,
3653 } ,
3754}
3855
3956impl LintLevelSets {
40- fn new ( ) -> Self {
57+ pub fn new ( ) -> Self {
4158 LintLevelSets { list : Vec :: new ( ) , lint_cap : Level :: Forbid }
4259 }
4360
44- fn get_lint_level (
61+ pub fn get_lint_level (
4562 & self ,
4663 lint : & ' static Lint ,
4764 idx : u32 ,
48- aux : Option < & FxHashMap < LintId , ( Level , LintSource ) > > ,
65+ aux : Option < & FxHashMap < LintId , LevelSource > > ,
4966 sess : & Session ,
50- ) -> ( Level , LintSource ) {
67+ ) -> LevelSource {
5168 let ( level, mut src) = self . get_lint_id_level ( LintId :: of ( lint) , idx, aux) ;
5269
5370 // If `level` is none then we actually assume the default level for this
@@ -59,7 +76,7 @@ impl LintLevelSets {
5976 // `allow(warnings)` in scope then we want to respect that instead.
6077 if level == Level :: Warn {
6178 let ( warnings_level, warnings_src) =
62- self . get_lint_id_level ( LintId :: of ( lint :: builtin:: WARNINGS ) , idx, aux) ;
79+ self . get_lint_id_level ( LintId :: of ( builtin:: WARNINGS ) , idx, aux) ;
6380 if let Some ( configured_warning_level) = warnings_level {
6481 if configured_warning_level != Level :: Warn {
6582 level = configured_warning_level;
@@ -79,11 +96,11 @@ impl LintLevelSets {
7996 return ( level, src) ;
8097 }
8198
82- fn get_lint_id_level (
99+ pub fn get_lint_id_level (
83100 & self ,
84101 id : LintId ,
85102 mut idx : u32 ,
86- aux : Option < & FxHashMap < LintId , ( Level , LintSource ) > > ,
103+ aux : Option < & FxHashMap < LintId , LevelSource > > ,
87104 ) -> ( Option < Level > , LintSource ) {
88105 if let Some ( specs) = aux {
89106 if let Some ( & ( level, src) ) = specs. get ( & id) {
@@ -499,7 +516,7 @@ impl LintLevelMap {
499516 lint : & ' static Lint ,
500517 id : HirId ,
501518 session : & Session ,
502- ) -> Option < ( Level , LintSource ) > {
519+ ) -> Option < LevelSource > {
503520 self . id_to_set . get ( & id) . map ( |idx| self . sets . get_lint_level ( lint, * idx, None , session) )
504521 }
505522}
0 commit comments