Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/rustc_middle/src/ty/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ pub(super) fn vtable_allocation_provider<'tcx>(
// This confirms that the layout computation for &dyn Trait has an accurate sizing.
assert!(vtable_entries.len() >= vtable_min_entries(tcx, poly_trait_ref));

let layout = tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty))
.expect("failed to build vtable representation");
let layout = match tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)) {
Ok(layout) => layout,
Err(e) => tcx.dcx().emit_fatal(e.into_diagnostic()),
};
assert!(layout.is_sized(), "can't create a vtable for an unsized type");
let size = layout.size.bytes();
let align = layout.align.bytes();
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/limits/vtable-try-as-dyn.full-debuginfo.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: values of the type `[u8; usize::MAX]` are too big for the target architecture

error: aborting due to 1 previous error

4 changes: 4 additions & 0 deletions tests/ui/limits/vtable-try-as-dyn.no-debuginfo.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: values of the type `[u8; usize::MAX]` are too big for the target architecture

error: aborting due to 1 previous error

15 changes: 15 additions & 0 deletions tests/ui/limits/vtable-try-as-dyn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// At the time of writing, vtable.rs would ICE only with debuginfo disabled, while this testcase,
// originally reported as #152030, would ICE even with debuginfo enabled.
//@ revisions: no-debuginfo full-debuginfo
//@ compile-flags: --crate-type=lib --emit=mir
//@[no-debuginfo] compile-flags: -C debuginfo=0
//@[full-debuginfo] compile-flags: -C debuginfo=2
#![feature(try_as_dyn)]

trait Trait {}
impl<T> Trait for T {}

//~? ERROR: values of the type `[u8; usize::MAX]` are too big for the target architecture
pub fn foo(x: &[u8; usize::MAX]) {
let _ = std::any::try_as_dyn::<[u8; usize::MAX], dyn Trait>(x);
}
8 changes: 8 additions & 0 deletions tests/ui/limits/vtable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ compile-flags: --crate-type=lib --emit=mir -C debuginfo=0
pub trait Trait {}
impl<T> Trait for T {}

//~? ERROR: values of the type `[u8; usize::MAX]` are too big for the target architecture
pub fn foo(x: &[u8; usize::MAX]) -> &dyn Trait {
x as &dyn Trait
}
4 changes: 4 additions & 0 deletions tests/ui/limits/vtable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: values of the type `[u8; usize::MAX]` are too big for the target architecture

error: aborting due to 1 previous error

Loading