@@ -10,9 +10,9 @@ use rustc_errors::{Applicability, FatalError, PResult};
1010use rustc_feature:: { AttributeTemplate , BuiltinAttribute , BUILTIN_ATTRIBUTE_MAP } ;
1111use rustc_session:: lint:: builtin:: ILL_FORMED_ATTRIBUTE_INPUT ;
1212use rustc_session:: parse:: ParseSess ;
13- use rustc_span:: { sym, Symbol } ;
13+ use rustc_span:: { sym, Span , Symbol } ;
1414
15- pub fn check_meta ( sess : & ParseSess , attr : & Attribute ) {
15+ pub fn check_attr ( sess : & ParseSess , attr : & Attribute ) {
1616 if attr. is_doc_comment ( ) {
1717 return ;
1818 }
@@ -115,25 +115,34 @@ pub fn check_builtin_attribute(
115115 name : Symbol ,
116116 template : AttributeTemplate ,
117117) {
118- // Some special attributes like `cfg` must be checked
119- // before the generic check, so we skip them here.
120- let should_skip = |name| name == sym:: cfg;
121-
122118 match parse_meta ( sess, attr) {
123- Ok ( meta) => {
124- if !should_skip ( name) && !is_attr_template_compatible ( & template, & meta. kind ) {
125- emit_malformed_attribute ( sess, attr, name, template) ;
126- }
127- }
119+ Ok ( meta) => check_builtin_meta_item ( sess, & meta, attr. style , name, template) ,
128120 Err ( mut err) => {
129121 err. emit ( ) ;
130122 }
131123 }
132124}
133125
126+ pub fn check_builtin_meta_item (
127+ sess : & ParseSess ,
128+ meta : & MetaItem ,
129+ style : ast:: AttrStyle ,
130+ name : Symbol ,
131+ template : AttributeTemplate ,
132+ ) {
133+ // Some special attributes like `cfg` must be checked
134+ // before the generic check, so we skip them here.
135+ let should_skip = |name| name == sym:: cfg;
136+
137+ if !should_skip ( name) && !is_attr_template_compatible ( & template, & meta. kind ) {
138+ emit_malformed_attribute ( sess, style, meta. span , name, template) ;
139+ }
140+ }
141+
134142fn emit_malformed_attribute (
135143 sess : & ParseSess ,
136- attr : & Attribute ,
144+ style : ast:: AttrStyle ,
145+ span : Span ,
137146 name : Symbol ,
138147 template : AttributeTemplate ,
139148) {
@@ -147,7 +156,7 @@ fn emit_malformed_attribute(
147156 let mut msg = "attribute must be of the form " . to_owned ( ) ;
148157 let mut suggestions = vec ! [ ] ;
149158 let mut first = true ;
150- let inner = if attr . style == ast:: AttrStyle :: Inner { "!" } else { "" } ;
159+ let inner = if style == ast:: AttrStyle :: Inner { "!" } else { "" } ;
151160 if template. word {
152161 first = false ;
153162 let code = format ! ( "#{}[{}]" , inner, name) ;
@@ -172,12 +181,12 @@ fn emit_malformed_attribute(
172181 suggestions. push ( code) ;
173182 }
174183 if should_warn ( name) {
175- sess. buffer_lint ( & ILL_FORMED_ATTRIBUTE_INPUT , attr . span , ast:: CRATE_NODE_ID , & msg) ;
184+ sess. buffer_lint ( & ILL_FORMED_ATTRIBUTE_INPUT , span, ast:: CRATE_NODE_ID , & msg) ;
176185 } else {
177186 sess. span_diagnostic
178- . struct_span_err ( attr . span , & error_msg)
187+ . struct_span_err ( span, & error_msg)
179188 . span_suggestions (
180- attr . span ,
189+ span,
181190 if suggestions. len ( ) == 1 {
182191 "must be of the form"
183192 } else {
@@ -196,7 +205,7 @@ pub fn emit_fatal_malformed_builtin_attribute(
196205 name : Symbol ,
197206) -> ! {
198207 let template = BUILTIN_ATTRIBUTE_MAP . get ( & name) . expect ( "builtin attr defined" ) . template ;
199- emit_malformed_attribute ( sess, attr, name, template) ;
208+ emit_malformed_attribute ( sess, attr. style , attr . span , name, template) ;
200209 // This is fatal, otherwise it will likely cause a cascade of other errors
201210 // (and an error here is expected to be very rare).
202211 FatalError . raise ( )
0 commit comments