Description
While working on #77438, I've run into the following ICE. It seems to be caused by the type layout code not expecting On further consideration, the issue also appears with Box
to have more than 3 fields, in this case the fat pointer containing two fields, plus the AllocRef
instance.Box<T, A>
as long as A
is non zero sized.
This ICE was likely not encountered during testing of #77187 because in the case of Box<T, Global>
, Global
is zero sized. In the example below, removing the borrow of Global
will cause the compilation to succeed.
@eddyb could you take a look at this? :)
cc @TimDiekmann you may run into this as well on RawVec
Code
Old code
#![feature(allocator_api)]
fn main() {
Box::new_in(&[0, 1], &std::alloc::Global);
}
New, more minimal code
#![feature(allocator_api)]
fn main() {
Box::new_in((), &std::alloc::Global);
}
Meta
rustc --version --verbose
:
rustc 1.49.0-nightly (fd542592f 2020-10-26) running on x86_64-unknown-linux-gnu - playground
rustc 1.48.0-beta.3 (4708ac76e 2020-10-15) running on x86_64-unknown-linux-gnu - local dev environment
Error output
rust/compiler/rustc_middle/src/ty/layout.rs
Line 2056 in 07e968b
thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/fd542592f08ca0d1f7255600115c2eafdf6b5da7/compiler/rustc_middle/src/ty/layout.rs:2056:17
Backtrace
From playground
thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/fd542592f08ca0d1f7255600115c2eafdf6b5da7/compiler/rustc_middle/src/ty/layout.rs:2056:17
stack backtrace:
0: std::panicking::begin_panic
1: rustc_middle::ty::layout::<impl rustc_target::abi::TyAndLayoutMethods<C> for &rustc_middle::ty::TyS>::field
2: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::scalar_pair_element_llvm_type
3: <rustc_target::abi::TyAndLayout<&rustc_middle::ty::TyS> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::scalar_pair_element_llvm_type
4: <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_codegen_llvm::abi::FnAbiLlvmExt>::llvm_type
5: rustc_codegen_llvm::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods for rustc_codegen_llvm::context::CodegenCx>::predefine_fn
6: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
7: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
8: rustc_codegen_llvm::base::compile_codegen_unit
9: rustc_codegen_ssa::base::codegen_crate
10: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
11: rustc_interface::passes::QueryContext::enter
12: rustc_interface::queries::Queries::ongoing_codegen
13: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
14: rustc_span::with_source_map
15: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.