Skip to content

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

@matthiaskrgr

Description

@matthiaskrgr
Member

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

Activity

added
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.
C-bugCategory: This is a bug.
on Aug 3, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 3, 2024
matthiaskrgr

matthiaskrgr commented on Aug 3, 2024

@matthiaskrgr
MemberAuthor

bisects to #120248 🤔 cc @WaffleLapkin

removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 4, 2024
theemathas

theemathas commented on Aug 4, 2024

@theemathas
Contributor

Minimized:

trait Trait {
    type Associated;
}

impl Trait for i32 {
    type Associated = i64;
}

trait Generic<T> {}

type TraitObject = dyn Generic<<i32 as Trait>::Associated>;

struct Wrap(TraitObject);

fn cast(x: *mut TraitObject) {
    x as *mut Wrap;
}

This compiles on stable. ICEs on beta.

Error output on beta
   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at compiler/rustc_borrowck/src/type_check/mod.rs:2386:38:
called `Result::unwrap()` on an `Err` value: NoSolution
stack backtrace:
   0:     0x7f444bee13a5 - std::backtrace_rs::backtrace::libunwind::trace::hec2dc58314f3b5ff
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f444bee13a5 - std::backtrace_rs::backtrace::trace_unsynchronized::h331ee0b0169d7b05
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f444bee13a5 - std::sys::backtrace::_print_fmt::h29aa16f5d373cd01
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/sys/backtrace.rs:65:5
   3:     0x7f444bee13a5 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hee7def06ed53e721
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/sys/backtrace.rs:40:26
   4:     0x7f444bf30eab - core::fmt::rt::Argument::fmt::hc46773f831b98118
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/core/src/fmt/rt.rs:173:76
   5:     0x7f444bf30eab - core::fmt::write::hda013bd82d767381
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/core/src/fmt/mod.rs:1182:21
   6:     0x7f444bed5f2f - std::io::Write::write_fmt::hb37aee6d7f10fc9b
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/io/mod.rs:1827:15
   7:     0x7f444bee3b91 - std::sys::backtrace::BacktraceLock::print::h907db10e44632b3a
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/sys/backtrace.rs:43:9
   8:     0x7f444bee3b91 - std::panicking::default_hook::{{closure}}::hf6a2255341957303
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/panicking.rs:269:22
   9:     0x7f444bee386c - std::panicking::default_hook::h0b7d4412c1e361bd
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/panicking.rs:296:9
  10:     0x7f444f1f3a50 - std[efeefe75b6db041f]::panicking::update_hook::<alloc[759981cd4e4e801b]::boxed::Box<rustc_driver_impl[c3312e73a30af321]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7f444bee455f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hdc9e661750688cd9
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/alloc/src/boxed.rs:2084:9
  12:     0x7f444bee455f - std::panicking::rust_panic_with_hook::h6fa5f6f38389e656
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/panicking.rs:808:13
  13:     0x7f444bee4187 - std::panicking::begin_panic_handler::{{closure}}::he96dd93ff17a0601
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/panicking.rs:674:13
  14:     0x7f444bee1869 - std::sys::backtrace::__rust_end_short_backtrace::h2f5b06618a35c92b
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/sys/backtrace.rs:168:18
  15:     0x7f444bee3e14 - rust_begin_unwind
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/panicking.rs:665:5
  16:     0x7f444bf2d463 - core::panicking::panic_fmt::h8c83251fb1f17232
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/core/src/panicking.rs:74:14
  17:     0x7f444bf2dab6 - core::result::unwrap_failed::ha33a948b4cc83713
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/core/src/result.rs:1679:5
  18:     0x7f445093b6ce - <rustc_borrowck[6480dc8642ee2324]::type_check::TypeChecker>::typeck_mir
  19:     0x7f44517c2c08 - rustc_borrowck[6480dc8642ee2324]::type_check::type_check
  20:     0x7f44508465df - rustc_borrowck[6480dc8642ee2324]::nll::compute_regions
  21:     0x7f445169ba1c - rustc_borrowck[6480dc8642ee2324]::do_mir_borrowck
  22:     0x7f445168ce38 - rustc_query_impl[31fd7ff07bfdf275]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[31fd7ff07bfdf275]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cecd0bcfd982753]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7f4450a59468 - rustc_query_system[e7fb6eb8ab67ecdb]::query::plumbing::try_execute_query::<rustc_query_impl[31fd7ff07bfdf275]::DynamicConfig<rustc_query_system[e7fb6eb8ab67ecdb]::query::caches::VecCache<rustc_span[e52881666e69bc1d]::def_id::LocalDefId, rustc_middle[2cecd0bcfd982753]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[31fd7ff07bfdf275]::plumbing::QueryCtxt, false>
  24:     0x7f4450a58f15 - rustc_query_impl[31fd7ff07bfdf275]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7f44510ecf3b - rustc_interface[b6630b0d0d781590]::passes::analysis
  26:     0x7f44510ec867 - rustc_query_impl[31fd7ff07bfdf275]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[31fd7ff07bfdf275]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cecd0bcfd982753]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7f445159ac22 - rustc_query_system[e7fb6eb8ab67ecdb]::query::plumbing::try_execute_query::<rustc_query_impl[31fd7ff07bfdf275]::DynamicConfig<rustc_query_system[e7fb6eb8ab67ecdb]::query::caches::SingleCache<rustc_middle[2cecd0bcfd982753]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[31fd7ff07bfdf275]::plumbing::QueryCtxt, false>
  28:     0x7f445159a9cf - rustc_query_impl[31fd7ff07bfdf275]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f4451479016 - rustc_interface[b6630b0d0d781590]::interface::run_compiler::<core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>, rustc_driver_impl[c3312e73a30af321]::run_compiler::{closure#0}>::{closure#1}
  30:     0x7f44513b851b - std[efeefe75b6db041f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b6630b0d0d781590]::util::run_in_thread_with_globals<rustc_interface[b6630b0d0d781590]::interface::run_compiler<core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>, rustc_driver_impl[c3312e73a30af321]::run_compiler::{closure#0}>::{closure#1}, core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>>
  31:     0x7f44513b82ea - <<std[efeefe75b6db041f]::thread::Builder>::spawn_unchecked_<rustc_interface[b6630b0d0d781590]::util::run_in_thread_with_globals<rustc_interface[b6630b0d0d781590]::interface::run_compiler<core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>, rustc_driver_impl[c3312e73a30af321]::run_compiler::{closure#0}>::{closure#1}, core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c78a77099d0262f3]::result::Result<(), rustc_span[e52881666e69bc1d]::ErrorGuaranteed>>::{closure#1} as core[c78a77099d0262f3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7f444beee5bb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5e49ad344eded169
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/alloc/src/boxed.rs:2070:9
  33:     0x7f444beee5bb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc344207bfeabc120
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/alloc/src/boxed.rs:2070:9
  34:     0x7f444beee5bb - std::sys::pal::unix::thread::Thread::new::thread_start::h30a261106ad4495b
                               at /rustc/08328a323ecd80b443a8fcc72c6b1071f48e233f/library/std/src/sys/pal/unix/thread.rs:108:17
  35:     0x7f444bdf8609 - start_thread
  36:     0x7f444bd1b353 - clone
  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: rustc 1.81.0-beta.2 (08328a323 2024-07-25) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `cast`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground` (lib)

@rustbot label +regression-from-stable-to-beta

Of note, the opposite pointer cast fails to compile on stable, beta, and nightly. This seems wrong to me.

The opposite cast
trait Trait {
    type Associated;
}

impl Trait for i32 {
    type Associated = i64;
}

trait Generic<T> {}

type TraitObject = dyn Generic<<i32 as Trait>::Associated>;

struct Wrap(TraitObject);

fn cast(x: *mut Wrap) {
    x as *mut TraitObject;
}

Error:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `Wrap: Generic<i64>` is not satisfied
  --> src/lib.rs:16:5
   |
16 |     x as *mut TraitObject;
   |     ^ the trait `Generic<i64>` is not implemented for `Wrap`
   |
help: this trait has no implementations, consider adding one
  --> src/lib.rs:9:1
   |
9  | trait Generic<T> {}
   | ^^^^^^^^^^^^^^^^
   = note: required for the cast from `*mut Wrap` to `*mut (dyn Generic<i64> + 'static)`

error[E0277]: the size for values of type `(dyn Generic<i64> + 'static)` cannot be known at compilation time
  --> src/lib.rs:16:5
   |
16 |     x as *mut TraitObject;
   |     ^ doesn't have a size known at compile-time
   |
   = help: within `Wrap`, the trait `Sized` is not implemented for `(dyn Generic<i64> + 'static)`, which is required by `Wrap: Sized`
note: required because it appears within the type `Wrap`
  --> src/lib.rs:13:8
   |
13 | struct Wrap(TraitObject);
   |        ^^^^
   = note: required for the cast from `*mut Wrap` to `*mut (dyn Generic<i64> + 'static)`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 2 previous errors
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 4, 2024
apiraino

apiraino commented on Aug 5, 2024

@apiraino
Contributor

bisects to #120248 🤔 cc @WaffleLapkin

Just for context (unsure if relevant here) I see in that PR a question for T-lang about a breaking change at this comment and in the following FCP that was approved

WaffleLapkin

WaffleLapkin commented on Aug 5, 2024

@WaffleLapkin
Member

So while the breaking change was approved, I believe this code should compile (and definitely not ICE).

The issue seems to be that borrowck can't prove a bound (after typeck did). Seeing for you need a projection to trigger the issue (<i32 as Trait>::Associated>) I think there is normalization missing somewhere.

apiraino

apiraino commented on Aug 5, 2024

@apiraino
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

added
P-highHigh priority
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 5, 2024
added
S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
on Aug 5, 2024
added a commit that references this issue on Aug 5, 2024
77f57cb
added a commit that references this issue on Aug 6, 2024
aeaa236
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Participants

    @matthiaskrgr@compiler-errors@apiraino@theemathas@saethlin

    Issue actions

      ICE: called `Result::unwrap()` on an `Err` value: NoSolution · Issue #128621 · rust-lang/rust