@@ -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:: { 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 ;
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" ] ,
@@ -195,43 +191,40 @@ fn parse_name_value<S: Stage>(
195191 }
196192 } ;
197193
194+ match cx. sess . psess . check_config . expecteds . get ( & name) {
195+ Some ( ExpectedValues :: Some ( values) ) if !values. contains ( & value. map ( |( v, _) | v) ) => {
196+ cx. emit_lint ( AttributeLintKind :: UnexpectedCfgValue { name, name_span, value } , span) ;
197+ }
198+ None if cx. sess . psess . check_config . exhaustive_names => {
199+ cx. emit_lint ( AttributeLintKind :: UnexpectedCfgName { name, name_span, value } , span) ;
200+ }
201+ _ => { /* not unexpected */ }
202+ }
203+
198204 Ok ( CfgEntry :: NameValue { name, name_span, value, span } )
199205}
200206
201- pub fn eval_config_entry (
202- sess : & Session ,
203- cfg_entry : & CfgEntry ,
204- id : NodeId ,
205- emit_lints : ShouldEmit ,
206- ) -> EvalConfigResult {
207+ pub fn eval_config_entry ( sess : & Session , cfg_entry : & CfgEntry ) -> EvalConfigResult {
207208 match cfg_entry {
208209 CfgEntry :: All ( subs, ..) => {
209- let mut all = None ;
210210 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
211+ let res = eval_config_entry ( sess, sub) ;
213212 if !res. as_bool ( ) {
214- all . get_or_insert ( res) ;
213+ return res;
215214 }
216215 }
217- all . unwrap_or_else ( || EvalConfigResult :: True )
216+ EvalConfigResult :: True
218217 }
219218 CfgEntry :: Any ( subs, span) => {
220- let mut any = None ;
221219 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
224- if res. as_bool ( ) {
225- any. get_or_insert ( res) ;
220+ if eval_config_entry ( sess, sub) . as_bool ( ) {
221+ return EvalConfigResult :: True ;
226222 }
227223 }
228- any. unwrap_or_else ( || EvalConfigResult :: False {
229- reason : cfg_entry. clone ( ) ,
230- reason_span : * span,
231- } )
224+ EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
232225 }
233226 CfgEntry :: Not ( sub, span) => {
234- if eval_config_entry ( sess, sub, id , emit_lints ) . as_bool ( ) {
227+ if eval_config_entry ( sess, sub) . as_bool ( ) {
235228 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
236229 } else {
237230 EvalConfigResult :: True
@@ -244,31 +237,7 @@ pub fn eval_config_entry(
244237 EvalConfigResult :: False { reason : cfg_entry. clone ( ) , reason_span : * span }
245238 }
246239 }
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-
240+ CfgEntry :: NameValue { name, name_span : _, value, span } => {
272241 if sess. psess . config . contains ( & ( * name, value. map ( |( v, _) | v) ) ) {
273242 EvalConfigResult :: True
274243 } else {
0 commit comments