11//! Meta-syntax validation logic of attributes for post-expansion.
22
33use errors:: { PResult , Applicability } ;
4- use syntax:: ast:: { self , Attribute , AttrKind , Ident , MetaItem } ;
5- use syntax:: attr:: { AttributeTemplate , mk_name_value_item_str} ;
4+ use syntax:: feature_gate:: AttributeTemplate ;
5+ use syntax:: ast:: { self , Attribute , AttrKind , Ident , MetaItem , MetaItemKind } ;
6+ use syntax:: attr:: mk_name_value_item_str;
67use syntax:: early_buffered_lints:: BufferedEarlyLintId ;
78use syntax:: feature_gate:: BUILTIN_ATTRIBUTE_MAP ;
89use syntax:: token;
@@ -41,6 +42,16 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
4142 } )
4243}
4344
45+ /// Checks that the given meta-item is compatible with this `AttributeTemplate`.
46+ fn is_attr_template_compatible ( template : & AttributeTemplate , meta : & ast:: MetaItemKind ) -> bool {
47+ match meta {
48+ MetaItemKind :: Word => template. word ,
49+ MetaItemKind :: List ( ..) => template. list . is_some ( ) ,
50+ MetaItemKind :: NameValue ( lit) if lit. kind . is_str ( ) => template. name_value_str . is_some ( ) ,
51+ MetaItemKind :: NameValue ( ..) => false ,
52+ }
53+ }
54+
4455pub fn check_builtin_attribute (
4556 sess : & ParseSess ,
4657 attr : & Attribute ,
@@ -57,7 +68,7 @@ pub fn check_builtin_attribute(
5768 name == sym:: test || name == sym:: bench;
5869
5970 match parse_meta ( sess, attr) {
60- Ok ( meta) => if !should_skip ( name) && !template . compatible ( & meta. kind ) {
71+ Ok ( meta) => if !should_skip ( name) && !is_attr_template_compatible ( & template , & meta. kind ) {
6172 let error_msg = format ! ( "malformed `{}` attribute input" , name) ;
6273 let mut msg = "attribute must be of the form " . to_owned ( ) ;
6374 let mut suggestions = vec ! [ ] ;
0 commit comments