rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.9k stars 12.52k forks source link

ICE when an inner attribute is not permitted #89451

Closed mejrs closed 2 years ago

mejrs commented 2 years ago

This did not ICE in 1.52, but does in 1.53+. It never compiled in any version.

This regression started with nightly-2021-04-12 (see the bisect in the post below).

Playground link

Code

use f;
#![ice]
#[::tokio::main]
struct A;

Meta

rustc --version --verbose:

rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-pc-windows-msvc
release: 1.53.0
LLVM version: 12.0.1

Error output

error: an inner attribute is not permitted in this context
 --> src\lib.rs:2:1
  |
2 | #![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.

thread 'rustc' panicked at 'Failed to find trailing delimited group in: [(Token(Token { kind: Ident("struct", false), span: src\lib.rs:4:1: 4:7 (#0) }), Alone), (Token(Token { kind: Ident("A", false), span: src\lib.rs:4:8: 4:9 (#0) }), Joint), (Token(Token { kind: Semi, span: src\lib.rs:4:9: 4:10 (#0) }), Alone)]', compiler\rustc_ast\src\tokenstream.rs:277:25
Backtrace

``` stack backtrace: 0: 0x7ffe09aa574e - ::fmt::h6cc98e249320f302 1: 0x7ffe09ace88c - core::fmt::write::h85dfbe120b6ddd44 2: 0x7ffe09a99748 - ::fmt::h5e54761071278f40 3: 0x7ffe09aa97e2 - std::panicking::take_hook::h88bf14ecfdf59a5b 4: 0x7ffe09aa92c3 - std::panicking::take_hook::h88bf14ecfdf59a5b 5: 0x7ffdf752de37 - rustc_driver::report_ice::hbc044b9faaa778a2 6: 0x7ffe09aaa035 - std::panicking::rust_panic_with_hook::hbf8551f03adac8c7 7: 0x7ffe09aa9ba1 - rust_begin_unwind 8: 0x7ffe09aa609f - ::fmt::h6cc98e249320f302 9: 0x7ffe09aa9af9 - rust_begin_unwind 10: 0x7ffe09b01a6c - std::panicking::begin_panic_fmt::h68b18176e5d4f15a 11: 0x7ffdfb82dafd - ::fmt::h752c49396f0dcd1d 12: 0x7ffdfb817ee5 - ::fmt::h752c49396f0dcd1d 13: 0x7ffdfb82bf81 - ::fmt::h752c49396f0dcd1d 14: 0x7ffdfb82f308 - rustc_ast::tokenstream::AttrAnnotatedTokenStream::to_tokenstream::h63a7eb6898134dcf 15: 0x7ffdfb040fb2 - rustc_parse::nt_to_tokenstream::h54642edbd50dd653 16: 0x7ffdfb040519 - rustc_parse::nt_to_tokenstream::h54642edbd50dd653 17: 0x7ffdfade62d4 - rustc_expand::expand::MacroExpander::fully_expand_fragment::h0e95deb451ca37bb 18: 0x7ffdfade4111 - rustc_expand::expand::MacroExpander::expand_crate::h323a237c45105132 19: 0x7ffdf7667400 - rustc_interface::passes::BoxedResolver::to_resolver_outputs::h41c44f992ccd4377 20: 0x7ffdf765d359 - rustc_interface::interface::try_print_query_stack::h5efb436f8f839a83 21: 0x7ffdf764a8d3 - ::fmt::h5c2c502907d3716d 22: 0x7ffdf76652b7 - rustc_interface::interface::try_print_query_stack::h5efb436f8f839a83 23: 0x7ffdf76835a7 - rustc_interface::queries::Queries::expansion::h899b6ab63955eefe 24: 0x7ffdf7538425 - rustc_driver::pretty::print_after_hir_lowering::hc5364ea0ee4ca08c 25: 0x7ffdf7530b3c - ::fmt::h84f69d4761638945 26: 0x7ffdf7539cd2 - rustc_driver::pretty::print_after_hir_lowering::hc5364ea0ee4ca08c 27: 0x7ffdf75621c4 - ::fmt::h934311db2359d134 28: 0x7ffdf75644ef - ::fmt::h934311db2359d134 29: 0x7ffdf756ec4d - ::fmt::h934311db2359d134 30: 0x7ffe09ab817a - std::sys::windows::thread::Thread::new::h8dd2182e95caa21a 31: 0x7ffe78437034 - BaseThreadInitThunk 32: 0x7ffe79022651 - RtlUserThreadStart 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.53.0 (53cb7b09b 2021-06-17) running on x86_64-pc-windows-msvc note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib --crate-type cdylib 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 error: could not compile `my_module` To learn more, run the command again with --verbose. ```

