Skip to content

Commit 696612c

Browse files
committed
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.
1 parent 29ed49f commit 696612c

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,11 +4088,11 @@ impl<'a> Parser<'a> {
40884088
node: StmtKind::Item(i),
40894089
},
40904090
None => {
4091-
let unused_attrs = |attrs: &[_], s: &mut Self| {
4091+
let unused_attrs = |attrs: &[Attribute], s: &mut Self| {
40924092
if !attrs.is_empty() {
40934093
if s.prev_token_kind == PrevTokenKind::DocComment {
40944094
s.span_fatal_err(s.prev_span, Error::UselessDocComment).emit();
4095-
} else {
4095+
} else if attrs.iter().any(|a| a.style == AttrStyle::Outer) {
40964096
s.span_err(s.span, "expected statement after outer attribute");
40974097
}
40984098
}

src/test/ui/issue-45296.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let unused = ();
13+
14+
#![allow(unused_variables)]
15+
}

src/test/ui/issue-45296.stderr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: an inner attribute is not permitted in this context
2+
--> $DIR/issue-45296.rs:14:7
3+
|
4+
14 | #![allow(unused_variables)]
5+
| ^
6+
|
7+
= 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
8+
`/// My function`, annotate the item following them.
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)