disable some layout optimizations for unsizable structs
This commit is contained in:
parent
381b778d27
commit
3003d05a8b
@ -57,6 +57,10 @@ fn univariant(
|
||||
// run and bias niches to the right and then check which one is closer to one of the struct's
|
||||
// edges.
|
||||
if let Some(layout) = &layout {
|
||||
// Don't try to calculate an end-biased layout for unsizable structs,
|
||||
// otherwise we could end up with different layouts for
|
||||
// Foo<Type> and Foo<dyn Trait> which would break unsizing
|
||||
if !matches!(kind, StructKind::MaybeUnsized) {
|
||||
if let Some(niche) = layout.largest_niche {
|
||||
let head_space = niche.offset.bytes();
|
||||
let niche_length = niche.value.size(dl).bytes();
|
||||
@ -73,7 +77,8 @@ fn univariant(
|
||||
.expect("alt layout should have a niche like the regular one");
|
||||
let alt_head_space = niche.offset.bytes();
|
||||
let alt_niche_len = niche.value.size(dl).bytes();
|
||||
let alt_tail_space = alt_layout.size.bytes() - alt_head_space - alt_niche_len;
|
||||
let alt_tail_space =
|
||||
alt_layout.size.bytes() - alt_head_space - alt_niche_len;
|
||||
|
||||
debug_assert_eq!(layout.size.bytes(), alt_layout.size.bytes());
|
||||
|
||||
@ -103,6 +108,7 @@ fn univariant(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
layout
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user