chrismit3s commented 2 years ago

If this is an easy fix, I'd like to give it a try as my first serious contribution. But I'm probably going to need some mentoring.

@rustbot label +E-needs-mentor

mejrs commented 2 years ago

Thanks πŸ‘ I don't have the time/energy (or the expertise, for that matter) to do it myself.

For what it's worth, here is the output from bisecting this:

********************************************************************************
Regression in nightly-2021-04-12
********************************************************************************

fetching https://static.rust-lang.org/dist/2021-04-11/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-04-11: 40 B / 40 B [===============] 100.00 % 102.26 KB/s converted 2021-04-11 to a836d9b6413d9d593be6c09463ff8c4c70e56599
fetching https://static.rust-lang.org/dist/2021-04-12/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-04-12: 40 B / 40 B [===============] 100.00 % 916.96 KB/s converted 2021-04-12 to a8661245649f3d1c0dc5b23270bdac0bbd2d8f64
looking for regression commit between 2021-04-11 and 2021-04-12
opening existing repository at "rust.git"
refreshing repository
fetching (via local git) commits from a836d9b6413d9d593be6c09463ff8c4c70e56599 to a8661245649f3d1c0dc5b23270bdac0bbd2d8f64
opening existing repository at "rust.git"
refreshing repository
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 9 bors merge commits in the specified range
  commit[0] 2021-04-10UTC: Auto merge of #84016 - Aaron1011:new-preexp-tests, r=petrochenkov
  commit[1] 2021-04-10UTC: Auto merge of #84023 - Aaron1011:derive-invoc-order, r=petrochenkov
  commit[2] 2021-04-11UTC: Auto merge of #84053 - RalfJung:liballoc-miri, r=Manishearth
  commit[3] 2021-04-11UTC: Auto merge of #84071 - nagisa:nixos-patching-fix, r=Mark-Simulacrum
  commit[4] 2021-04-11UTC: Auto merge of #83806 - JohnTitor:issue-51446, r=estebank
  commit[5] 2021-04-11UTC: Auto merge of #82608 - Aaron1011:feature/final-preexp-tts, r=petrochenkov
  commit[6] 2021-04-11UTC: Auto merge of #84063 - LingMan:patch-1, r=nagisa
  commit[7] 2021-04-11UTC: Auto merge of #81469 - tweksteen:android_set_message, r=m-ou-se
  commit[8] 2021-04-11UTC: Auto merge of #83482 - hyd-dev:uwtable, r=nagisa
FabianWolff commented 2 years ago

@chrismit3s I guess this assert!() should be a delay_span_bug() instead: https://github.com/rust-lang/rust/blob/5051904d66b14d7b8dd2750bd30610c8c81cb01d/compiler/rustc_ast/src/tokenstream.rs#L276-L280

Badel2 commented 2 years ago

Not sure if this is a valid MCVE, but I found this case while fuzzing with fuzz-rustc:

#![a=#![b]c]

Playground

thread 'rustc' panicked at 'Failed to find trailing delimited group in: [(Token(Token { kind: Ident("c", false), span: src/lib.rs:1:11: 1:12 (#0) }), Alone)]', compiler/rustc_ast/src/tokenstream.rs:270:25
mejrs commented 2 years ago

This no longer ices πŸŽ‰