Skip to content

[ICE]: called Result::unwrap() on an Err value: NoSolution #156315

@matthiaskrgr

Description

@matthiaskrgr

this one triggers a different unwrap than #156309
auto-reduced (treereduce-rust):

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

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

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

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

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> {}
impl<'a, T> CoerceShared<CustomRef<'a, T>> for CustomMut<'a, T> {}

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

impl<'a, T> Clone for 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:

borrowed_ty.peel_refs(),
ty::Variance::Covariant,
dest_ty.peel_refs(),
location.to_locations(),
category,
)
.unwrap();
self.constraints.outlives_constraints.push(OutlivesConstraint {
sup: ref_region.as_var(),
sub: borrow_region.as_var(),
locations: location.to_locations(),
span: location.to_locations().span(self.body),
category,

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

Program output

error[E0106]: missing lifetime specifier
 --> /tmp/icemaker_global_tempdir.5uK8My7zlvE6/rustc_testrunner_tmpdir_reporting.tX0I7qYXjCUc/mvce.rs:8:29
  |
8 | struct CustomRef<'a, T>(&'a CustomMut);
  |                             ^^^^^^^^^ expected named lifetime parameter
  |
help: consider using the `'a` lifetime
  |
8 | struct CustomRef<'a, T>(&'a CustomMut<'a>);
  |                                      ++++

warning: unused import: `Reborrow`
 --> /tmp/icemaker_global_tempdir.5uK8My7zlvE6/rustc_testrunner_tmpdir_reporting.tX0I7qYXjCUc/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 struct `CustomMut`
 --> /tmp/icemaker_global_tempdir.5uK8My7zlvE6/rustc_testrunner_tmpdir_reporting.tX0I7qYXjCUc/mvce.rs:8:29
  |
8 | struct CustomRef<'a, T>(&'a CustomMut);
  |                             ^^^^^^^^^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `T`
 --> /tmp/icemaker_global_tempdir.5uK8My7zlvE6/rustc_testrunner_tmpdir_reporting.tX0I7qYXjCUc/mvce.rs:4:8
  |
4 | struct CustomMut<'a, T>(&'a mut T);
  |        ^^^^^^^^^     -
help: add missing generic argument
  |
8 | struct CustomRef<'a, T>(&'a CustomMut<T>);
  |                                      +++


thread 'rustc' (194646) panicked at /rustc-dev/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_borrowck/src/type_check/mod.rs:2511:22:
called `Result::unwrap()` on an `Err` value: NoSolution
stack backtrace:
   0:     0x7fc759874239 - <<std[db65628f2330fd11]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[b3c617e8375f9bd0]::fmt::Display>::fmt
   1:     0x7fc759e1b788 - core[b3c617e8375f9bd0]::fmt::write
   2:     0x7fc75988ac66 - <std[db65628f2330fd11]::sys::stdio::unix::Stderr as std[db65628f2330fd11]::io::Write>::write_fmt
   3:     0x7fc75984a2de - std[db65628f2330fd11]::panicking::default_hook::{closure#0}
   4:     0x7fc7598678f3 - std[db65628f2330fd11]::panicking::default_hook
   5:     0x7fc7587544d1 - std[db65628f2330fd11]::panicking::update_hook::<alloc[b10a1c065189447]::boxed::Box<rustc_driver_impl[1f444ccaa450aabc]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc759867bd2 - std[db65628f2330fd11]::panicking::panic_with_hook
   7:     0x7fc75984a3a2 - std[db65628f2330fd11]::panicking::panic_handler::{closure#0}
   8:     0x7fc7598410b9 - std[db65628f2330fd11]::sys::backtrace::__rust_end_short_backtrace::<std[db65628f2330fd11]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fc75984be0d - __rustc[87b1f669d989e0ab]::rust_begin_unwind
  10:     0x7fc75692c50c - core[b3c617e8375f9bd0]::panicking::panic_fmt
  11:     0x7fc755f99682 - core[b3c617e8375f9bd0]::result::unwrap_failed
  12:     0x7fc75acc23c7 - <rustc_borrowck[543291a75b63dc2a]::type_check::TypeChecker as rustc_middle[4a2cff3451d2bad5]::mir::visit::Visitor>::visit_body
  13:     0x7fc75ac7286c - rustc_borrowck[543291a75b63dc2a]::type_check::type_check
  14:     0x7fc75a8d7176 - <rustc_borrowck[543291a75b63dc2a]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  15:     0x7fc75a8d2b1b - rustc_borrowck[543291a75b63dc2a]::mir_borrowck
  16:     0x7fc75a8d28e9 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::mir_borrowck::invoke_provider_fn::__rust_begin_short_backtrace
  17:     0x7fc759f6d6a6 - 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>
  18:     0x7fc759f6fdc3 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
  19:     0x7fc759f6ff94 - <rustc_middle[4a2cff3451d2bad5]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[232b63f46aa35c0e]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  20:     0x7fc759f6f276 - rustc_interface[232b63f46aa35c0e]::passes::analysis
  21:     0x7fc75af822c9 - rustc_query_impl[3b9ecabc2cca1a8f]::execution::try_execute_query::<rustc_middle[4a2cff3451d2bad5]::query::caches::SingleCache<rustc_middle[4a2cff3451d2bad5]::query::erase::ErasedData<[u8; 0usize]>>, false>
  22:     0x7fc75af81f33 - rustc_query_impl[3b9ecabc2cca1a8f]::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
  23:     0x7fc75afc765b - rustc_interface[232b63f46aa35c0e]::interface::run_compiler::<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}
  24:     0x7fc75af75c3e - 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}, ()>
  25:     0x7fc75af7632d - <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}
  26:     0x7fc75af7712c - <std[db65628f2330fd11]::sys::thread::unix::Thread>::new::thread_start
  27:     0x7fc754aa097a - <unknown>
  28:     0x7fc754b242bc - <unknown>
  29:                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.97.0-nightly (3e353d735 2026-05-08) running on x86_64-unknown-linux-gnu

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 2 previous errors; 1 warning emitted

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

@rustbot label +F-reborrow

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-reborrow`#![feature(reborrow)]`; see #145612I-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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions