Skip to content

ICE "Found outer attribute Attribute" #87936

Closed

Description

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

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

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

    No branches or pull requests

    Issue actions