@@ -2,17 +2,16 @@ pub(crate) mod check_cfg;
22
33use rustc_ast:: token:: Delimiter ;
44use rustc_ast:: tokenstream:: DelimSpan ;
5- use rustc_ast:: { AttrItem , Attribute , CRATE_NODE_ID , LitKind , NodeId , ast, token} ;
5+ use rustc_ast:: { AttrItem , Attribute , CRATE_NODE_ID , LitKind , ast, token} ;
66use rustc_errors:: { Applicability , PResult } ;
77use rustc_feature:: { AttributeTemplate , Features , template} ;
88use rustc_hir:: attrs:: CfgEntry ;
9+ use rustc_hir:: lints:: AttributeLintKind ;
910use rustc_hir:: { AttrPath , RustcVersion } ;
1011use rustc_parse:: parser:: { ForceCollect , Parser } ;
1112use rustc_parse:: { exp, parse_in} ;
1213use rustc_session:: Session ;
1314use rustc_session:: config:: ExpectedValues ;
14- use rustc_session:: lint:: BuiltinLintDiag ;
15- use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
1615use rustc_session:: parse:: { ParseSess , feature_err} ;
1716use rustc_span:: { ErrorGuaranteed , Span , Symbol , sym} ;
1817use thin_vec:: ThinVec ;
@@ -23,10 +22,7 @@ use crate::session_diagnostics::{
2322 AttributeParseError , AttributeParseErrorReason , CfgAttrBadDelim , MetaBadDelimSugg ,
2423 ParsedDescription ,
2524} ;
26- use crate :: {
27- AttributeParser , CfgMatchesLintEmitter , fluent_generated, parse_version, session_diagnostics,
28- try_gate_cfg,
29- } ;
25+ use crate :: { AttributeParser , fluent_generated, parse_version, session_diagnostics, try_gate_cfg} ;
3026
3127pub const CFG_TEMPLATE : AttributeTemplate = template ! (
3228 List : & [ "predicate" ] ,
@@ -194,43 +190,40 @@ fn parse_name_value<S: Stage>(
194190 }
195191 } ;
196192
193+ match cx. sess . psess . check_config . expecteds . get ( & name) {
194+ Some ( ExpectedValues :: Some ( values) ) if !values. contains ( & value. map ( |( v, _) | v) ) => {
195+ cx. emit_lint ( AttributeLintKind :: UnexpectedCfgValue { name, name_span, value } , span) ;
196+ }
197+ None if cx. sess . psess . check_config . exhaustive_names => {
198+ cx. emit_lint ( AttributeLintKind :: UnexpectedCfgName { name, name_span, value } , span) ;
199+ }
200+ _ => { /* not unexpected */ }
201+ }
202+
197203 Ok ( CfgEntry :: NameValue { name, name_span, value, span } )
198204}
199205
200- pub fn eval_config_entry (
201- sess : & Session ,
202- cfg_entry : & CfgEntry ,
203- id : NodeId ,
204- emit_lints : ShouldEmit ,
205- ) -> EvalConfigResult {
206+ pub fn eval_config_entry ( sess : & Session , cfg_entry : & CfgEntry ) -> EvalConfigResult {
206207 match cfg_entry {
207208 CfgEntry :: All ( subs, ..) => {
208- let mut all = None ;
209209 for sub in subs {
210- let res = eval_config_entry ( sess, sub, id, emit_lints) ;
211- // We cannot short-circuit because `eval_config_entry` emits some lints
210+ let res = eval_config_entry ( sess, sub) ;
212211 if !res. as_bool ( ) {
213- all . get_or_insert ( res) ;
212+ return res;
214213 }
215214 }
216- all . unwrap_or_else ( || EvalConfigResult :: True )
215+ EvalConfigResult :: True
217216 }
218217 CfgEntry :: Any ( subs, span) => {
219- let mut any = None ;
220218 for sub in subs {
221- let res = eval_config_entry ( sess, sub, id, emit_lints) ;
222- // We cannot short-circuit because `eval_config_entry` emits some lints
223- if res. as_bool ( ) {
224- any. get_or_insert ( res) ;
219+ if eval_config_entry ( sess, sub) . as_bool ( ) {
220+ return EvalConfigResult :: True ;
225221 }
226222 }
227- any. unwrap_or_else ( || EvalConfigResult :: False {
228- reason : cfg_entry. clone ( ) ,
229- reason_span : * span,
230- } )
223+ EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
231224 }
232225 CfgEntry :: Not ( sub, span) => {
233- if eval_config_entry ( sess, sub, id , emit_lints ) . as_bool ( ) {
226+ if eval_config_entry ( sess, sub) . as_bool ( ) {
234227 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
235228 } else {
236229 EvalConfigResult :: True
@@ -243,31 +236,7 @@ pub fn eval_config_entry(
243236 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
244237 }
245238 }
246- CfgEntry :: NameValue { name, name_span, value, span } => {
247- if let ShouldEmit :: ErrorsAndLints = emit_lints {
248- match sess. psess . check_config . expecteds . get ( name) {
249- Some ( ExpectedValues :: Some ( values) )
250- if !values. contains ( & value. map ( |( v, _) | v) ) =>
251- {
252- id. emit_span_lint (
253- sess,
254- UNEXPECTED_CFGS ,
255- * span,
256- BuiltinLintDiag :: UnexpectedCfgValue ( ( * name, * name_span) , * value) ,
257- ) ;
258- }
259- None if sess. psess . check_config . exhaustive_names => {
260- id. emit_span_lint (
261- sess,
262- UNEXPECTED_CFGS ,
263- * span,
264- BuiltinLintDiag :: UnexpectedCfgName ( ( * name, * name_span) , * value) ,
265- ) ;
266- }
267- _ => { /* not unexpected */ }
268- }
269- }
270-
239+ CfgEntry :: NameValue { name, name_span : _, value, span } => {
271240 if sess. psess . config . contains ( & ( * name, value. map ( |( v, _) | v) ) ) {
272241 EvalConfigResult :: True
273242 } else {
0 commit comments