1
Fork 0

suggest to trim prefix in nested meta items

This commit is contained in:
csmoe 2018-10-09 22:54:47 +08:00
parent 30c6698193
commit d3b018ccdb
2 changed files with 27 additions and 3 deletions

View file

@ -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<ReprAttr> {
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
}

View file

@ -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<Symbol> {
match self.node {
MetaItemKind::NameValue(ref v) => {