ICE using `repr(align(…))` type as trait object receiver (arbitrary `self`-type)
Open
Nobody has claimed this yet.
A-dyn-trait
A-layout
C-bug
F-arbitrary_self_types
F-dispatch_from_dyn
I-ICE
S-bug-has-test
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#![feature(unsize, dispatch_from_dyn, arbitrary_self_types)]
use std::marker::Unsize;
use std::ops::{Deref, DispatchFromDyn};
#[repr(align(16))]
pub struct MyPointer<T: ?Sized>(*const T);
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<MyPointer<U>> for MyPointer<T> {}
impl<T: ?Sized> Deref for MyPointer<T> {
type Target = T;
fn deref(&self) -> &T {
unimplemented!()
}
}
pub trait Trait {
fn foo(self: MyPointer<Self>) {}
}
// make sure some usage of `<dyn Trait>::foo` makes it to codegen
pub fn user() -> *const () {
<dyn Trait>::foo as *const ()
}
Error output
error: internal compiler error: compiler/rustc_ty_utils/src/abi.rs:740:18: receiver type has unsupported layout: TyAndLayout { ty: MyPointer<dyn Trait>, layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(16 bytes), pref: Align(16 bytes) }, backend_repr: Memory { sized: true }, fields: Arbitrary { offsets: [Size(0 bytes)], memory_index: [0] }, largest_niche: Some(Niche { offset: Size(8 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), uninhabited: false, variants: Single { index: 0 }, max_repr_align: Some(Align(16 bytes)), unadjusted_abi_align: Align(8 bytes), randomization_seed: 7312131278044645289 } }
thread 'rustc' panicked at compiler/rustc_ty_utils/src/abi.rs:740:18:
Box<dyn Any>
stack backtrace:
0: 0x770c57633893 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2fbd06f1ad558926
1: 0x770c57e05a58 - core::fmt::write::he613d79b06f4b50b
2: 0x770c5913a2d1 - std::io::Write::write_fmt::h2d558f8849cee296
3: 0x770c576336f2 - std::sys::backtrace::BacktraceLock::print::h980245f16d2e53c5
4: 0x770c57635faa - std::panicking::default_hook::{{closure}}::ha8e1870143bb4424
5: 0x770c57635b2f - std::panicking::default_hook::h510c7e30611e55b6
6: 0x770c566991ff - std[9e04a37a0a8a4f45]::panicking::update_hook::<alloc[324835f0a3c901e2]::boxed::Box<rustc_driver_impl[8fdf64b2f913ec67]::install_ice_hook::{closure#1}>>::{closure#0}
7: 0x770c57636823 - std::panicking::rust_panic_with_hook::hf32ade211372445e
8: 0x770c566d66c1 - std[9e04a37a0a8a4f45]::panicking::begin_panic::<rustc_errors[1bf8457a84dc8be7]::ExplicitBug>::{closure#0}
9: 0x770c566ca8b6 - std[9e04a37a0a8a4f45]::sys::backtrace::__rust_end_short_backtrace::<std[9e04a37a0a8a4f45]::panicking::begin_panic<rustc_errors[1bf8457a84dc8be7]::ExplicitBug>::{closure#0}, !>
10: 0x770c566ca89b - std[9e04a37a0a8a4f45]::panicking::begin_panic::<rustc_errors[1bf8457a84dc8be7]::ExplicitBug>
11: 0x770c566e0071 - <rustc_errors[1bf8457a84dc8be7]::diagnostic::BugAbort as rustc_errors[1bf8457a84dc8be7]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: 0x770c56d1e56a - rustc_middle[77f5a5ad0a03fbe5]::util::bug::opt_span_bug_fmt::<rustc_span[616a7760585f005b]::span_encoding::Span>::{closure#0}
13: 0x770c56cf97da - rustc_middle[77f5a5ad0a03fbe5]::ty::context::tls::with_opt::<rustc_middle[77f5a5ad0a03fbe5]::util::bug::opt_span_bug_fmt<rustc_span[616a7760585f005b]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x770c56cf966b - rustc_middle[77f5a5ad0a03fbe5]::ty::context::tls::with_context_opt::<rustc_middle[77f5a5ad0a03fbe5]::ty::context::tls::with_opt<rustc_middle[77f5a5ad0a03fbe5]::util::bug::opt_span_bug_fmt<rustc_span[616a7760585f005b]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x770c5497a4c0 - rustc_middle[77f5a5ad0a03fbe5]::util::bug::bug_fmt
16: 0x770c58697fd7 - <core[1a8e3f3c1152e72c]::iter::adapters::enumerate::Enumerate<_> as core[1a8e3f3c1152e72c]::iter::traits::iterator::Iterator>::try_fold::enumerate::<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty, (), core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>>, core[1a8e3f3c1152e72c]::iter::adapters::map::map_try_fold<(usize, rustc_middle[77f5a5ad0a03fbe5]::ty::Ty), core[1a8e3f3c1152e72c]::result::Result<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>, &rustc_middle[77f5a5ad0a03fbe5]::ty::layout::FnAbiError>, (), core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>>, rustc_ty_utils[7aab6de42c66b8b6]::abi::fn_abi_new_uncached::{closure#3}, <core[1a8e3f3c1152e72c]::iter::adapters::GenericShunt<core[1a8e3f3c1152e72c]::iter::adapters::map::Map<core[1a8e3f3c1152e72c]::iter::adapters::enumerate::Enumerate<core[1a8e3f3c1152e72c]::iter::adapters::chain::Chain<core[1a8e3f3c1152e72c]::iter::adapters::chain::Chain<core[1a8e3f3c1152e72c]::iter::adapters::copied::Copied<core[1a8e3f3c1152e72c]::slice::iter::Iter<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>, core[1a8e3f3c1152e72c]::iter::adapters::copied::Copied<core[1a8e3f3c1152e72c]::slice::iter::Iter<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>>, core[1a8e3f3c1152e72c]::option::IntoIter<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>>, rustc_ty_utils[7aab6de42c66b8b6]::abi::fn_abi_new_uncached::{closure#3}>, core[1a8e3f3c1152e72c]::result::Result<core[1a8e3f3c1152e72c]::convert::Infallible, &rustc_middle[77f5a5ad0a03fbe5]::ty::layout::FnAbiError>> as core[1a8e3f3c1152e72c]::iter::traits::iterator::Iterator>::try_fold<(), core[1a8e3f3c1152e72c]::iter::traits::iterator::Iterator::try_for_each::call<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>, core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>, core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>::Break>::{closure#0}, core[1a8e3f3c1152e72c]::ops::control_flow::ControlFlow<rustc_target[f1139571c8f7483e]::callconv::ArgAbi<rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>>>::{closure#0}>::{closure#0}>::{closure#0}
17: 0x770c587c4ee8 - rustc_ty_utils[7aab6de42c66b8b6]::abi::fn_abi_new_uncached
18: 0x770c587bf392 - rustc_ty_utils[7aab6de42c66b8b6]::abi::fn_abi_of_instance
19: 0x770c587be818 - rustc_query_impl[fc8387517396db3d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fc8387517396db3d]::query_impl::fn_abi_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[77f5a5ad0a03fbe5]::query::erase::Erased<[u8; 16usize]>>
20: 0x770c587bb563 - rustc_query_system[3b7ccee9954445dd]::query::plumbing::try_execute_query::<rustc_query_impl[fc8387517396db3d]::DynamicConfig<rustc_query_system[3b7ccee9954445dd]::query::caches::DefaultCache<rustc_middle[77f5a5ad0a03fbe5]::ty::PseudoCanonicalInput<(rustc_middle[77f5a5ad0a03fbe5]::ty::instance::Instance, &rustc_middle[77f5a5ad0a03fbe5]::ty::list::RawList<(), rustc_middle[77f5a5ad0a03fbe5]::ty::Ty>)>, rustc_middle[77f5a5ad0a03fbe5]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[fc8387517396db3d]::plumbing::QueryCtxt, false>
21: 0x770c587bb107 - rustc_query_impl[fc8387517396db3d]::query_impl::fn_abi_of_instance::get_query_non_incr::__rust_end_short_backtrace
22: 0x770c54cfaf46 - <rustc_codegen_ssa[99f2d35fcd5a252c]::mir::FunctionCx<rustc_codegen_llvm[ddc53a90a6190b8a]::builder::GenericBuilder<rustc_codegen_llvm[ddc53a90a6190b8a]::context::FullCx>>>::codegen_terminator
23: 0x770c58ea9195 - rustc_codegen_ssa[99f2d35fcd5a252c]::mir::codegen_mir::<rustc_codegen_llvm[ddc53a90a6190b8a]::builder::GenericBuilder<rustc_codegen_llvm[ddc53a90a6190b8a]::context::FullCx>>
24: 0x770c58e8cc9b - rustc_codegen_llvm[ddc53a90a6190b8a]::base::compile_codegen_unit::module_codegen
25: 0x770c58fbf715 - <rustc_codegen_llvm[ddc53a90a6190b8a]::LlvmCodegenBackend as rustc_codegen_ssa[99f2d35fcd5a252c]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
26: 0x770c58fc1017 - <rustc_codegen_llvm[ddc53a90a6190b8a]::LlvmCodegenBackend as rustc_codegen_ssa[99f2d35fcd5a252c]::traits::backend::CodegenBackend>::codegen_crate
27: 0x770c59177345 - <rustc_interface[3173e466a85c5e7c]::queries::Linker>::codegen_and_build_linker
28: 0x770c59174bf0 - rustc_interface[3173e466a85c5e7c]::passes::create_and_enter_global_ctxt::<core[1a8e3f3c1152e72c]::option::Option<rustc_interface[3173e466a85c5e7c]::queries::Linker>, rustc_driver_impl[8fdf64b2f913ec67]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
29: 0x770c58f80b20 - rustc_interface[3173e466a85c5e7c]::interface::run_compiler::<(), rustc_driver_impl[8fdf64b2f913ec67]::run_compiler::{closure#0}>::{closure#1}
30: 0x770c58ca4412 - std[9e04a37a0a8a4f45]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3173e466a85c5e7c]::util::run_in_thread_with_globals<rustc_interface[3173e466a85c5e7c]::util::run_in_thread_pool_with_globals<rustc_interface[3173e466a85c5e7c]::interface::run_compiler<(), rustc_driver_impl[8fdf64b2f913ec67]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
31: 0x770c58ca4cf4 - <<std[9e04a37a0a8a4f45]::thread::Builder>::spawn_unchecked_<rustc_interface[3173e466a85c5e7c]::util::run_in_thread_with_globals<rustc_interface[3173e466a85c5e7c]::util::run_in_thread_pool_with_globals<rustc_interface[3173e466a85c5e7c]::interface::run_compiler<(), rustc_driver_impl[8fdf64b2f913ec67]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1a8e3f3c1152e72c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
32: 0x770c58ca60eb - std::sys::pal::unix::thread::Thread::new::thread_start::h907dccd2cf29cc8f
33: 0x770c5a4f4a94 - <unknown>
34: 0x770c5a581a34 - clone
35: 0x0 - <unknown>
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 `/playground/rustc-ice-2025-03-16T17_35_25-24.txt` to your bug report
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 [fn_abi_of_instance] computing call ABI of `<dyn Trait as Trait>::foo - virtual#3`
end of query stack
error: could not compile `playground` (lib)
@rustbot label F-arbitrary_self_types, F-dispatch_from_dyn, requires-nightly, A-trait-objects, A-layout
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with compiler/rustc_ty_utils/src/abi.rs around line 740 and the fn_abi_of_instance query named in the report. Reproduce the ICE with the provided minimal Rust example and inspect how the trait-object receiver layout is handled. Done means the example no longer triggers an internal compiler error and produces an appropriate compiler result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100