Skip to content

ICE: called Result::unwrap() on an Err value: NoSolution #128621

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

#![feature(ptr_metadata)]
use std::{ops::FnMut, ptr::Pointee};

pub type EmplacerFn<'a, T> = dyn for<'b> FnMut(<T as Pointee>::Metadata) + 'a;

pub struct Emplacer<'a, T>(EmplacerFn<'a, T>);

impl<'a, T> Emplacer<'a, T> {
    pub unsafe fn from_fn<'b>(emplacer_fn: &'b mut EmplacerFn<'a, T>) -> &'b mut Self {
        unsafe { &mut *((emplacer_fn as *mut EmplacerFn<'a, T>) as *mut Self) }
    }
}

pub fn main() {}
original code

original:

#![feature(ptr_metadata)]
// This test is the result of minimizing the `emplacable` crate to reproduce
// <https://github.com/rust-lang/miri/issues/3541>.

use std::{ops::FnMut, ptr::Pointee};

pub type EmplacerFn<'a, T> = dyn for<'b> FnMut(<T as Pointee>::Metadata) + 'a;

#[repr(transparent)]
pub struct Emplacer<'a, T>(EmplacerFn<'a, T>)
where
    T: ?Sized;

impl<'a, T> Emplacer<'a, T>
where
    &'b mut Self: ?Sized,
{
    pub unsafe fn from_fn<'b>(emplacer_fn: &'b mut EmplacerFn<'a, T>) -> &'b mut Self {
        // This used to trigger:
        // constructing invalid value: wrong trait in wide pointer vtable: expected
        // `std::ops::FnMut(<[std::boxed::Box<i32>] as std::ptr::Pointee>::Metadata)`, but encountered
        // `std::ops::FnMut<(usize,)>`.
        unsafe { &mut *((emplacer_fn as *mut EmplacerFn<'a, T>) as *mut Self) }
    }
}

pub fn box_new_with<T>()
where
    T: ?Sized,
{
    let emplacer_closure = &mut |_meta| {
        unreachable!();
    };

    unsafe { Emplacer::<T>::from_fn(emplacer_closure) };
}

fn main() {
    box_new_with::<[Box<i32>]>();
}

Version information

rustc 1.82.0-nightly (edc4dc337 2024-08-03)
binary: rustc
commit-hash: edc4dc337b28a389dbd87b3825d7929381edeb8f
commit-date: 2024-08-03
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

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

Program output

thread 'rustc' panicked at compiler/rustc_borrowck/src/type_check/mod.rs:2379:38:
called `Result::unwrap()` on an `Err` value: NoSolution
stack backtrace:
   0:     0x7e8e559a114d - std::backtrace_rs::backtrace::libunwind::trace::h3396cafc0cf0d168
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7e8e559a114d - std::backtrace_rs::backtrace::trace_unsynchronized::hbe65a7c762aaf69a
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7e8e559a114d - std::sys::backtrace::_print_fmt::hfdd3dddbd75728fc
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/sys/backtrace.rs:66:9
   3:     0x7e8e559a114d - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hfba02964013c3262
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/sys/backtrace.rs:39:26
   4:     0x7e8e559f168b - core::fmt::rt::Argument::fmt::h1cc3e67cc5e9d174
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/core/src/fmt/rt.rs:173:76
   5:     0x7e8e559f168b - core::fmt::write::hdb76d7e5bc6978cf
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/core/src/fmt/mod.rs:1178:21
   6:     0x7e8e55994ec3 - std::io::Write::write_fmt::h27ce112238514bf4
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/io/mod.rs:1823:15
   7:     0x7e8e559a3942 - std::sys::backtrace::BacktraceLock::print::h9feef95ad1ac9d67
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/sys/backtrace.rs:42:9
   8:     0x7e8e559a3942 - std::panicking::default_hook::{{closure}}::h33a1b00b93aac464
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/panicking.rs:266:22
   9:     0x7e8e559a35ae - std::panicking::default_hook::hfa713793aec3526f
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/panicking.rs:293:9
  10:     0x7e8e51ea6997 - std[e05a76fc5581e11]::panicking::update_hook::<alloc[76bfb925f7cccf2e]::boxed::Box<rustc_driver_impl[c2f8fa5a81365ad3]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7e8e559a4332 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h92beb97f09018d1f
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/alloc/src/boxed.rs:2164:9
  12:     0x7e8e559a4332 - std::panicking::rust_panic_with_hook::hb8e05073b20eee1b
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/panicking.rs:805:13
  13:     0x7e8e559a3fe7 - std::panicking::begin_panic_handler::{{closure}}::h8ac2d6811e12e338
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/panicking.rs:671:13
  14:     0x7e8e559a1639 - std::sys::backtrace::__rust_end_short_backtrace::h4e11dc802a78f1a1
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/sys/backtrace.rs:170:18
  15:     0x7e8e559a3c74 - rust_begin_unwind
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/panicking.rs:662:5
  16:     0x7e8e559edce3 - core::panicking::panic_fmt::h64d8681f23dadf6d
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/core/src/panicking.rs:74:14
  17:     0x7e8e559ee336 - core::result::unwrap_failed::hf97f3a13da3067be
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/core/src/result.rs:1679:5
  18:     0x7e8e536c2526 - <rustc_borrowck[7f0a2371269bdcfb]::type_check::TypeChecker>::typeck_mir
  19:     0x7e8e5456591a - rustc_borrowck[7f0a2371269bdcfb]::type_check::type_check
  20:     0x7e8e53506817 - rustc_borrowck[7f0a2371269bdcfb]::nll::compute_regions
  21:     0x7e8e544db80f - rustc_borrowck[7f0a2371269bdcfb]::do_mir_borrowck
  22:     0x7e8e544cbd47 - rustc_query_impl[59527bbfe333c2c8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[59527bbfe333c2c8]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5fc6768cbdcaf94e]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7e8e535f4a45 - rustc_query_system[fb9c72285b8affb2]::query::plumbing::try_execute_query::<rustc_query_impl[59527bbfe333c2c8]::DynamicConfig<rustc_query_system[fb9c72285b8affb2]::query::caches::VecCache<rustc_span[6181c2fd5039252a]::def_id::LocalDefId, rustc_middle[5fc6768cbdcaf94e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[59527bbfe333c2c8]::plumbing::QueryCtxt, false>
  24:     0x7e8e535f448d - rustc_query_impl[59527bbfe333c2c8]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7e8e53ee8eaa - rustc_interface[b1d83cf6a56376dd]::passes::analysis
  26:     0x7e8e53ee805b - rustc_query_impl[59527bbfe333c2c8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[59527bbfe333c2c8]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5fc6768cbdcaf94e]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7e8e543a442e - rustc_query_system[fb9c72285b8affb2]::query::plumbing::try_execute_query::<rustc_query_impl[59527bbfe333c2c8]::DynamicConfig<rustc_query_system[fb9c72285b8affb2]::query::caches::SingleCache<rustc_middle[5fc6768cbdcaf94e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[59527bbfe333c2c8]::plumbing::QueryCtxt, false>
  28:     0x7e8e543a418f - rustc_query_impl[59527bbfe333c2c8]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7e8e542b7063 - rustc_interface[b1d83cf6a56376dd]::interface::run_compiler::<core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>, rustc_driver_impl[c2f8fa5a81365ad3]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7e8e54256289 - std[e05a76fc5581e11]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b1d83cf6a56376dd]::util::run_in_thread_with_globals<rustc_interface[b1d83cf6a56376dd]::util::run_in_thread_pool_with_globals<rustc_interface[b1d83cf6a56376dd]::interface::run_compiler<core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>, rustc_driver_impl[c2f8fa5a81365ad3]::run_compiler::{closure#0}>::{closure#1}, core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>>::{closure#0}, core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>>
  31:     0x7e8e54256032 - <<std[e05a76fc5581e11]::thread::Builder>::spawn_unchecked_<rustc_interface[b1d83cf6a56376dd]::util::run_in_thread_with_globals<rustc_interface[b1d83cf6a56376dd]::util::run_in_thread_pool_with_globals<rustc_interface[b1d83cf6a56376dd]::interface::run_compiler<core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>, rustc_driver_impl[c2f8fa5a81365ad3]::run_compiler::{closure#0}>::{closure#1}, core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>>::{closure#0}, core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d16eec4b7581b6ce]::result::Result<(), rustc_span[6181c2fd5039252a]::ErrorGuaranteed>>::{closure#1} as core[d16eec4b7581b6ce]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7e8e559ae04b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdd26b728780d5edf
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/alloc/src/boxed.rs:2150:9
  33:     0x7e8e559ae04b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9f4e5f896641f315
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/alloc/src/boxed.rs:2150:9
  34:     0x7e8e559ae04b - std::sys::pal::unix::thread::Thread::new::thread_start::hf133519f4699d161
                               at /rustc/edc4dc337b28a389dbd87b3825d7929381edeb8f/library/std/src/sys/pal/unix/thread.rs:105:17
  35:     0x7e8e4e8a6ded - <unknown>
  36:     0x7e8e4e92a0dc - <unknown>
  37:                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.82.0-nightly (edc4dc337 2024-08-03) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at /tmp/icemaker_global_tempdir.hs07VfNUIJu0/rustc_testrunner_tmpdir_reporting.PNoBQTfCLNlo/mvce.rs:7:1: 7:28>::from_fn`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

@rustbot label +F-ptr_metadata

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions