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

rustc panic when annotating incorrectly #89971

Closed
moshevds opened this issue Oct 17, 2021 · 3 comments
Closed

rustc panic when annotating incorrectly #89971

moshevds opened this issue Oct 17, 2021 · 3 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

@moshevds
Copy link

Code

Cargo.toml:

[package]
name = "rustc-panic-example"
version = "0.1.0"
edition = "2018"
[dependencies]
serde = { version = "1.0.127", features = ["derive"] }

src/main.rs:

use serde::Serialize;
#![allow(unreachable_code)]
#[derive(Serialize)]
#[allow(unreachable_code)]
struct Foo(());

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (c1026539b 2021-10-15)
binary: rustc
commit-hash: c1026539bd22e9d070988deaa47b1360cbc76436
commit-date: 2021-10-15
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

Error output

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

stack backtrace:
   0: rust_begin_unwind
             at /rustc/c1026539bd22e9d070988deaa47b1360cbc76436/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/c1026539bd22e9d070988deaa47b1360cbc76436/library/core/src/panicking.rs:100:14
   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: scoped_tls::ScopedKey<T>::set

@moshevds moshevds 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 Oct 17, 2021
@ben0x539
Copy link
Contributor

Is this similar to #88938?

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: Fixed by the above PR and it has a regression test, closing.

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

4 participants