Open
Description
Code
#![feature(coerce_unsized)]
use std::ops::CoerceUnsized;
struct Foo<T: ?Sized> {
a: T,
}
impl<T, U> CoerceUnsized<U> for Foo<T> {}
union U {
a: usize,
}
const C: U = Foo { a: 10 };
fn main() {}
Meta
rustc --version --verbose
:
rustc 1.81.0-nightly (fda509e81 2024-06-25)
binary: rustc
commit-hash: fda509e817abeeecb5b76bc1de844f355675c81e
commit-date: 2024-06-25
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Error output
error[E0376]: the trait `CoerceUnsized` may only be implemented for a coercion between structures
--> cast442.rs:8:1
|
8 | impl<T, U> CoerceUnsized<U> for Foo<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Backtrace
thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/cast.rs:442:17:
assertion `left == right` failed
left: Foo
right: U
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed::<&rustc_middle::ty::adt::AdtDef, &rustc_middle::ty::adt::AdtDef>
4: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::unsize_into
5: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::statement
6: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
[... omitted 2 frames ...]
7: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
8: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
[... omitted 2 frames ...]
9: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#3}>::{closure#0}
10: rustc_hir_analysis::check_crate
11: rustc_interface::passes::run_required_analyses
12: rustc_interface::passes::analysis
[... omitted 1 frame ...]
13: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#5}>
14: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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: please attach the file at `/Volumes/T7/workspace/placeholder_rustexec/0625/rustc-ice-2024-06-26T06_34_30-28249.txt` to your bug report
query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `C`
#1 [eval_to_const_value_raw] simplifying constant for the type system `C`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0376`.
Note
- ICE location:
compiler/rustc_const_eval/src/interpret/cast.rs#L442
rust/compiler/rustc_const_eval/src/interpret/cast.rs
Lines 431 to 442 in fda509e
- ICE:
unsize_into: invalid conversion
inrustc_const_eval/src/interpret/cast.rs
#126269 might be related
@rustbot label +F-coerce_unsized