Skip to content

Invalid proc_macro example causes internal error: entered unreachable code #99478

Open
@0rphon

Description

@0rphon

The following is invalid code that should cause a compilation error but instead causes the compiler to crash on both stable and nightly.

Code

proc macro:

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn tester(_: TokenStream, _: TokenStream) -> TokenStream {
    panic!();
}

main.rs

#![playground_macro::tester]

fn main() {}

Meta

rustc --version --verbose:

rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-pc-windows-msvc
release: 1.62.1
LLVM version: 14.0.5

also exists on nightly:

rustc 1.64.0-nightly (f8588549c 2022-07-18)
binary: rustc
commit-hash: f8588549c3c3d45c32b404210cada01e2a45def3
commit-date: 2022-07-18
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

E:\coding\playground>cargo run
   Compiling playground v0.1.0 (E:\coding\playground\playground)
error[E0658]: inner macro attributes are unstable
 --> playground\src\main.rs:1:4
  |
1 | #![playground_macro::tester]
  |    ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information

error: custom attribute panicked
 --> playground\src\main.rs:1:1
  |
1 | #![playground_macro::tester]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: explicit panic

thread 'rustc' panicked at 'internal error: entered unreachable code', compiler\rustc_expand\src\base.rs:436:9
stack backtrace:
   0:     0x7fff8a75994f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h179779de1f45f3d7
   1:     0x7fff8a79492a - core::fmt::write::h550798e7478df3ee
   2:     0x7fff8a74bf79 - <std::io::IoSlice as core::fmt::Debug>::fmt::haf0965e87654d72f
   3:     0x7fff8a75d1fb - std::panicking::default_hook::hfe90f75dfb2f2638
   4:     0x7fff8a75cdee - std::panicking::default_hook::hfe90f75dfb2f2638
   5:     0x7fff7d94f679 - <rustc_middle[677a8a964d5b21dc]::ty::SymbolName as core[4a1975f242dc1ae1]::fmt::Debug>::fmt
   6:     0x7fff8a75dada - std::panicking::rust_panic_with_hook::h699a264298ffd2b1
   7:     0x7fff8a75d7f2 - <std::panicking::begin_panic_handler::StrPanicPayload as core::panic::BoxMeUp>::get::h82324bc0a50ada1a
   8:     0x7fff8a75a507 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h179779de1f45f3d7
   9:     0x7fff8a75d509 - rust_begin_unwind
  10:     0x7fff8a7c8475 - core::panicking::panic_fmt::haa7f67cdcdeb9cea
  11:     0x7fff8a7c831c - core::panicking::panic::h13e986a401f2dc97
  12:     0x7fff816846be - <rustc_expand[9693b9b8a38cdfb5]::base::Annotatable>::expect_crate
  13:     0x7fff816d03a0 - <rustc_expand[9693b9b8a38cdfb5]::expand::AstFragmentKind>::name
  14:     0x7fff816bb437 - <rustc_expand[9693b9b8a38cdfb5]::expand::MacroExpander>::fully_expand_fragment
  15:     0x7fff816b8abf - <rustc_expand[9693b9b8a38cdfb5]::expand::MacroExpander>::expand_crate
  16:     0x7fff7daad88e - rustc_interface[a3fc17c5c19ff554]::passes::analysis
  17:     0x7fff7da68a8e - <rustc_interface[a3fc17c5c19ff554]::passes::LintStoreExpandImpl as rustc_expand[9693b9b8a38cdfb5]::base::LintStoreExpand>::pre_expansion_lint
  18:     0x7fff7da4918d - <rustc_interface[a3fc17c5c19ff554]::queries::Queries>::expansion
  19:     0x7fff7d8de27e - <rustc_target[4b3bc41a4b72ff80]::asm::msp430::Msp430InlineAsmReg>::reg_class
  20:     0x7fff7d9621c5 - rustc_driver[32690c61b3c47841]::pretty::print_after_hir_lowering
  21:     0x7fff7d8ff9a0 - <rustc_target[4b3bc41a4b72ff80]::asm::msp430::Msp430InlineAsmReg>::reg_class
  22:     0x7fff7d903087 - <rustc_target[4b3bc41a4b72ff80]::asm::msp430::Msp430InlineAsmReg>::reg_class
  23:     0x7fff7d90d166 - <rustc_driver[32690c61b3c47841]::args::Error as core[4a1975f242dc1ae1]::fmt::Debug>::fmt
  24:     0x7fff7d90e288 - <rustc_driver[32690c61b3c47841]::args::Error as core[4a1975f242dc1ae1]::fmt::Debug>::fmt
  25:     0x7fff8a76edac - std::sys::windows::thread::Thread::new::h0e2fb5b30b10e287
  26:     0x7ff8131c7034 - BaseThreadInitThunk
  27:     0x7ff8133a2651 - 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.62.1 (e092d0b6b 2022-07-16) running on x86_64-pc-windows-msvc

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

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

query stack during panic:
end of query stack
For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground` due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-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