diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 0c82b5c71070..8f9f91979a42 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -596,7 +596,17 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, *item = Some(v); true } else { - span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + if let Some(lit) = meta.name_value_literal() { + handle_errors( + sess, + lit.span, + AttrError::UnsupportedLiteral, + lit.node.is_bytestr(), + ); + } else { + span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + } + false } }; @@ -622,7 +632,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, } NestedMetaItemKind::Literal(lit) => { let is_bytestr = lit.node.is_bytestr(); - handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, is_bytestr); + handle_errors(sess, lit.span, AttrError::UnsupportedLiteral, is_bytestr); continue 'outer } } @@ -682,7 +692,12 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { mark_used(attr); for item in items { if !item.is_meta_item() { - handle_errors(sess, item.span, AttrError::UnsupportedLiteral, false); + let (span, is_bytestr) = if let Some(lit) = item.literal() { + (lit.span, lit.node.is_bytestr()) + } else { + (item.span, false) + }; + handle_errors(sess, span, AttrError::UnsupportedLiteral, is_bytestr); continue } diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index a980f3ab5158..5404420988c3 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -219,6 +219,15 @@ impl MetaItem { name_from_path(&self.ident) } + // #[attribute(name = "value")] + // ^^^^^^^^^^^^^^ + pub fn name_value_literal(&self) -> Option<&Lit> { + match &self.node { + MetaItemKind::NameValue(v) => Some(v), + _ => None, + } + } + pub fn value_str(&self) -> Option { match self.node { MetaItemKind::NameValue(ref v) => {