Closed
Description
Code
#![feature(allocator_api)]
use core::alloc::{AllocError, Allocator, Layout};
use core::ptr::NonNull;
struct AwfulAllocator<const N: usize>([u64; N]);
unsafe impl<const N: usize> Allocator for AwfulAllocator<N> {
fn allocate(&self, _layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
todo!()
}
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
todo!()
}
}
fn main() {
let f = AwfulAllocator([0; 128]);
let _x = Box::<i32, AwfulAllocator<128>>::new_in(43, f);
}
Meta
rustc --version --verbose
:
rustc --version --verbose
rustc 1.57.0-nightly (25ec82738 2021-10-05)
binary: rustc
commit-hash: 25ec8273855fde2d72ae877b397e054de5300e10
commit-date: 2021-10-05
host: x86_64-apple-darwin
release: 1.57.0-nightly
LLVM version: 13.0.0
Error output
error: internal compiler error: /rustc/25ec8273855fde2d72ae877b397e054de5300e10/compiler/rustc_codegen_ssa/src/mir/operand.rs:132:38: Deref of by-Ref operand OperandRef(Ref((%"alloc::boxed::Box<core::mem::maybe_uninit::MaybeUninit<i32>, AwfulAllocator<128_usize>>"*: %10 = alloca %"alloc::boxed::Box<core::mem::maybe_uninit::MaybeUninit<i32>, AwfulAllocator<128_usize>>", align 8), None, Align { pow2: 3 }) @ TyAndLayout { ty: std::boxed::Box<std::mem::MaybeUninit<i32>, AwfulAllocator<128_usize>>, layout: Layout { fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 8 }], memory_index: [0, 1] }, variants: Single { index: 0 }, abi: Aggregate { sized: true }, largest_niche: Some(Niche { offset: Size { raw: 0 }, scalar: Scalar { value: Pointer, valid_range: 1..=18446744073709551615 } }), align: AbiAndPrefAlign { abi: Align { pow2: 3 }, pref: Align { pow2: 3 } }, size: Size { raw: 1032 } } })
thread 'rustc' panicked at 'Box', compiler/rustc_errors/src/lib.rs:1146:9
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::bug
3: rustc_errors::Handler::bug
4: rustc_middle::ty::context::tls::with_opt
5: rustc_middle::util::bug::opt_span_bug_fmt
6: rustc_middle::util::bug::bug_fmt
7: rustc_codegen_ssa::mir::operand::OperandRef::deref
8: rustc_codegen_ssa::mir::place::>::codegen_place
9: rustc_codegen_ssa::mir::rvalue::>::codegen_rvalue_operand
10: rustc_codegen_ssa::mir::codegen_mir
11: rustc_codegen_ssa::base::codegen_instance
12: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
13: rustc_query_system::dep_graph::graph::DepGraph::with_task
14: rustc_codegen_llvm::base::compile_codegen_unit
15: rustc_codegen_ssa::base::codegen_crate
16: ::codegen_crate
17: rustc_session::utils::::time
18: rustc_interface::queries::Queries::ongoing_codegen
19: rustc_interface::queries::::enter
20: rustc_span::with_source_map
21: scoped_tls::ScopedKey::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
note: 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.57.0-nightly (25ec827 2021-10-05) running on x86_64-apple-darwin
note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
error: could not compile s
end of query stack
error: could not compile
s
<backtrace>
Note that this does not happen if you substitute the last line with
let _x = Vec::<i32, AwfulAllocator<128>>::new_in(f);