Skip to content

Commit d3b018c

Browse files
committed
suggest to trim prefix in nested meta items
1 parent 30c6698 commit d3b018c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/libsyntax/attr/builtin.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,17 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
596596
*item = Some(v);
597597
true
598598
} else {
599-
span_err!(diagnostic, meta.span, E0551, "incorrect meta item");
599+
if let Some(lit) = meta.name_value_literal() {
600+
handle_errors(
601+
sess,
602+
lit.span,
603+
AttrError::UnsupportedLiteral,
604+
lit.node.is_bytestr(),
605+
);
606+
} else {
607+
span_err!(diagnostic, meta.span, E0551, "incorrect meta item");
608+
}
609+
600610
false
601611
}
602612
};
@@ -622,7 +632,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
622632
}
623633
NestedMetaItemKind::Literal(lit) => {
624634
let is_bytestr = lit.node.is_bytestr();
625-
handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, is_bytestr);
635+
handle_errors(sess, lit.span, AttrError::UnsupportedLiteral, is_bytestr);
626636
continue 'outer
627637
}
628638
}
@@ -682,7 +692,12 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
682692
mark_used(attr);
683693
for item in items {
684694
if !item.is_meta_item() {
685-
handle_errors(sess, item.span, AttrError::UnsupportedLiteral, false);
695+
let (span, is_bytestr) = if let Some(lit) = item.literal() {
696+
(lit.span, lit.node.is_bytestr())
697+
} else {
698+
(item.span, false)
699+
};
700+
handle_errors(sess, span, AttrError::UnsupportedLiteral, is_bytestr);
686701
continue
687702
}
688703

src/libsyntax/attr/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ impl MetaItem {
219219
name_from_path(&self.ident)
220220
}
221221

222+
// #[attribute(name = "value")]
223+
// ^^^^^^^^^^^^^^
224+
pub fn name_value_literal(&self) -> Option<&Lit> {
225+
match &self.node {
226+
MetaItemKind::NameValue(v) => Some(v),
227+
_ => None,
228+
}
229+
}
230+
222231
pub fn value_str(&self) -> Option<Symbol> {
223232
match self.node {
224233
MetaItemKind::NameValue(ref v) => {

0 commit comments

Comments
 (0)