Skip to content

ICE parse_expected_identifier_found_keyword_str #149692

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

macro str($nt_item: item) {
    // OK
}

// OK

str!(Self { field });

// OK

original:

// Check that we are refusing to match on complex nonterminals for which tokens are
// unavailable and we'd have to go through AST comparisons.



str!(enum E {});

macro str($nt_item: item) {
    macro n(a $nt_item b) {
        struct S;
    }

    n!(a $nt_item b); // OK
}

str!(a, 'a, (x, y, z)); // OK

str!(Self { field });

str!(a, 'a, (x, y, z)); // OK

str!(enum E {});

str!(enum E {});

Version information

rustc 1.93.0-nightly (66428d92b 2025-12-05)
binary: rustc
commit-hash: 66428d92bec337ed4785d695d0127276a482278c
commit-date: 2025-12-05
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Possibly related line of code:

let ident = if self.token.is_ident()
&& (!is_const || self.look_ahead(1, |t| *t == token::OpenParen))
&& self.look_ahead(1, |t| {
matches!(t.kind, token::Lt | token::OpenBrace | token::OpenParen)
}) {
self.parse_ident().unwrap()
} else {
return Ok(());
};
let mut found_generics = false;
if self.check(exp!(Lt)) {

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

Program output


thread 'rustc' (2641208) panicked at compiler/rustc_parse/src/parser/item.rs:400:32:
called `Result::unwrap()` on an `Err` value: Some(DiagInner { level: Error, messages: [(FluentIdentifier("parse_expected_identifier_found_keyword_str", None), NoStyle)], code: None, lint_id: None, span: MultiSpan { primary_spans: [/tmp/icemaker_global_tempdir.XPzOU6e7yJCI/rustc_testrunner_tmpdir_reporting.vyUalTd7Z3Iq/mvce.rs:7:6: 7:10 (#0)], span_labels: [(/tmp/icemaker_global_tempdir.XPzOU6e7yJCI/rustc_testrunner_tmpdir_reporting.vyUalTd7Z3Iq/mvce.rs:7:6: 7:10 (#0), Translated("expected identifier, found keyword"))] }, children: [], suggestions: Enabled([]), args: {"token": Str("Self")}, reserved_args: {}, sort_span: /tmp/icemaker_global_tempdir.XPzOU6e7yJCI/rustc_testrunner_tmpdir_reporting.vyUalTd7Z3Iq/mvce.rs:7:6: 7:10 (#0), is_lint: None, long_ty_path: None, emitted_at: DiagLocation { file: "compiler/rustc_parse/src/parser/diagnostics.rs", line: 381, col: 34 } })
stack backtrace:
   0:     0x7ff47ce6f6b3 - <<std[d1cf8494b7637499]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[7a5baad27c58ac9b]::fmt::Display>::fmt
   1:     0x7ff47d411848 - core[7a5baad27c58ac9b]::fmt::write
   2:     0x7ff47ce85ed6 - <std[d1cf8494b7637499]::sys::stdio::unix::Stderr as std[d1cf8494b7637499]::io::Write>::write_fmt
   3:     0x7ff47ce45e78 - std[d1cf8494b7637499]::panicking::default_hook::{closure#0}
   4:     0x7ff47ce63583 - std[d1cf8494b7637499]::panicking::default_hook
   5:     0x7ff47becfec7 - std[d1cf8494b7637499]::panicking::update_hook::<alloc[fc8570482610e41]::boxed::Box<rustc_driver_impl[9b4b378bd639d3bd]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7ff47ce63862 - std[d1cf8494b7637499]::panicking::panic_with_hook
   7:     0x7ff47ce45f38 - std[d1cf8494b7637499]::panicking::panic_handler::{closure#0}
   8:     0x7ff47ce3a7e9 - std[d1cf8494b7637499]::sys::backtrace::__rust_end_short_backtrace::<std[d1cf8494b7637499]::panicking::panic_handler::{closure#0}, !>
   9:     0x7ff47ce47aed - __rustc[a3b33349d2d89bba]::rust_begin_unwind
  10:     0x7ff47a01147c - core[7a5baad27c58ac9b]::panicking::panic_fmt
  11:     0x7ff47989bba2 - core[7a5baad27c58ac9b]::result::unwrap_failed
  12:     0x7ff47ab774b8 - <rustc_parse[313e5cda521f76ea]::parser::Parser>::recover_missing_kw_before_item
  13:     0x7ff47e14c85c - <rustc_parse[313e5cda521f76ea]::parser::Parser>::parse_item_kind
  14:     0x7ff47e14befe - <rustc_parse[313e5cda521f76ea]::parser::Parser>::parse_item_kind
  15:     0x7ff47e14781a - <rustc_parse[313e5cda521f76ea]::parser::Parser>::parse_item_common
  16:     0x7ff47e92e872 - <rustc_expand[6cd70212c50627bf]::expand::MacroExpander>::fully_expand_fragment
  17:     0x7ff47e90e2ea - <rustc_expand[6cd70212c50627bf]::expand::MacroExpander>::expand_crate
  18:     0x7ff47ddf72b2 - rustc_interface[a570f551ea6bf79f]::passes::configure_and_expand
  19:     0x7ff47e901115 - rustc_interface[a570f551ea6bf79f]::passes::resolver_for_lowering_raw
  20:     0x7ff47e900e8d - rustc_query_impl[ac86e4dc6825f939]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ac86e4dc6825f939]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[35056dba64335523]::query::erase::Erased<[u8; 16usize]>>
  21:     0x7ff47e900e67 - <rustc_query_impl[ac86e4dc6825f939]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[7a5baad27c58ac9b]::ops::function::FnOnce<(rustc_middle[35056dba64335523]::ty::context::TyCtxt, ())>>::call_once
  22:     0x7ff47e56209f - rustc_query_system[59d0c891baa5ac40]::query::plumbing::try_execute_query::<rustc_query_impl[ac86e4dc6825f939]::DynamicConfig<rustc_query_system[59d0c891baa5ac40]::query::caches::SingleCache<rustc_middle[35056dba64335523]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[ac86e4dc6825f939]::plumbing::QueryCtxt, false>
  23:     0x7ff47e561bfc - rustc_query_impl[ac86e4dc6825f939]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7ff47e6f6337 - <rustc_interface[a570f551ea6bf79f]::passes::create_and_enter_global_ctxt<core[7a5baad27c58ac9b]::option::Option<rustc_interface[a570f551ea6bf79f]::queries::Linker>, rustc_driver_impl[9b4b378bd639d3bd]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[7a5baad27c58ac9b]::ops::function::FnOnce<(&rustc_session[61d9c53fe18acc9a]::session::Session, rustc_middle[35056dba64335523]::ty::context::CurrentGcx, alloc[fc8570482610e41]::sync::Arc<rustc_data_structures[adb2697dbf3e0adc]::jobserver::Proxy>, &std[d1cf8494b7637499]::sync::once_lock::OnceLock<rustc_middle[35056dba64335523]::ty::context::GlobalCtxt>, &rustc_data_structures[adb2697dbf3e0adc]::sync::worker_local::WorkerLocal<rustc_middle[35056dba64335523]::arena::Arena>, &rustc_data_structures[adb2697dbf3e0adc]::sync::worker_local::WorkerLocal<rustc_hir[670b2116001876c4]::Arena>, rustc_driver_impl[9b4b378bd639d3bd]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  25:     0x7ff47e5b8c85 - rustc_interface[a570f551ea6bf79f]::interface::run_compiler::<(), rustc_driver_impl[9b4b378bd639d3bd]::run_compiler::{closure#0}>::{closure#1}
  26:     0x7ff47e50e1d6 - std[d1cf8494b7637499]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a570f551ea6bf79f]::util::run_in_thread_with_globals<rustc_interface[a570f551ea6bf79f]::util::run_in_thread_pool_with_globals<rustc_interface[a570f551ea6bf79f]::interface::run_compiler<(), rustc_driver_impl[9b4b378bd639d3bd]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27:     0x7ff47e50dfa9 - <std[d1cf8494b7637499]::thread::lifecycle::spawn_unchecked<rustc_interface[a570f551ea6bf79f]::util::run_in_thread_with_globals<rustc_interface[a570f551ea6bf79f]::util::run_in_thread_pool_with_globals<rustc_interface[a570f551ea6bf79f]::interface::run_compiler<(), rustc_driver_impl[9b4b378bd639d3bd]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7a5baad27c58ac9b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7ff47e50c3f8 - <std[d1cf8494b7637499]::sys::thread::unix::Thread>::new::thread_start
  29:     0x7ff4780969cb - <unknown>
  30:     0x7ff47811aa0c - <unknown>
  31:                0x0 - <unknown>

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

note: rustc 1.93.0-nightly (66428d92b 2025-12-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-translationArea: Translation infrastructure, and migrating existing diagnostics to SessionDiagnosticC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-bisectionStatus: A bisection has been found for this issueT-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