Skip to content

Commit b201b2f

Browse files
committed
Make vtable_allocation always succeed
1 parent e9d69d9 commit b201b2f

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

compiler/rustc_codegen_cranelift/src/vtable.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ pub(crate) fn get_vtable<'tcx>(
7272
let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) {
7373
*vtable_ptr
7474
} else {
75-
let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) {
76-
Ok(alloc) => alloc,
77-
Err(_) => fx.tcx.sess.fatal("allocation of constant vtable failed"),
78-
};
75+
let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref);
7976
let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory();
8077
let vtable_ptr = pointer_for_allocation(fx, vtable_allocation);
8178

compiler/rustc_codegen_ssa/src/meth.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
7070
return val;
7171
}
7272

73-
let vtable_alloc_id = match tcx.vtable_allocation(ty, trait_ref) {
74-
Ok(alloc) => alloc,
75-
Err(_) => tcx.sess.fatal("allocation of constant vtable failed"),
76-
};
73+
let vtable_alloc_id = tcx.vtable_allocation(ty, trait_ref);
7774
let vtable_allocation = tcx.global_alloc(vtable_alloc_id).unwrap_memory();
7875
let vtable_const = cx.const_data_from_alloc(vtable_allocation);
7976
let align = cx.data_layout().pointer_align.abi;

compiler/rustc_middle/src/ty/vtable.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::TryFrom;
22

3-
use crate::mir::interpret::{alloc_range, AllocId, Allocation, InterpResult, Pointer, Scalar};
3+
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar};
44
use crate::ty::fold::TypeFoldable;
55
use crate::ty::{self, DefId, SubstsRef, Ty, TyCtxt};
66
use rustc_ast::Mutability;
@@ -28,11 +28,11 @@ impl<'tcx> TyCtxt<'tcx> {
2828
self,
2929
ty: Ty<'tcx>,
3030
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
31-
) -> InterpResult<'tcx, AllocId> {
31+
) -> AllocId {
3232
let tcx = self;
3333
let vtables_cache = tcx.vtables_cache.lock();
3434
if let Some(alloc_id) = vtables_cache.get(&(ty, poly_trait_ref)).cloned() {
35-
return Ok(alloc_id);
35+
return alloc_id;
3636
}
3737
drop(vtables_cache);
3838

@@ -60,7 +60,8 @@ impl<'tcx> TyCtxt<'tcx> {
6060
let ptr_align = tcx.data_layout.pointer_align.abi;
6161

6262
let vtable_size = ptr_size * u64::try_from(vtable_entries.len()).unwrap();
63-
let mut vtable = Allocation::uninit(vtable_size, ptr_align, true)?;
63+
let mut vtable =
64+
Allocation::uninit(vtable_size, ptr_align, /* panic_on_fail */ true).unwrap();
6465

6566
// No need to do any alignment checks on the memory accesses below, because we know the
6667
// allocation is correctly aligned as we created it above. Also we're only offsetting by
@@ -101,6 +102,6 @@ impl<'tcx> TyCtxt<'tcx> {
101102
let alloc_id = tcx.create_memory_alloc(tcx.intern_const_alloc(vtable));
102103
let mut vtables_cache = self.vtables_cache.lock();
103104
vtables_cache.insert((ty, poly_trait_ref), alloc_id);
104-
Ok(alloc_id)
105+
alloc_id
105106
}
106107
}

compiler/rustc_mir/src/interpret/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3030
ensure_monomorphic_enough(*self.tcx, ty)?;
3131
ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?;
3232

33-
let vtable_allocation = self.tcx.vtable_allocation(ty, poly_trait_ref)?;
33+
let vtable_allocation = self.tcx.vtable_allocation(ty, poly_trait_ref);
3434

3535
let vtable_ptr = self.memory.global_base_pointer(Pointer::from(vtable_allocation))?;
3636

0 commit comments

Comments
 (0)