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..." with #[derive(thiserrror::Error)] and #[allow(..)] #88938

Closed
jgallagher opened this issue Sep 14, 2021 · 2 comments
Labels
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.

Comments

@jgallagher
Copy link

Code

use thiserror::Error;

#![warn(single_use_lifetimes)] // not legal here, but the ICE disappears if this is moved above the `use`

#[derive(Error)]
#[allow(single_use_lifetimes)]
enum Foo {
    #[error("blah blah")]
    Bar,
}

Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b149086e3735754ac70811ca05103814

This might be a dupe of #87936, but the combination of the #![warn(..)] placement and the fact that this is just using a proc macro led me to think it's possible it's different enough to be interesting.

Meta

rustc --version --verbose:

rustc 1.55.0 (c8dfcfe04 2021-09-06)
binary: rustc
commit-hash: c8dfcfe046a7680554bf4eb612bad840e7631c4b
commit-date: 2021-09-06
host: x86_64-apple-darwin
release: 1.55.0
LLVM version: 12.0.1

Also occurs in nightly:

rustc 1.57.0-nightly (9bb77da74 2021-09-13)
binary: rustc
commit-hash: 9bb77da74dac4768489127d21e32db19b59ada5b
commit-date: 2021-09-13
host: x86_64-apple-darwin
release: 1.57.0-nightly
LLVM version: 13.0.0

Error output

error: an inner attribute is not permitted in this context
 --> src/main.rs:3:1
  |
3 | #![warn(single_use_lifetimes)] // not legal here, but the ICE disappears if this is moved above the `use`
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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.

thread 'rustc' panicked at 'Found outer attribute Attribute { kind: Normal(AttrItem { path: Path { span: src/main.rs:6:3: 6:8 (#0), segments: [PathSegment { ident: allow#0, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: src/main.rs:6:8: 6:9 (#0), close: src/main.rs:6:29: 6:30 (#0) }, Parenthesis, TokenStream([(Token(Token { kind: Ident("single_use_lifetimes", false), span: src/main.rs:6:9: 6:29 (#0) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: src/main.rs:6:1: 6:2 (#0) }), Alone), (Delimited(DelimSpan { open: src/main.rs:6:2: 6:3 (#0), close: src/main.rs:6:30: 6:31 (#0) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("allow", false), span: src/main.rs:6:3: 6:8 (#0) }), Alone), (Delimited(DelimSpan { open: src/main.rs:6:8: 6:9 (#0), close: src/main.rs:6:29: 6:30 (#0) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("single_use_lifetimes", false), span: src/main.rs:6:9: 6:29 (#0) }), Alone)])), Alone)])), Alone)])))), id: AttrId(2), style: Outer, span: src/main.rs:6:1: 6:31 (#0) } after inner attrs [Attribute { kind: Normal(AttrItem { path: Path { span: src/main.rs:3:4: 3:8 (#0), segments: [PathSegment { ident: warn#0, id: NodeId(4294967040), args: None }], tokens: None }, args: Delimited(DelimSpan { open: src/main.rs:3:8: 3:9 (#0), close: src/main.rs:3:29: 3:30 (#0) }, Parenthesis, TokenStream([(Token(Token { kind: Ident("single_use_lifetimes", false), span: src/main.rs:3:9: 3:29 (#0) }), Alone)])), tokens: None }, Some(LazyTokenStream(AttrAnnotatedTokenStream([(Token(Token { kind: Pound, span: src/main.rs:3:1: 3:2 (#0) }), Joint), (Token(Token { kind: Not, span: src/main.rs:3:2: 3:3 (#0) }), Alone), (Delimited(DelimSpan { open: src/main.rs:3:3: 3:4 (#0), close: src/main.rs:3:30: 3:31 (#0) }, Bracket, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("warn", false), span: src/main.rs:3:4: 3:8 (#0) }), Alone), (Delimited(DelimSpan { open: src/main.rs:3:8: 3:9 (#0), close: src/main.rs:3:29: 3:30 (#0) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Ident("single_use_lifetimes", false), span: src/main.rs:3:9: 3:29 (#0) }), Alone)])), Alone)])), Alone)])))), id: AttrId(0), style: Inner, span: src/main.rs:3:1: 3:31 (#0) }]', compiler/rustc_ast/src/tokenstream.rs:224:33

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.55.0 (c8dfcfe04 2021-09-06) running on x86_64-apple-darwin

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

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

query stack during panic:
end of query stack
Backtrace

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
  13: rustc_interface::queries::Queries::expansion
  14: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  15: rustc_span::with_source_map
  16: rustc_interface::interface::create_compiler_and_run
  17: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@jgallagher jgallagher 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 Sep 14, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 27, 2021
…id_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.
@EliseZeroTwo
Copy link
Contributor

This was fixed by #90267

@JohnTitor
Copy link
Member

Triage: The above PR indeed fixed the issue and has a regression test, closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

3 participants