Skip to content

don't issue "expected statement after outer attr." after inner attr. #45315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issue-45296.rs
Original file line number Diff line number Diff line change
@@ -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)]
}
11 changes: 11 additions & 0 deletions src/test/ui/issue-45296.stderr
Original file line number Diff line number Diff line change
@@ -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