Rollup merge of #152120 - meithecatte:push-ltvwvkqrytno, r=petrochenkov
Don't ICE on layout error in vtable computation Fixes rust-lang/rust#152030. Note: I'm including a more general testcase that doesn't use the feature in the original report, but only reproduces with debuginfo disabled. Does it make sense to also include the original testcase?
This commit is contained in:
commit
2c4656ac66
6 changed files with 39 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
4
tests/ui/limits/vtable-try-as-dyn.full-debuginfo.stderr
Normal file
4
tests/ui/limits/vtable-try-as-dyn.full-debuginfo.stderr
Normal file
|
|
@ -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
tests/ui/limits/vtable-try-as-dyn.no-debuginfo.stderr
Normal file
4
tests/ui/limits/vtable-try-as-dyn.no-debuginfo.stderr
Normal file
|
|
@ -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
tests/ui/limits/vtable-try-as-dyn.rs
Normal file
15
tests/ui/limits/vtable-try-as-dyn.rs
Normal file
|
|
@ -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
tests/ui/limits/vtable.rs
Normal file
8
tests/ui/limits/vtable.rs
Normal file
|
|
@ -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
tests/ui/limits/vtable.stderr
Normal file
4
tests/ui/limits/vtable.stderr
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue