Pattern types have their base type as a field
This commit is contained in:
parent
e821cb8dd9
commit
d9f22d289c
4 changed files with 53 additions and 6 deletions
|
|
@ -839,11 +839,15 @@ where
|
|||
| ty::FnDef(..)
|
||||
| ty::CoroutineWitness(..)
|
||||
| ty::Foreign(..)
|
||||
| ty::Pat(_, _)
|
||||
| ty::Dynamic(_, _) => {
|
||||
bug!("TyAndLayout::field({:?}): not applicable", this)
|
||||
}
|
||||
|
||||
ty::Pat(base, _) => {
|
||||
assert_eq!(i, 0);
|
||||
TyMaybeWithLayout::Ty(base)
|
||||
}
|
||||
|
||||
ty::UnsafeBinder(bound_ty) => {
|
||||
let ty = tcx.instantiate_bound_regions_with_erased(bound_ty.into());
|
||||
field_ty_or_layout(TyAndLayout { ty, ..this }, cx, i)
|
||||
|
|
|
|||
|
|
@ -350,6 +350,14 @@ fn layout_of_uncached<'tcx>(
|
|||
ty::PatternKind::Or(..) => bug!("patterns cannot have nested or patterns"),
|
||||
},
|
||||
}
|
||||
// Pattern types contain their base as their sole field.
|
||||
// This allows the rest of the compiler to process pattern types just like
|
||||
// single field transparent Adts, and only the parts of the compiler that
|
||||
// specifically care about pattern types will have to handle it.
|
||||
layout.fields = FieldsShape::Arbitrary {
|
||||
offsets: [Size::ZERO].into_iter().collect(),
|
||||
memory_index: [0].into_iter().collect(),
|
||||
};
|
||||
tcx.mk_layout(layout)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,14 @@ error: layout_of((i8) is (i8::MIN..=-1 | 1..)) = Layout {
|
|||
valid_range: 1..=255,
|
||||
},
|
||||
),
|
||||
fields: Primitive,
|
||||
fields: Arbitrary {
|
||||
offsets: [
|
||||
Size(0 bytes),
|
||||
],
|
||||
memory_index: [
|
||||
0,
|
||||
],
|
||||
},
|
||||
largest_niche: Some(
|
||||
Niche {
|
||||
offset: Size(0 bytes),
|
||||
|
|
@ -91,7 +98,14 @@ error: layout_of((i8) is (i8::MIN..=-2 | 0..)) = Layout {
|
|||
valid_range: 0..=254,
|
||||
},
|
||||
),
|
||||
fields: Primitive,
|
||||
fields: Arbitrary {
|
||||
offsets: [
|
||||
Size(0 bytes),
|
||||
],
|
||||
memory_index: [
|
||||
0,
|
||||
],
|
||||
},
|
||||
largest_niche: Some(
|
||||
Niche {
|
||||
offset: Size(0 bytes),
|
||||
|
|
|
|||
|
|
@ -57,7 +57,14 @@ error: layout_of((u32) is 1..) = Layout {
|
|||
valid_range: 1..=4294967295,
|
||||
},
|
||||
),
|
||||
fields: Primitive,
|
||||
fields: Arbitrary {
|
||||
offsets: [
|
||||
Size(0 bytes),
|
||||
],
|
||||
memory_index: [
|
||||
0,
|
||||
],
|
||||
},
|
||||
largest_niche: Some(
|
||||
Niche {
|
||||
offset: Size(0 bytes),
|
||||
|
|
@ -390,7 +397,14 @@ error: layout_of((i8) is -10..=10) = Layout {
|
|||
valid_range: (..=10) | (246..),
|
||||
},
|
||||
),
|
||||
fields: Primitive,
|
||||
fields: Arbitrary {
|
||||
offsets: [
|
||||
Size(0 bytes),
|
||||
],
|
||||
memory_index: [
|
||||
0,
|
||||
],
|
||||
},
|
||||
largest_niche: Some(
|
||||
Niche {
|
||||
offset: Size(0 bytes),
|
||||
|
|
@ -428,7 +442,14 @@ error: layout_of((i8) is i8::MIN..=0) = Layout {
|
|||
valid_range: (..=0) | (128..),
|
||||
},
|
||||
),
|
||||
fields: Primitive,
|
||||
fields: Arbitrary {
|
||||
offsets: [
|
||||
Size(0 bytes),
|
||||
],
|
||||
memory_index: [
|
||||
0,
|
||||
],
|
||||
},
|
||||
largest_niche: Some(
|
||||
Niche {
|
||||
offset: Size(0 bytes),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue