Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE "Found outer attribute Attribute" #87936

Closed
EliseZeroTwo opened this issue Aug 11, 2021 · 4 comments · Fixed by #90267
Closed

ICE "Found outer attribute Attribute" #87936

EliseZeroTwo opened this issue Aug 11, 2021 · 4 comments · Fixed by #90267
Labels
A-attributes Area: #[attributes(..)] A-proc-macros Area: Procedural macros C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@EliseZeroTwo
Copy link
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

@EliseZeroTwo EliseZeroTwo added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2021
@jonas-schievink jonas-schievink added A-attributes Area: #[attributes(..)] A-proc-macros Area: Procedural macros I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 11, 2021
@apiraino
Copy link
Contributor

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

@EliseZeroTwo
Copy link
Contributor Author

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
Copy link
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
Copy link
Contributor

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

@rustbot label -I-prioritize +P-medium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: #[attributes(..)] A-proc-macros Area: Procedural macros C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants