rust-lang / rust-lang/rust

[ICE]: expected region '{region error} to be of kind ReVar

Open
#156,311 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-reborrow I-ICE needs-triage T-compiler WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

//@compile-flags: -Znext-solver=globally
#![feature(reborrow)]
use std::marker::{CoerceShared, Reborrow};

struct CustomMut<'a, T>(&'a mut T);

impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {}

struct CustomRef<'a, T>(&'CustomMut T);

fn method(_a: CustomRef<'_, ()>) {}

fn main() {
    let a = CustomMut(&mut ());
    method(a);
}

original:

//@ run-pass

#![feature(reborrow)]
use std::marker::{CoerceShared, Reborrow};

#[allow(unused)]
struct CustomMut<'a, T>(&'a mut T);
impl<'a, T> Reborrow for CustomMut<'a, T> {
    fn clone(&self) -> Self {
        Self(self.0)
    }
}
impl<'a, T> CoerceShared<CustomRef<'a, T>> for CustomMut<'reborrow, T> {}

struct CustomRef<'a, T>(&'CustomMut T);

impl<'a, T> Clone for CoerceShared<CustomRef<'a, T>> {
    fn clone(&self) -> Self {
        Self(self.0)
    }
}
impl<'a, T> Copy for CustomRef<'a, T> {}

fn method(_a: CustomRef<'_, ()>) {}

fn main() {
    let a = CustomMut(&mut ());
    method(a);
}

Version information

rustc 1.97.0-nightly (3e353d735 2026-05-08)
binary: rustc
commit-hash: 3e353d7353b0cd6fa4eefd5c882457cc2708184c
commit-date: 2026-05-08
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Possibly related line of code:
https://github.com/rust-lang/rust/blob/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_middle/src/ty/region.rs#L323-L335

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=globally

Program output

error[E0261]: use of undeclared lifetime name `'reborrow`
 --> /tmp/icemaker_global_tempdir.dtYE6wFp6BMl/rustc_testrunner_tmpdir_reporting.kFLBoocGaF3W/mvce.rs:6:40
  |
6 | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {}
  |                                        ^^^^^^^^^ undeclared lifetime
  |
help: consider introducing lifetime `'reborrow` here
  |
6 | impl<'reborrow, 'a, T> CoerceShared for CustomMut<'reborrow, T> {}
  |      ++++++++++

error[E0261]: use of undeclared lifetime name `'CustomMut`
 --> /tmp/icemaker_global_tempdir.dtYE6wFp6BMl/rustc_testrunner_tmpdir_reporting.kFLBoocGaF3W/mvce.rs:8:26
  |
8 | struct CustomRef<'a, T>(&'CustomMut T);
  |                          ^^^^^^^^^^ undeclared lifetime
  |
help: consider introducing lifetime `'CustomMut` here
  |
