Skip to content

ICE "Found outer attribute Attribute" #87936

Closed
@EliseZeroTwo

Description

@EliseZeroTwo
Contributor

I encountered an ICE while incorrectly inserting a outer attribute above deriving serde::Serialize or serde::Deserialize inside of a proc-macro. This did not happen with any other derive I tried.

Code

#[proc_macro]
pub fn proc_macro_ice(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let output = quote::quote! {
                #![deny(missing_docs)]
		#[derive(serde::Serialize)]
		#[allow(missing_docs)]
		pub struct ICE();
    };

    output.into()
}

Meta

rustc +stable --version --verbose:

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: aarch64-apple-darwin
release: 1.54.0
LLVM version: 12.0.1

rustc +nightly --version --verbose:

rustc 1.56.0-nightly (ad981d58e 2021-08-08)
binary: rustc
commit-hash: ad981d58e1ca16bcf4072577934630deb11c5e14
commit-date: 2021-08-08
host: aarch64-apple-darwin
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

error: an inner attribute is not permitted in this context
 --> ice/src/lib.rs:1:1
  |
1 | ice_macros::proc_macro_ice!();
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
  = note: this error originates in the macro `ice_macros::proc_macro_ice` (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at 'Found outer attribute Attribute { kind: Normal(AttrItem { path: Path { span: ice/src/lib.rs:1:1: 1:31 (#4), segments: [PathSegment { ident: allow#4, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Parenthesis, TokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("allow", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), Alone)])), Alone)])))), id: AttrId(32), style: Outer, span: ice/src/lib.rs:1:1: 1:31 (#4) } after inner attrs [Attribute { kind: Normal(AttrItem { path: Path { span: ice/src/lib.rs:1:1: 1:31 (#4), segments: [PathSegment { ident: deny#4, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Parenthesis, TokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Token(Token { kind: Not, span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("deny", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), Alone)])), Alone)])))), id: AttrId(30), style: Inner, span: ice/src/lib.rs:1:1: 1:31 (#4) }]', compiler/rustc_ast/src/tokenstream.rs:224:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0 (a178d0322 2021-07-26) running on aarch64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
Backtrace

error: an inner attribute is not permitted in this context
 --> ice/src/lib.rs:1:1
  |
1 | ice_macros::proc_macro_ice!();
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
  = note: this error originates in the macro `ice_macros::proc_macro_ice` (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at 'Found outer attribute Attribute { kind: Normal(AttrItem { path: Path { span: ice/src/lib.rs:1:1: 1:31 (#4), segments: [PathSegment { ident: allow#4, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Parenthesis, TokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("allow", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), Alone)])), Alone)])))), id: AttrId(32), style: Outer, span: ice/src/lib.rs:1:1: 1:31 (#4) } after inner attrs [Attribute { kind: Normal(AttrItem { path: Path { span: ice/src/lib.rs:1:1: 1:31 (#4), segments: [PathSegment { ident: deny#4, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Parenthesis, TokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Token(Token { kind: Not, span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("deny", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone), (Delimited(DelimSpan { open: ice/src/lib.rs:1:1: 1:31 (#4), close: ice/src/lib.rs:1:1: 1:31 (#4) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("missing_docs", false), span: ice/src/lib.rs:1:1: 1:31 (#4) }), Alone)])), Alone)])), Alone)])))), id: AttrId(30), style: Inner, span: ice/src/lib.rs:1:1: 1:31 (#4) }]', compiler/rustc_ast/src/tokenstream.rs:224:33
stack backtrace:
   0: _rust_begin_unwind
   1: std::panicking::begin_panic_fmt
   2: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
   3: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
   4: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   5: rustc_ast::tokenstream::AttrAnnotatedTokenStream::to_tokenstream
   6: rustc_parse::prepend_attrs
   7: rustc_parse::nt_to_tokenstream
   8: <rustc_expand::proc_macro::ProcMacroDerive as rustc_expand::base::MultiItemModifier>::expand
   9: rustc_expand::expand::MacroExpander::fully_expand_fragment
  10: rustc_expand::expand::MacroExpander::expand_crate
  11: rustc_session::utils::<impl rustc_session::session::Session>::time
  12: rustc_interface::passes::configure_and_expand_inner
  13: rustc_interface::passes::boxed_resolver::BoxedResolver::new
  14: rustc_interface::queries::Queries::expansion
  15: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  16: rustc_span::with_source_map
  17: rustc_interface::interface::create_compiler_and_run
  18: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0 (a178d0322 2021-07-26) running on aarch64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: aborting due to previous error

Activity

added
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 11, 2021
added
A-attributesArea: Attributes (`#[…]`, `#![…]`)
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 11, 2021
apiraino

apiraino commented on Aug 12, 2021

@apiraino
Contributor

@EliseZeroTwo can you please also provide the cargo.toml configuration to reproduce an mcve for your issue? thanks

EliseZeroTwo

EliseZeroTwo commented on Aug 12, 2021

@EliseZeroTwo
ContributorAuthor

Sure, sorry for forgetting, here is the mcve: https://gitlab.com/elise/ice-0

But incase you dont want to see the entire project the Cargo.toml for the macro was just:

[package]
name = "ice-macros"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

[dependencies]
quote = "1.0.9"

And the Cargo.toml of the project to use the macro (and trigger the ICE) was:

[package]
name = "ice"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ice-macros = { path = "../ice-macros"}
serde = { version = "1", features = ["derive"] }
apiraino

apiraino commented on Aug 12, 2021

@apiraino
Contributor

Cool, thank you! Here's the result of a bisection: seems to point to PR #82608 cc @Aaron1011

searched nightlies: from nightly-2021-01-01 to nightly-2021-08-11
regressed nightly: nightly-2021-04-12
searched commits: from a836d9b to a866124
regressed commit: ba6275b

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2021-01-01 --regress ice 
apiraino

apiraino commented on Aug 12, 2021

@apiraino
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 12, 2021
added a commit that references this issue on Oct 27, 2021

Rollup merge of rust-lang#90267 - EliseZeroTwo:elisezerotwo/fix_inval…

17d1742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jonas-schievink@apiraino@EliseZeroTwo@rustbot

      Issue actions

        ICE "Found outer attribute Attribute" · Issue #87936 · rust-lang/rust