1
1
use std:: cmp;
2
2
3
3
use crate :: ich:: StableHashingContext ;
4
+ use crate :: lint;
4
5
use crate :: lint:: context:: { CheckLintNameResult , LintStore } ;
5
- use crate :: lint:: { self , LintSource } ;
6
6
use rustc_data_structures:: fx:: FxHashMap ;
7
7
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
8
8
use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
@@ -11,13 +11,30 @@ use rustc_session::lint::{builtin, Level, Lint, LintId};
11
11
use rustc_session:: Session ;
12
12
use rustc_span:: source_map:: MultiSpan ;
13
13
use rustc_span:: symbol:: { sym, Symbol } ;
14
+ use rustc_span:: Span ;
14
15
use syntax:: ast;
15
16
use syntax:: attr;
16
17
use syntax:: print:: pprust;
17
18
use syntax:: sess:: feature_err;
18
19
19
20
use rustc_error_codes:: * ;
20
21
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
+
21
38
pub struct LintLevelSets {
22
39
list : Vec < LintSet > ,
23
40
lint_cap : Level ,
@@ -27,27 +44,27 @@ enum LintSet {
27
44
CommandLine {
28
45
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
29
46
// flag.
30
- specs : FxHashMap < LintId , ( Level , LintSource ) > ,
47
+ specs : FxHashMap < LintId , LevelSource > ,
31
48
} ,
32
49
33
50
Node {
34
- specs : FxHashMap < LintId , ( Level , LintSource ) > ,
51
+ specs : FxHashMap < LintId , LevelSource > ,
35
52
parent : u32 ,
36
53
} ,
37
54
}
38
55
39
56
impl LintLevelSets {
40
- fn new ( ) -> Self {
57
+ pub fn new ( ) -> Self {
41
58
LintLevelSets { list : Vec :: new ( ) , lint_cap : Level :: Forbid }
42
59
}
43
60
44
- fn get_lint_level (
61
+ pub fn get_lint_level (
45
62
& self ,
46
63
lint : & ' static Lint ,
47
64
idx : u32 ,
48
- aux : Option < & FxHashMap < LintId , ( Level , LintSource ) > > ,
65
+ aux : Option < & FxHashMap < LintId , LevelSource > > ,
49
66
sess : & Session ,
50
- ) -> ( Level , LintSource ) {
67
+ ) -> LevelSource {
51
68
let ( level, mut src) = self . get_lint_id_level ( LintId :: of ( lint) , idx, aux) ;
52
69
53
70
// If `level` is none then we actually assume the default level for this
@@ -59,7 +76,7 @@ impl LintLevelSets {
59
76
// `allow(warnings)` in scope then we want to respect that instead.
60
77
if level == Level :: Warn {
61
78
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) ;
63
80
if let Some ( configured_warning_level) = warnings_level {
64
81
if configured_warning_level != Level :: Warn {
65
82
level = configured_warning_level;
@@ -79,11 +96,11 @@ impl LintLevelSets {
79
96
return ( level, src) ;
80
97
}
81
98
82
- fn get_lint_id_level (
99
+ pub fn get_lint_id_level (
83
100
& self ,
84
101
id : LintId ,
85
102
mut idx : u32 ,
86
- aux : Option < & FxHashMap < LintId , ( Level , LintSource ) > > ,
103
+ aux : Option < & FxHashMap < LintId , LevelSource > > ,
87
104
) -> ( Option < Level > , LintSource ) {
88
105
if let Some ( specs) = aux {
89
106
if let Some ( & ( level, src) ) = specs. get ( & id) {
@@ -499,7 +516,7 @@ impl LintLevelMap {
499
516
lint : & ' static Lint ,
500
517
id : HirId ,
501
518
session : & Session ,
502
- ) -> Option < ( Level , LintSource ) > {
519
+ ) -> Option < LevelSource > {
503
520
self . id_to_set . get ( & id) . map ( |idx| self . sets . get_lint_level ( lint, * idx, None , session) )
504
521
}
505
522
}
0 commit comments