8 | struct CustomRef<'CustomMut, 'a, T>(&'CustomMut T);
  |                  +++++++++++

warning: unused import: `Reborrow`
 --> /tmp/icemaker_global_tempdir.dtYE6wFp6BMl/rustc_testrunner_tmpdir_reporting.kFLBoocGaF3W/mvce.rs:2:33
  |
2 | use std::marker::{CoerceShared, Reborrow};
  |                                 ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

error[E0107]: missing generics for trait `CoerceShared`
    --> /tmp/icemaker_global_tempdir.dtYE6wFp6BMl/rustc_testrunner_tmpdir_reporting.kFLBoocGaF3W/mvce.rs:6:13
     |
   6 | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {}
     |             ^^^^^^^^^^^^ expected 1 generic argument
     |
note: trait defined here, with 1 generic parameter: `Target`
    --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/marker.rs:1363:11
     |
1363 | pub trait CoerceShared<Target: Copy>: Reborrow {
     |           ^^^^^^^^^^^^ ------
help: add missing generic argument
     |
   6 | impl<'a, T> CoerceShared<Target> for CustomMut<'reborrow, T> {}
     |                         ++++++++

error[E0377]: the trait `CoerceShared` may only be implemented for a coercion between structures
 --> /tmp/icemaker_global_tempdir.dtYE6wFp6BMl/rustc_testrunner_tmpdir_reporting.kFLBoocGaF3W/mvce.rs:6:1
  |
6 | impl<'a, T> CoerceShared for CustomMut<'reborrow, T> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: /rustc-dev/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_middle/src/ty/region.rs:329:18: expected region '{region error} to be of kind ReVar


thread 'rustc' (4171729) panicked at /rustc-dev/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_middle/src/ty/region.rs:329:18:
Box<dyn Any>
stack backtrace:
   0:     0x7f7d48474239 - <<std[db65628f2330fd11]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[b3c617e8375f9bd0]::fmt::Display>::fmt
   1:     0x7f7d48a1b788 - core[b3c617e8375f9bd0]::fmt::write
   2:     0x7f7d4848ac66 - <std[db65628f2330fd11]::sys::stdio::unix::Stderr as std[db65628f2330fd11]::io::Write>::write_fmt
   3:     0x7f7d4844a2de - std[db65628f2330fd11]::panicking::default_hook::{closure#0}
   4:     0x7f7d484678f3 - std[db65628f2330fd11]::panicking::default_hook
   5:     0x7f7d473544d1 - std[db65628f2330fd11]::panicking::update_hook::<alloc[b10a1c065189447]::boxed::Box<rustc_driver_impl[1f444ccaa450aabc]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f7d48467bd2 - std[db65628f2330fd11]::panicking::panic_with_hook
   7:     0x7f7d47381f51 - std[db65628f2330fd11]::panicking::begin_panic::<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>::{closure#0}
   8:     0x7f7d4737af46 - std[db65628f2330fd11]::sys::backtrace::__rust_end_short_backtrace::<std[db65628f2330fd11]::panicking::begin_panic<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>::{closure#0}, !>
   9:     0x7f7d4737acab - std[db65628f2330fd11]::panicking::begin_panic::<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>
  10:     0x7f7d4738d431 - <rustc_errors[4e25407aa9dfcb98]::diagnostic::BugAbort as rustc_errors[4e25407aa9dfcb98]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f7d4799cf69 - rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt::<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}
  12:     0x7f7d4799d0d2 - rustc_middle[4a2cff3451d2bad5]::ty::context::tls::with_opt::<rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7f7d4798b82b - rustc_middle[4a2cff3451d2bad5]::ty::context::tls::with_context_opt::<rustc_middle[4a2cff3451d2bad5]::ty::context::tls::with_opt<rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7f7d45331134 - rustc_middle[4a2cff3451d2bad5]::util::bug::bug_fmt
  15:     0x7f7d4a9450e9 - <rustc_middle[4a2cff3451d2bad5]::ty::region::Region>::as_var.cold
  16:     0x7f7d498c22f6 - <rustc_borrowck[543291a75b63dc2a]::type_check::TypeChecker as rustc_middle[4a2cff3451d2bad5]::mir::visit::Visitor>::visit_body
  17:     0x7f7d4987286c - rustc_borrowck[543291a75b63dc2a]::type_check::type_check
  18:     0x7f7d494d7176 - <rustc_borrowck[543291a75b63dc2a]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  19:     0x7f7d494d2b1b - rustc_borrowck[543291a75b63dc2a]::mir_borrowck
  20:     0x7f7d494d28e9 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  21:     0x7f7d48b6d6a6 - rustc_query_impl[3b9ecabc2cca1a8f]::execution::try_execute_query::<rustc_data_structures[4a3bb46d707d6722]::vec_cache::VecCache<rustc_span[749aae40fdac821d]::def_id::LocalDefId, rustc_middle[4a2cff3451d2bad5]::query::erase::ErasedData<[u8; 8usize]>, rustc_middle[4a2cff3451d2bad5]::dep_graph::graph::DepNodeIndex>, false>
  22:     0x7f7d48b6fdc3 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7f7d48b6ff94 - <rustc_middle[4a2cff3451d2bad5]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[232b63f46aa35c0e]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  24:     0x7f7d48b6f276 - rustc_interface[232b63f46aa35c0e]::passes::analysis
  25:     0x7f7d49b822c9 - rustc_query_impl[3b9ecabc2cca1a8f]::execution::try_execute_query::<rustc_middle[4a2cff3451d2bad5]::query::caches::SingleCache<rustc_middle[4a2cff3451d2bad5]::query::erase::ErasedData<[u8; 0usize]>>, false>
  26:     0x7f7d49b81f33 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  27:     0x7f7d49bc765b - rustc_interface[232b63f46aa35c0e]::interface::run_compiler::<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}
  28:     0x7f7d49b75c3e - std[db65628f2330fd11]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_with_globals<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_pool_with_globals<rustc_interface[232b63f46aa35c0e]::interface::run_compiler<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  29:     0x7f7d49b7632d - <std[db65628f2330fd11]::thread::lifecycle::spawn_unchecked<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_with_globals<rustc_interface[232b63f46aa35c0e]::util::run_in_thread_pool_with_globals<rustc_interface[232b63f46aa35c0e]::interface::run_compiler<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[b3c617e8375f9bd0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7f7d49b7712c - <std[db65628f2330fd11]::sys::thread::unix::Thread>::new::thread_start
  31:     0x7f7d436a597a - <unknown>
  32:     0x7f7d437292bc - <unknown>
  33:                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.97.0-nightly (3e353d735 2026-05-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [mir_borrowck] borrow-checking `main`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0107, E0261, E0377.
For more information about an error, try `rustc --explain E0107`.

@rustbot label +F-reborrow +WG-trait-system-refactor

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reduced Rust program in a.rs and reproduce it using rustc -Znext-solver=globally. Read compiler/rustc_middle/src/ty/region.rs around lines 323-335, then follow the reported mir_borrowck query and rustc_borrowck type-checking path. Done means the case produces a normal compiler diagnostic without an internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.