Skip to content

[ICE]: don't parse a statement if you see } #159989

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

fn main() {
    for<> || -> () {};
    
    for<'a> || -> () |_;
    
     
    
}

original:

fn main() {
    for<> || -> () {};
    //~^ ERROR `for<...>` binders for closures are experimental
    for<'a> || -> () |_;
    //~^ ERROR `for<...>` binders for closures are experimental
    for<'a, 'a> |_: &'a ()| -> () {};
    //~^ ERROR `for<...>` binders for closures are experimental
}

Version information

rustc 1.99.0-nightly (dfbea5bc9 2026-07-26)
binary: rustc
commit-hash: dfbea5bc945a9d7ff017d3d4bfbd1af9295fe5b8
commit-date: 2026-07-26
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Possibly related line of code:

} else if self.eat(exp!(Semi)) {
// Do not attempt to parse an expression if we're done here.
self.error_outer_attrs(attrs)?;
self.mk_stmt(lo, StmtKind::Empty)
} else if self.token == token::CloseBrace {
self.error_outer_attrs(attrs)?;
self.dcx().span_bug(self.token.span, "don't parse a statement if you see `}`");
} else {
// Remainder are line-expr stmts. This is similar to the `parse_stmt_path_start` case
// above.
let restrictions =
if force_full_expr { Restrictions::empty() } else { Restrictions::STMT_EXPR };
let e = self.collect_tokens(

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: internal compiler error: don't parse a statement if you see `}`
 --> /tmp/icemaker_global_tempdir.YXfZAcAri1AU/rustc_testrunner_tmpdir_reporting.Vge3Xnr9XCPu/mvce.rs:8:1
  |
8 | }
  | ^


thread 'rustc' (2147360) panicked at /rustc-dev/dfbea5bc945a9d7ff017d3d4bfbd1af9295fe5b8/compiler/rustc_parse/src/parser/stmt.rs:171:24:
Box<dyn Any>
stack backtrace:
   0:     0x7eff23047286 - <<std[9385d3d5237024da]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[930210027468071a]::fmt::Display>::fmt
   1:     0x7eff2360d912 - core[930210027468071a]::fmt::write
   2:     0x7eff2305c3dc - <std[9385d3d5237024da]::sys::stdio::unix::Stderr as core[930210027468071a]::io::write::Write>::write_fmt
   3:     0x7eff23018eba - std[9385d3d5237024da]::panicking::default_hook::{closure#0}
   4:     0x7eff23039923 - std[9385d3d5237024da]::panicking::default_hook
   5:     0x7eff21fb69eb - std[9385d3d5237024da]::panicking::update_hook::<alloc[9a0bfe16f00ccf17]::boxed::Box<rustc_driver_impl[c4303933fd0bc786]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7eff23039dc2 - std[9385d3d5237024da]::panicking::panic_with_hook
   7:     0x7eff21fe3fa4 - std[9385d3d5237024da]::panicking::begin_panic::<rustc_errors[957e6af7b9ce008a]::ExplicitBug>::{closure#0}
   8:     0x7eff21fdcd26 - std[9385d3d5237024da]::sys::backtrace::__rust_end_short_backtrace::<std[9385d3d5237024da]::panicking::begin_panic<rustc_errors[957e6af7b9ce008a]::ExplicitBug>::{closure#0}, !>
   9:     0x7eff21fdccdb - std[9385d3d5237024da]::panicking::begin_panic::<rustc_errors[957e6af7b9ce008a]::ExplicitBug>
  10:     0x7eff21fefb51 - <rustc_errors[957e6af7b9ce008a]::diagnostic::BugAbort as rustc_errors[957e6af7b9ce008a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7eff22830b15 - <rustc_errors[957e6af7b9ce008a]::DiagCtxtHandle>::span_bug::<rustc_span[1c06c81eaf792beb]::span_encoding::Span, &str>
  12:     0x7eff2371add1 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_stmt_without_recovery
  13:     0x7eff1fc499a6 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::recover_missing_braces_around_closure_body
  14:     0x7eff237809fe - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::collect_tokens_for_expr::<<rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_dot_or_call::{closure#0}>
  15:     0x7eff23759bcb - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_prefix
  16:     0x7eff237622c5 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_assoc_with
  17:     0x7eff24294924 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_closure
  18:     0x7eff2376a12c - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::collect_tokens_for_expr::<<rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_dot_or_call::{closure#0}>
  19:     0x7eff23759bcb - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_prefix
  20:     0x7eff237622c5 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_expr_assoc_with
  21:     0x7eff23716f19 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_stmt_without_recovery
  22:     0x7eff2371e2be - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_block_common
  23:     0x7eff23710c7d - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_fn
  24:     0x7eff237b77ac - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_item_kind
  25:     0x7eff237b2dda - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_item_common
  26:     0x7eff23754554 - <rustc_parse[4f78c5ebe9dcb452]::parser::Parser>::parse_mod
  27:     0x7eff24512bfd - rustc_interface[4226e4c0792ce910]::passes::parse
  28:     0x7eff247d8b50 - rustc_interface[4226e4c0792ce910]::interface::run_compiler::<(), rustc_driver_impl[c4303933fd0bc786]::run_compiler::{closure#0}>::{closure#2}
  29:     0x7eff246f4f64 - std[9385d3d5237024da]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4226e4c0792ce910]::util::run_in_thread_with_globals<rustc_interface[4226e4c0792ce910]::util::run_in_thread_pool_with_globals<rustc_interface[4226e4c0792ce910]::interface::run_compiler<(), rustc_driver_impl[c4303933fd0bc786]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  30:     0x7eff246f4d33 - <std[9385d3d5237024da]::thread::lifecycle::spawn_unchecked<rustc_interface[4226e4c0792ce910]::util::run_in_thread_with_globals<rustc_interface[4226e4c0792ce910]::util::run_in_thread_pool_with_globals<rustc_interface[4226e4c0792ce910]::interface::run_compiler<(), rustc_driver_impl[c4303933fd0bc786]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[930210027468071a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7eff246ffafa - <std[9385d3d5237024da]::sys::thread::unix::Thread>::new::thread_start
  32:     0x7eff1de97739 - <unknown>
  33:     0x7eff1df1bedc - <unknown>
  34:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.99.0-nightly (dfbea5bc9 2026-07-26) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 1 previous error


Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-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