]> git.lizzy.rs Git - rust.git/commitdiff
find_deprecation: deprecation attr may be ill-formed meta.
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 13 Nov 2019 18:32:12 +0000 (19:32 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Fri, 15 Nov 2019 12:24:06 +0000 (13:24 +0100)
src/libsyntax/attr/builtin.rs
src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.rs [new file with mode: 0644]
src/test/ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.stderr [new file with mode: 0644]

index 2b759c205f54edaf51133de8e77e91610736b7d8..75e0c1411595560a84ebd76dbea815bb68d540ab 100644 (file)
@@ -665,7 +665,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 (file)
index 0000000..c0cde75
--- /dev/null
@@ -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 (file)
index 0000000..24178fa
--- /dev/null
@@ -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
+