about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-10-17 22:21:01 +0800
committerGitHub <noreply@github.com>2017-10-17 22:21:01 +0800
commit87729fcdbad78d10a80da84d92c6992e61b924d7 (patch)
tree8a6dba8b48d8b527c49c5d134bb6b2b265e68d60
parent16167cbf737436c468bd3d9ca05785210214c2d1 (diff)
parent696612c02f7e64b8ca5f62c4614d0cb5b20ff9b7 (diff)
Rollup merge of #45315 - zackmdavis:expected_statement_after_outer_attr_after_inner_attr, r=petrochenkov
don't issue "expected statement after outer attr." after inner attr.

While an inner attribute here is in fact erroneous, that error ("inner
attribute is not permitted in this context") successfully gets set earlier;
this further admonition is nonsensical.

Resolves #45296.
-rw-r--r--src/libsyntax/parse/parser.rs4
-rw-r--r--src/test/ui/issue-45296.rs15
-rw-r--r--src/test/ui/issue-45296.stderr11
3 files changed, 28 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index bd400ef6dd6..8fd2bad4e44 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4088,11 +4088,11 @@ impl<'a> Parser<'a> {
                     node: StmtKind::Item(i),
                 },
                 None => {
-                    let unused_attrs = |attrs: &[_], s: &mut Self| {
+                    let unused_attrs = |attrs: &[Attribute], s: &mut Self| {
                         if !attrs.is_empty() {
                             if s.prev_token_kind == PrevTokenKind::DocComment {
                                 s.span_fatal_err(s.prev_span, Error::UselessDocComment).emit();
-                            } else {
+                            } else if attrs.iter().any(|a| a.style == AttrStyle::Outer) {
                                 s.span_err(s.span, "expected statement after outer attribute");
                             }
                         }
diff --git a/src/test/ui/issue-45296.rs b/src/test/ui/issue-45296.rs
new file mode 100644
index 00000000000..7a2b4e56d69
--- /dev/null
+++ b/src/test/ui/issue-45296.rs
@@ -0,0 +1,15 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    let unused = ();
+
+    #![allow(unused_variables)]
+}
diff --git a/src/test/ui/issue-45296.stderr b/src/test/ui/issue-45296.stderr
new file mode 100644
index 00000000000..7bfcac974c5
--- /dev/null
+++ b/src/test/ui/issue-45296.stderr
@@ -0,0 +1,11 @@
+error: an inner attribute is not permitted in this context
+  --> $DIR/issue-45296.rs:14:7
+   |
+14 |     #![allow(unused_variables)]
+   |       ^
+   |
+   = note: inner attributes and doc comments, like `#![no_std]` or `//! My crate`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes and doc comments, like `#[test]` and
+                                              `/// My function`, annotate the item following them.
+
+error: aborting due to previous error
+