Skip to content

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

Closed

Description

@matthiaskrgr

snippet:

fn main() { pub }

Version information

rustc 1.99.0-nightly (d3663963c 2026-07-29)
binary: rustc
commit-hash: d3663963ca08f465d01d283a7199778902623bb9
commit-date: 2026-07-29
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: visibility `pub` is not followed by an item
 --> /tmp/icemaker_global_tempdir.85Auzek59MzW/rustc_testrunner_tmpdir_reporting.IMYecndfGNap/mvce.rs:1:13
  |
1 | fn main() { pub }
  |             ^^^ the visibility
  |
  = help: you likely meant to define an item, e.g., `pub fn foo() {}`

error: internal compiler error: don't parse a statement if you see `}`
 --> /tmp/icemaker_global_tempdir.85Auzek59MzW/rustc_testrunner_tmpdir_reporting.IMYecndfGNap/mvce.rs:1:17
  |
1 | fn main() { pub }
  |                 ^


thread 'rustc' (1821747) panicked at /rustc-dev/d3663963ca08f465d01d283a7199778902623bb9/compiler/rustc_parse/src/parser/stmt.rs:173:24:
Box<dyn Any>
stack backtrace:
   0:     0x7fc8384b3046 - <<std[de18a84e87bef96]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[11760cdd6396813d]::fmt::Display>::fmt
   1:     0x7fc838c0ad52 - core[11760cdd6396813d]::fmt::write
   2:     0x7fc8384c818c - <std[de18a84e87bef96]::sys::stdio::unix::Stderr as core[11760cdd6396813d]::io::write::Write>::write_fmt
   3:     0x7fc838484c1a - std[de18a84e87bef96]::panicking::default_hook::{closure#0}
   4:     0x7fc8384a5723 - std[de18a84e87bef96]::panicking::default_hook
   5:     0x7fc837419e0b - std[de18a84e87bef96]::panicking::update_hook::<alloc[6d2f5dc59fc5ad00]::boxed::Box<rustc_driver_impl[80ca0a791fc64eb4]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc8384a5bc2 - std[de18a84e87bef96]::panicking::panic_with_hook
   7:     0x7fc837447bd4 - std[de18a84e87bef96]::panicking::begin_panic::<rustc_errors[3360ec22066709a2]::ExplicitBug>::{closure#0}
   8:     0x7fc837440926 - std[de18a84e87bef96]::sys::backtrace::__rust_end_short_backtrace::<std[de18a84e87bef96]::panicking::begin_panic<rustc_errors[3360ec22066709a2]::ExplicitBug>::{closure#0}, !>
   9:     0x7fc83743e967 - std[de18a84e87bef96]::panicking::begin_panic::<rustc_errors[3360ec22066709a2]::ExplicitBug>
  10:     0x7fc837453781 - <rustc_errors[3360ec22066709a2]::diagnostic::BugAbort as rustc_errors[3360ec22066709a2]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fc837c9c175 - <rustc_errors[3360ec22066709a2]::DiagCtxtHandle>::span_bug::<rustc_span[22444b93dc8c3ee6]::span_encoding::Span, &str>
  12:     0x7fc838d03070 - <rustc_parse[cfe3938aa4a232f5]::parser::Parser>::parse_stmt_without_recovery
  13:     0x7fc838cfa4a6 - <rustc_parse[cfe3938aa4a232f5]::parser::Parser>::parse_block_common
  14:     0x7fc838d09c3d - <rustc_parse[cfe3938aa4a232f5]::parser::Parser>::parse_fn
  15:     0x7fc838d8e92c - <rustc_parse[cfe3938aa4a232f5]::parser::Parser>::parse_item_kind
  16:     0x7fc838d89f5a - <rustc_parse[cfe3938aa4a232f5]::parser::Parser>::parse_item_common
  17:     0x7fc838d3ddd4 - <rustc_parse[cfe3938aa4a232f5]::parser::Parser>::parse_mod
  18:     0x7fc839d75abd - rustc_interface[2e32ffefb2ac5795]::passes::parse
  19:     0x7fc839d87750 - rustc_interface[2e32ffefb2ac5795]::interface::run_compiler::<(), rustc_driver_impl[80ca0a791fc64eb4]::run_compiler::{closure#0}>::{closure#2}
  20:     0x7fc839e05f24 - std[de18a84e87bef96]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2e32ffefb2ac5795]::util::run_in_thread_with_globals<rustc_interface[2e32ffefb2ac5795]::util::run_in_thread_pool_with_globals<rustc_interface[2e32ffefb2ac5795]::interface::run_compiler<(), rustc_driver_impl[80ca0a791fc64eb4]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  21:     0x7fc839e05ced - <std[de18a84e87bef96]::thread::lifecycle::spawn_unchecked<rustc_interface[2e32ffefb2ac5795]::util::run_in_thread_with_globals<rustc_interface[2e32ffefb2ac5795]::util::run_in_thread_pool_with_globals<rustc_interface[2e32ffefb2ac5795]::interface::run_compiler<(), rustc_driver_impl[80ca0a791fc64eb4]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[11760cdd6396813d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  22:     0x7fc839e1207a - <std[de18a84e87bef96]::sys::thread::unix::Thread>::new::thread_start
  23:     0x7fc833297739 - <unknown>
  24:     0x7fc83331bedc - <unknown>
  25:                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 (d3663963c 2026-07-29) running on x86_64-unknown-linux-gnu

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


Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on Jul 29, 2026
  2. added
    needs-triage
    on Jul 29, 2026
  3. self-assigned this
    on Jul 30, 2026
  4. added
    A-parser
    and removed
    needs-triage
    on Jul 30, 2026
  5. chenyukang commented on Jul 30, 2026

    @chenyukang
    Member

    introduced by #159849

  6. added 2 commits that reference this issue on Jul 30, 2026
    f9eab85
    d7f1ae6
  7. added a commit that references this issue on Jul 31, 2026
    c7b156b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-parserC-bugI-ICET-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions