diff options
| author | csmoe <35686186+csmoe@users.noreply.github.com> | 2018-10-09 22:54:47 +0800 |
|---|---|---|
| committer | csmoe <35686186+csmoe@users.noreply.github.com> | 2018-10-20 11:11:31 +0800 |
| commit | d3b018ccdba328389ca90cff8795e5f6b97e5c13 (patch) | |
| tree | d493df91a67de510cff740dc7de0faf77d536ec5 /src/libsyntax/attr | |
| parent | 30c669819342dc09d6bd29dc72d0ff85381b71d2 (diff) | |
| download | rust-d3b018ccdba328389ca90cff8795e5f6b97e5c13.tar.gz rust-d3b018ccdba328389ca90cff8795e5f6b97e5c13.zip | |
suggest to trim prefix in nested meta items
Diffstat (limited to 'src/libsyntax/attr')
| -rw-r--r-- | src/libsyntax/attr/builtin.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/attr/mod.rs | 9 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 0c82b5c7107..8f9f91979a4 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<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 } diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index a980f3ab515..5404420988c 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<Symbol> { match self.node { MetaItemKind::NameValue(ref v) => { |
