@@ -2,16 +2,16 @@ use std::convert::identity;
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:: { AttrSuggestionStyle , 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 ;
1515use rustc_session:: lint:: builtin:: UNEXPECTED_CFGS ;
1616use rustc_session:: parse:: { ParseSess , feature_err} ;
1717use rustc_span:: { ErrorGuaranteed , Span , Symbol , sym} ;
@@ -23,10 +23,7 @@ use crate::session_diagnostics::{
2323 AttributeParseError , AttributeParseErrorReason , CfgAttrBadDelim , MetaBadDelimSugg ,
2424 ParsedDescription ,
2525} ;
26- use crate :: {
27- AttributeParser , CfgMatchesLintEmitter , fluent_generated, parse_version, session_diagnostics,
28- try_gate_cfg,
29- } ;
26+ use crate :: { AttributeParser , fluent_generated, parse_version, session_diagnostics, try_gate_cfg} ;
3027
3128pub const CFG_TEMPLATE : AttributeTemplate = template ! (
3229 List : & [ "predicate" ] ,
@@ -195,43 +192,46 @@ fn parse_name_value<S: Stage>(
195192 }
196193 } ;
197194
198- Ok ( CfgEntry :: NameValue { name, name_span, value, span } )
195+ match cx. sess . psess . check_config . expecteds . get ( & name) {
196+ Some ( ExpectedValues :: Some ( values) ) if !values. contains ( & value. map ( |( v, _) | v) ) => cx
197+ . emit_lint (
198+ UNEXPECTED_CFGS ,
199+ AttributeLintKind :: UnexpectedCfgValue ( ( name, name_span) , value) ,
200+ span,
201+ ) ,
202+ None if cx. sess . psess . check_config . exhaustive_names => cx. emit_lint (
203+ UNEXPECTED_CFGS ,
204+ AttributeLintKind :: UnexpectedCfgName ( ( name, name_span) , value) ,
205+ span,
206+ ) ,
207+ _ => { /* not unexpected */ }
208+ }
209+
210+ Ok ( CfgEntry :: NameValue { name, value : value. map ( |( v, _) | v) , span } )
199211}
200212
201- pub fn eval_config_entry (
202- sess : & Session ,
203- cfg_entry : & CfgEntry ,
204- id : NodeId ,
205- emit_lints : ShouldEmit ,
206- ) -> EvalConfigResult {
213+ pub fn eval_config_entry ( sess : & Session , cfg_entry : & CfgEntry ) -> EvalConfigResult {
207214 match cfg_entry {
208215 CfgEntry :: All ( subs, ..) => {
209- let mut all = None ;
210216 for sub in subs {
211- let res = eval_config_entry ( sess, sub, id, emit_lints) ;
212- // We cannot short-circuit because `eval_config_entry` emits some lints
217+ let res = eval_config_entry ( sess, sub) ;
213218 if !res. as_bool ( ) {
214- all . get_or_insert ( res) ;
219+ return res;
215220 }
216221 }
217- all . unwrap_or_else ( || EvalConfigResult :: True )
222+ EvalConfigResult :: True
218223 }
219224 CfgEntry :: Any ( subs, span) => {
220- let mut any = None ;
221225 for sub in subs {
222- let res = eval_config_entry ( sess, sub, id, emit_lints) ;
223- // We cannot short-circuit because `eval_config_entry` emits some lints
226+ let res = eval_config_entry ( sess, sub) ;
224227 if res. as_bool ( ) {
225- any . get_or_insert ( res) ;
228+ return res;
226229 }
227230 }
228- any. unwrap_or_else ( || EvalConfigResult :: False {
229- reason : cfg_entry. clone ( ) ,
230- reason_span : * span,
231- } )
231+ EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
232232 }
233233 CfgEntry :: Not ( sub, span) => {
234- if eval_config_entry ( sess, sub, id , emit_lints ) . as_bool ( ) {
234+ if eval_config_entry ( sess, sub) . as_bool ( ) {
235235 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
236236 } else {
237237 EvalConfigResult :: True
@@ -244,32 +244,8 @@ pub fn eval_config_entry(
244244 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
245245 }
246246 }
247- CfgEntry :: NameValue { name, name_span, value, span } => {
248- if let ShouldEmit :: ErrorsAndLints = emit_lints {
249- match sess. psess . check_config . expecteds . get ( name) {
250- Some ( ExpectedValues :: Some ( values) )
251- if !values. contains ( & value. map ( |( v, _) | v) ) =>
252- {
253- id. emit_span_lint (
254- sess,
255- UNEXPECTED_CFGS ,
256- * span,
257- BuiltinLintDiag :: UnexpectedCfgValue ( ( * name, * name_span) , * value) ,
258- ) ;
259- }
260- None if sess. psess . check_config . exhaustive_names => {
261- id. emit_span_lint (
262- sess,
263- UNEXPECTED_CFGS ,
264- * span,
265- BuiltinLintDiag :: UnexpectedCfgName ( ( * name, * name_span) , * value) ,
266- ) ;
267- }
268- _ => { /* not unexpected */ }
269- }
270- }
271-
272- if sess. psess . config . contains ( & ( * name, value. map ( |( v, _) | v) ) ) {
247+ CfgEntry :: NameValue { name, value, span } => {
248+ if sess. psess . config . contains ( & ( * name, * value) ) {
273249 EvalConfigResult :: True
274250 } else {
275251 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
0 commit comments