Skip to content

Commit 17d1742

Browse files
authored
Rollup merge of rust-lang#90267 - EliseZeroTwo:elisezerotwo/fix_invalid_attrs_ice, r=Aaron1011
fix: inner attribute followed by outer attribute causing ICE Fixes rust-lang#87936, rust-lang#88938, and rust-lang#89971. This removes the assertion that validates that there are no outer attributes following inner attributes. Where the inner attribute is invalid you get an actual error.
2 parents 088dc91 + 7f0d43a commit 17d1742

4 files changed

+46
-6
lines changed

compiler/rustc_ast/src/tokenstream.rs

-6
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,6 @@ impl AttrAnnotatedTokenStream {
221221
for attr in &data.attrs {
222222
match attr.style {
223223
crate::AttrStyle::Outer => {
224-
assert!(
225-
inner_attrs.len() == 0,
226-
"Found outer attribute {:?} after inner attrs {:?}",
227-
attr,
228-
inner_attrs
229-
);
230224
outer_attrs.push(attr);
231225
}
232226
crate::AttrStyle::Inner => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
10+
#[proc_macro_derive(ICE)]
11+
pub fn derive(_: TokenStream) -> TokenStream {
12+
r#"#[allow(missing_docs)] struct X { }"#.parse().unwrap()
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// aux-build:issue-89971-outer-attr-following-inner-attr-ice.rs
2+
3+
#[macro_use]
4+
extern crate issue_89971_outer_attr_following_inner_attr_ice;
5+
6+
fn main() {
7+
Mew();
8+
X {};
9+
}
10+
11+
#![deny(missing_docs)]
12+
//~^ ERROR an inner attribute is not permitted in this context
13+
#[derive(ICE)]
14+
#[deny(missing_docs)]
15+
struct Mew();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: an inner attribute is not permitted in this context
2+
--> $DIR/issue-89971-outer-attr-following-inner-attr-ice.rs:11:1
3+
|
4+
LL | #![deny(missing_docs)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | struct Mew();
8+
| ------------- the inner attribute doesn't annotate this struct
9+
|
10+
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
11+
help: to annotate the struct, change the attribute from inner to outer style
12+
|
13+
LL - #![deny(missing_docs)]
14+
LL + #[deny(missing_docs)]
15+
|
16+
17+
error: aborting due to previous error
18+

0 commit comments

Comments
 (0)