about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2019-11-17 13:36:15 +0900
committerGitHub <noreply@github.com>2019-11-17 13:36:15 +0900
commit842612fcc00a679688bbc1bb74bb7480d12a0ac7 (patch)
tree405f342cf4b04790c542f24dc4e3dd6c07b13a6c /src
parent54998d1b3facdb684795c586d7a1e82582e32d27 (diff)
parent91aadf030548214da5a8f39a1b1dbd21db125625 (diff)
downloadrust-842612fcc00a679688bbc1bb74bb7480d12a0ac7.tar.gz
rust-842612fcc00a679688bbc1bb74bb7480d12a0ac7.zip
Rollup merge of #66381 - Centril:66340, r=petrochenkov
find_deprecation: deprecation attr may be ill-formed meta.

Fixes #66340.

r? @petrochenkov
cc @pnkfelix
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/attr/builtin.rs5
-rw-r--r--src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.rs11
-rw-r--r--src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr8
3 files changed, 23 insertions, 1 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs
index acf0dd1cabb..767fcabc017 100644
--- a/src/libsyntax/attr/builtin.rs
+++ b/src/libsyntax/attr/builtin.rs
@@ -667,7 +667,10 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess,
             break
         }
 
-        let meta = attr.meta().unwrap();
+        let meta = match attr.meta() {
+            Some(meta) => meta,
+            None => continue,
+        };
         depr = match &meta.kind {
             MetaItemKind::Word => Some(Deprecation { since: None, note: None }),
             MetaItemKind::NameValue(..) => {
diff --git a/src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.rs b/src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.rs
new file mode 100644
index 00000000000..c0cde75d4ca
--- /dev/null
+++ b/src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.rs
@@ -0,0 +1,11 @@
+// The original problem in #66340 was that `find_deprecation_generic`
+// called `attr.meta().unwrap()` under the assumption that the attribute
+// was a well-formed `MetaItem`.
+
+fn main() {
+    foo()
+}
+
+#[deprecated(note = test)]
+//~^ ERROR expected unsuffixed literal or identifier, found `test`
+fn foo() {}
diff --git a/src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr b/src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr
new file mode 100644
index 00000000000..24178faf8de
--- /dev/null
+++ b/src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr
@@ -0,0 +1,8 @@
+error: expected unsuffixed literal or identifier, found `test`
+  --> $DIR/issue-66340-deprecated-attr-non-meta-grammar.rs:9:21
+   |
+LL | #[deprecated(note = test)]
+   |                     ^^^^
+
+error: aborting due to previous error
+