@@ -4,14 +4,29 @@ use rustc_attr_data_structures::RustcVersion;
44use rustc_feature:: { Features , GatedCfg , find_gated_cfg} ;
55use rustc_session:: Session ;
66use rustc_session:: config:: ExpectedValues ;
7- use rustc_session:: lint:: BuiltinLintDiag ;
87use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
8+ use rustc_session:: lint:: { BuiltinLintDiag , Lint } ;
99use rustc_session:: parse:: feature_err;
1010use rustc_span:: { Span , Symbol , sym} ;
1111
1212use crate :: session_diagnostics:: { self , UnsupportedLiteralReason } ;
1313use crate :: { fluent_generated, parse_version} ;
1414
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+
1530#[ derive( Clone , Debug ) ]
1631pub struct Condition {
1732 pub name : Symbol ,
@@ -25,28 +40,28 @@ pub struct Condition {
2540pub fn cfg_matches (
2641 cfg : & MetaItemInner ,
2742 sess : & Session ,
28- lint_node_id : NodeId ,
43+ lint_emitter : impl CfgMatchesLintEmitter ,
2944 features : Option < & Features > ,
3045) -> bool {
3146 eval_condition ( cfg, sess, features, & mut |cfg| {
3247 try_gate_cfg ( cfg. name , cfg. span , sess, features) ;
3348 match sess. psess . check_config . expecteds . get ( & cfg. name ) {
3449 Some ( ExpectedValues :: Some ( values) ) if !values. contains ( & cfg. value ) => {
35- sess. psess . buffer_lint (
50+ lint_emitter. emit_span_lint (
51+ sess,
3652 UNEXPECTED_CFGS ,
3753 cfg. span ,
38- lint_node_id,
3954 BuiltinLintDiag :: UnexpectedCfgValue (
4055 ( cfg. name , cfg. name_span ) ,
4156 cfg. value . map ( |v| ( v, cfg. value_span . unwrap ( ) ) ) ,
4257 ) ,
4358 ) ;
4459 }
4560 None if sess. psess . check_config . exhaustive_names => {
46- sess. psess . buffer_lint (
61+ lint_emitter. emit_span_lint (
62+ sess,
4763 UNEXPECTED_CFGS ,
4864 cfg. span ,
49- lint_node_id,
5065 BuiltinLintDiag :: UnexpectedCfgName (
5166 ( cfg. name , cfg. name_span ) ,
5267 cfg. value . map ( |v| ( v, cfg. value_span . unwrap ( ) ) ) ,
0 commit comments