Skip to content

ICE: region variables should not be hashed #148620

@cushionbadak

Description

@cushionbadak

Code

#![feature(associated_const_equality)]

trait Trait<'a> {
    const K: &'a ();
}

fn main() -> Trait<'r, K = { &() }> {
    let x = Ok(42);
    if true {
        x?
    }

    Ok(())
}

A mutant of tests/ui/suggestions/try-operator-dont-suggest-semicolon.rs

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (c90bcb957 2025-11-06)
binary: rustc
commit-hash: c90bcb9571b7aab0d8beaa2ce8a998ffaf079d38
commit-date: 2025-11-06
host: x86_64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.3

Error output

Command: rustc

error[E0261]: use of undeclared lifetime name `'r`
 --> 02.rs:7:20
  |
7 | fn main() -> Trait<'r, K = { &() }> {
  |                    ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'r` lifetime
  |
7 | fn main() -> for<'r> Trait<'r, K = { &() }> {
  |              +++++++
help: consider introducing lifetime `'r` here
  |
7 | fn main<'r>() -> Trait<'r, K = { &() }> {
  |        ++++

warning: trait objects without an explicit `dyn` are deprecated
 --> 02.rs:7:14
  |
7 | fn main() -> Trait<'r, K = { &() }> {
  |              ^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
help: if this is a dyn-compatible trait, use `dyn`
  |
7 | fn main() -> dyn Trait<'r, K = { &() }> {
  |              +++


thread 'rustc' (5492753) panicked at /rustc-dev/c90bcb9571b7aab0d8beaa2ce8a998ffaf079d38/compiler/rustc_type_ir/src/region_kind.rs:240:17:
region variables should not be hashed: '?0
Backtrace

thread 'rustc' (5492753) panicked at /rustc-dev/c90bcb9571b7aab0d8beaa2ce8a998ffaf079d38/compiler/rustc_type_ir/src/region_kind.rs:240:17:
region variables should not be hashed: '?0
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_middle::ty::region::Region as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable
   3: <rustc_type_ir::ty_kind::TyKind<rustc_middle::ty::context::TyCtxt> as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable
   4: <rustc_type_ir::ty_info::WithCachedTypeInfo<rustc_type_ir::ty_kind::TyKind<rustc_middle::ty::context::TyCtxt>> as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable
   5: <rustc_middle::ty::context::TyCtxt>::feed_anon_const_type
   6: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_poly_trait_ref
   7: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_trait_object_ty::{closure#0}
   8: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty::{closure#0}
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::suggest_missing_break_or_return_expr
  10: <rustc_hir_typeck::coercion::CoerceMany<&rustc_hir::hir::Expr>>::report_return_mismatched_types
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_or_body_tail
  18: rustc_hir_typeck::check::check_fn
  19: rustc_hir_typeck::typeck_with_inspect::{closure#0}
  20: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
  21: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  22: rustc_hir_analysis::check_crate
  23: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  24: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  25: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/Users/jb/Library/CloudStorage/Dropbox/Desk/2503_rustc_ice/20251106 ice 보고용/rustc-ice-2025-11-07T04_18_08-52917.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on crate `02`
end of query stack
error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0261`.

Notes

  • ICE location: compiler/rustc_type_ir/src/region_kind.rs line-240

    ReLateParam(r) => {
    r.hash_stable(hcx, hasher);
    }
    RePlaceholder(r) => {
    r.hash_stable(hcx, hasher);
    }
    ReVar(_) => {
    panic!("region variables should not be hashed: {self:?}")
    }

  • Duplication Check

    • I searched for ICE issues with "region variables should not be hashed", (Github issue page with query)
    • issue-112397 is opened with identical ICE location report, but none of the code in that issue cause ICE in current compiler version.

@rustbot label +F-associated_const_equality

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-associated_const_equality`#![feature(associated_const_equality)]`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.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions