@@ -4,14 +4,29 @@ use rustc_attr_data_structures::RustcVersion;
4
4
use rustc_feature:: { Features , GatedCfg , find_gated_cfg} ;
5
5
use rustc_session:: Session ;
6
6
use rustc_session:: config:: ExpectedValues ;
7
- use rustc_session:: lint:: BuiltinLintDiag ;
8
7
use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
8
+ use rustc_session:: lint:: { BuiltinLintDiag , Lint } ;
9
9
use rustc_session:: parse:: feature_err;
10
10
use rustc_span:: { Span , Symbol , sym} ;
11
11
12
12
use crate :: session_diagnostics:: { self , UnsupportedLiteralReason } ;
13
13
use crate :: { fluent_generated, parse_version} ;
14
14
15
+ /// Emitter of a builtin lint from `cfg_matches`.
16
+ ///
17
+ /// Used to support emiting a lint (currently on check-cfg), either:
18
+ /// - as an early buffered lint (in `rustc`)
19
+ /// - or has a "normal" lint from HIR (in `rustdoc`)
20
+ pub trait CfgMatchesLintEmitter {
21
+ fn emit_span_lint ( & self , sess : & Session , lint : & ' static Lint , sp : Span , diag : BuiltinLintDiag ) ;
22
+ }
23
+
24
+ impl CfgMatchesLintEmitter for NodeId {
25
+ fn emit_span_lint ( & self , sess : & Session , lint : & ' static Lint , sp : Span , diag : BuiltinLintDiag ) {
26
+ sess. psess . buffer_lint ( lint, sp, * self , diag) ;
27
+ }
28
+ }
29
+
15
30
#[ derive( Clone , Debug ) ]
16
31
pub struct Condition {
17
32
pub name : Symbol ,
@@ -25,28 +40,28 @@ pub struct Condition {
25
40
pub fn cfg_matches (
26
41
cfg : & MetaItemInner ,
27
42
sess : & Session ,
28
- lint_node_id : NodeId ,
43
+ lint_emitter : impl CfgMatchesLintEmitter ,
29
44
features : Option < & Features > ,
30
45
) -> bool {
31
46
eval_condition ( cfg, sess, features, & mut |cfg| {
32
47
try_gate_cfg ( cfg. name , cfg. span , sess, features) ;
33
48
match sess. psess . check_config . expecteds . get ( & cfg. name ) {
34
49
Some ( ExpectedValues :: Some ( values) ) if !values. contains ( & cfg. value ) => {
35
- sess. psess . buffer_lint (
50
+ lint_emitter. emit_span_lint (
51
+ sess,
36
52
UNEXPECTED_CFGS ,
37
53
cfg. span ,
38
- lint_node_id,
39
54
BuiltinLintDiag :: UnexpectedCfgValue (
40
55
( cfg. name , cfg. name_span ) ,
41
56
cfg. value . map ( |v| ( v, cfg. value_span . unwrap ( ) ) ) ,
42
57
) ,
43
58
) ;
44
59
}
45
60
None if sess. psess . check_config . exhaustive_names => {
46
- sess. psess . buffer_lint (
61
+ lint_emitter. emit_span_lint (
62
+ sess,
47
63
UNEXPECTED_CFGS ,
48
64
cfg. span ,
49
- lint_node_id,
50
65
BuiltinLintDiag :: UnexpectedCfgName (
51
66
( cfg. name , cfg. name_span ) ,
52
67
cfg. value . map ( |v| ( v, cfg. value_span . unwrap ( ) ) ) ,
0 commit comments