diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-10-27 18:25:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-27 18:25:44 +0200 |
| commit | 17d17420285b312ea75faddad79d8552e685c85e (patch) | |
| tree | 4704e4f7249defb9f4045366ad8d79ad50920bc5 | |
| parent | 088dc91e0a8cda39c9525d275a55046427c33485 (diff) | |
| parent | 7f0d43a003a70ce4cc12d8239e379feb5e5e48f8 (diff) | |
| download | rust-17d17420285b312ea75faddad79d8552e685c85e.tar.gz rust-17d17420285b312ea75faddad79d8552e685c85e.zip | |
Rollup merge of #90267 - EliseZeroTwo:elisezerotwo/fix_invalid_attrs_ice, r=Aaron1011
fix: inner attribute followed by outer attribute causing ICE Fixes #87936, #88938, and #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.
4 files changed, 46 insertions, 6 deletions
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 5d994dbad4d..51cabb50cd3 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -221,12 +221,6 @@ impl AttrAnnotatedTokenStream { for attr in &data.attrs { match attr.style { crate::AttrStyle::Outer => { - assert!( - inner_attrs.len() == 0, - "Found outer attribute {:?} after inner attrs {:?}", - attr, - inner_attrs - ); outer_attrs.push(attr); } crate::AttrStyle::Inner => { diff --git a/src/test/ui/parser/auxiliary/issue-89971-outer-attr-following-inner-attr-ice.rs b/src/test/ui/parser/auxiliary/issue-89971-outer-attr-following-inner-attr-ice.rs new file mode 100644 index 00000000000..e5604b816b5 --- /dev/null +++ b/src/test/ui/parser/auxiliary/issue-89971-outer-attr-following-inner-attr-ice.rs @@ -0,0 +1,13 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(ICE)] +pub fn derive(_: TokenStream) -> TokenStream { + r#"#[allow(missing_docs)] struct X { }"#.parse().unwrap() +} diff --git a/src/test/ui/parser/issue-89971-outer-attr-following-inner-attr-ice.rs b/src/test/ui/parser/issue-89971-outer-attr-following-inner-attr-ice.rs new file mode 100644 index 00000000000..fe67d9822fc --- /dev/null +++ b/src/test/ui/parser/issue-89971-outer-attr-following-inner-attr-ice.rs @@ -0,0 +1,15 @@ +// aux-build:issue-89971-outer-attr-following-inner-attr-ice.rs + +#[macro_use] +extern crate issue_89971_outer_attr_following_inner_attr_ice; + +fn main() { + Mew(); + X {}; +} + +#![deny(missing_docs)] +//~^ ERROR an inner attribute is not permitted in this context +#[derive(ICE)] +#[deny(missing_docs)] +struct Mew(); diff --git a/src/test/ui/parser/issue-89971-outer-attr-following-inner-attr-ice.stderr b/src/test/ui/parser/issue-89971-outer-attr-following-inner-attr-ice.stderr new file mode 100644 index 00000000000..34a6ab00d7b --- /dev/null +++ b/src/test/ui/parser/issue-89971-outer-attr-following-inner-attr-ice.stderr @@ -0,0 +1,18 @@ +error: an inner attribute is not permitted in this context + --> $DIR/issue-89971-outer-attr-following-inner-attr-ice.rs:11:1 + | +LL | #![deny(missing_docs)] + | ^^^^^^^^^^^^^^^^^^^^^^ +... +LL | struct Mew(); + | ------------- the inner attribute doesn't annotate this struct + | + = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files +help: to annotate the struct, change the attribute from inner to outer style + | +LL - #![deny(missing_docs)] +LL + #[deny(missing_docs)] + | + +error: aborting due to previous error + |
