Skip to content

[ICE]: type mismatch when copying! #156313

@matthiaskrgr

Description

@matthiaskrgr

Code

this triggers an ice in miri (cargo miri run )

//@ 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 T);

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<'_, ()>) {
    let a = CustomMut(&mut ());
    method(a);
}

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

Meta

rustc --version --verbose:

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

Error output

<output>
Backtrace

Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
   Compiling ff v0.1.0 (/tmp/ff)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `/home/matthias/.rustup/toolchains/master/bin/cargo-miri runner target/miri/x86_64-unknown-linux-gnu/debug/ff`
warning: function cannot return without recursing
  --> src/main.rs:20:1
   |
20 | fn method(_a: CustomRef<'_, ()>) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
21 |     let a = CustomMut(&mut ());
22 |     method(a);
   |     --------- recursive call site
   |
   = help: a `loop` may express intention better if this is on purpose
   = note: `#[warn(unconditional_recursion)]` on by default

error: internal compiler error: /rustc/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_const_eval/src/interpret/place.rs:894:13: type mismatch when copying!
                                src: CustomMut<'_, ()>,
                                dest: CustomRef<'_, ()>
  --> src/main.rs:27:12
   |
27 |     method(a);
   |            ^


thread 'rustc' (122038) panicked at /rustc/3e353d7353b0cd6fa4eefd5c882457cc2708184c/compiler/rustc_const_eval/src/interpret/place.rs:894:13:
Box<dyn Any>
stack backtrace:
   0:     0x7fb1e5874239 - <<std[db65628f2330fd11]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[b3c617e8375f9bd0]::fmt::Display>::fmt
   1:     0x7fb1e5e1b788 - core[b3c617e8375f9bd0]::fmt::write
   2:     0x7fb1e588ac66 - <std[db65628f2330fd11]::sys::stdio::unix::Stderr as std[db65628f2330fd11]::io::Write>::write_fmt
   3:     0x7fb1e584a2de - std[db65628f2330fd11]::panicking::default_hook::{closure#0}
   4:     0x7fb1e58678f3 - std[db65628f2330fd11]::panicking::default_hook
   5:     0x7fb1e47544d1 - std[db65628f2330fd11]::panicking::update_hook::<alloc[b10a1c065189447]::boxed::Box<rustc_driver_impl[1f444ccaa450aabc]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fb1e5867bd2 - std[db65628f2330fd11]::panicking::panic_with_hook
   7:     0x7fb1e4781f51 - std[db65628f2330fd11]::panicking::begin_panic::<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>::{closure#0}
   8:     0x7fb1e477af46 - std[db65628f2330fd11]::sys::backtrace::__rust_end_short_backtrace::<std[db65628f2330fd11]::panicking::begin_panic<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>::{closure#0}, !>
   9:     0x7fb1e477acab - std[db65628f2330fd11]::panicking::begin_panic::<rustc_errors[4e25407aa9dfcb98]::ExplicitBug>
  10:     0x7fb1e478d431 - <rustc_errors[4e25407aa9dfcb98]::diagnostic::BugAbort as rustc_errors[4e25407aa9dfcb98]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fb1e4d7158c - <rustc_errors[4e25407aa9dfcb98]::DiagCtxtHandle>::span_bug::<rustc_span[749aae40fdac821d]::span_encoding::Span, alloc[b10a1c065189447]::string::String>
  12:     0x7fb1e4d9cf46 - rustc_middle[4a2cff3451d2bad5]::util::bug::opt_span_bug_fmt::<rustc_span[749aae40fdac821d]::span_encoding::Span>::{closure#0}
  13:     0x7fb1e4d9d0d2 - 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:     0x7fb1e4d8b82b - 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}, !>
  15:     0x7fb1e2d9d338 - rustc_middle[4a2cff3451d2bad5]::util::bug::span_bug_fmt::<rustc_span[749aae40fdac821d]::span_encoding::Span>
  16:     0x56365752973b - <rustc_const_eval[1843a6e232bbbb43]::interpret::eval_context::InterpCx<miri[2b9dc3af2a5e8aa4]::machine::MiriMachine>>::copy_op_no_validate::<rustc_const_eval[1843a6e232bbbb43]::interpret::operand::OpTy<miri[2b9dc3af2a5e8aa4]::machine::Provenance>, rustc_const_eval[1843a6e232bbbb43]::interpret::place::PlaceTy<miri[2b9dc3af2a5e8aa4]::machine::Provenance>>
  17:     0x56365759684b - <rustc_const_eval[1843a6e232bbbb43]::interpret::eval_context::InterpCx<miri[2b9dc3af2a5e8aa4]::machine::MiriMachine>>::eval_rvalue_into_place
  18:     0x5636576164e7 - miri[2b9dc3af2a5e8aa4]::eval::eval_entry
  19:     0x563657751660 - <miri[af20b88756fa8557]::MiriCompilerCalls as rustc_driver_impl[1f444ccaa450aabc]::Callbacks>::after_analysis
  20:     0x7fb1e6fc7675 - rustc_interface[232b63f46aa35c0e]::interface::run_compiler::<(), rustc_driver_impl[1f444ccaa450aabc]::run_compiler::{closure#0}>::{closure#1}
  21:     0x7fb1e4769acf - <rustc_thread_pool[e5693f1ff0fd8712]::job::StackJob<rustc_thread_pool[e5693f1ff0fd8712]::latch::LatchRef<rustc_thread_pool[e5693f1ff0fd8712]::latch::LockLatch>, <rustc_thread_pool[e5693f1ff0fd8712]::registry::Registry>::in_worker_cold<<rustc_thread_pool[e5693f1ff0fd8712]::thread_pool::ThreadPool>::install<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#5}::{closure#0}::{closure#1}::{closure#0}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> as rustc_thread_pool[e5693f1ff0fd8712]::job::Job>::execute
  22:     0x7fb1e54e377f - <rustc_thread_pool[e5693f1ff0fd8712]::registry::WorkerThread>::wait_or_steal_until_cold
  23:     0x7fb1e54e21d2 - <rustc_thread_pool[e5693f1ff0fd8712]::registry::ThreadBuilder>::run
  24:     0x7fb1e474ce2c - std[db65628f2330fd11]::sys::backtrace::__rust_begin_short_backtrace::<<rustc_thread_pool[e5693f1ff0fd8712]::ThreadPoolBuilder>::build_scoped<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#5}::{closure#0}::{closure#0}, 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#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  25:     0x7fb1e475693a - <std[db65628f2330fd11]::thread::lifecycle::spawn_unchecked<<rustc_thread_pool[e5693f1ff0fd8712]::ThreadPoolBuilder>::build_scoped<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#5}::{closure#0}::{closure#0}, 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#5}::{closure#0}::{closure#1}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#1} as core[b3c617e8375f9bd0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x7fb1e6f7712c - <std[db65628f2330fd11]::sys::thread::unix::Thread>::new::thread_start
  27:     0x7fb1e0aa597a - <unknown>
  28:     0x7fb1e0b292bc - <unknown>
  29:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/miri/issues/new

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/ff/rustc-ice-2026-05-08T10_19_26-121630.txt` to your bug report

note: rustc 1.97.0-nightly (3e353d735 2026-05-08) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C target-cpu=native -Z threads=16

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
note: the place in the program where the ICE was triggered
  --> src/main.rs:27:12
   |
27 |     method(a);
   |            ^
   |
   = note: stack backtrace:
           0: main
               at src/main.rs:27:12: 27:13
           1: <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
           2: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18: 166:21
           3: std::rt::lang_start::<()>::{closure#0}
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/rt.rs:206:18: 206:75
           4: std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/ops/function.rs:287:13: 287:31
           5: std::panicking::catch_unwind::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/panicking.rs:581:40: 581:43
           6: std::panicking::catch_unwind::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19: 544:88
           7: std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
           8: std::rt::lang_start_internal::{closure#0}
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/rt.rs:175:24: 175:49
           9: std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/panicking.rs:581:40: 581:43
           10: std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19: 544:88
           11: std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
           12: std::rt::lang_start_internal
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/rt.rs:171:5: 193:7
           13: std::rt::lang_start::<()>
               at /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/std/src/rt.rs:205:5: 210:6

error: aborting due to 1 previous error; 1 warning emitted

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.

    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