Skip to content

Commit 6031dfd

Browse files
committed
Allow unsizing pattern types with pointer base
1 parent 71068af commit 6031dfd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/unsize.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ pub(crate) fn coerce_unsized_into<'tcx>(
131131
dst.write_cvalue(fx, CValue::by_val_pair(base, info, dst.layout()));
132132
};
133133
match (&src_ty.kind(), &dst_ty.kind()) {
134+
(ty::Pat(a, _), ty::Pat(b, _)) => {
135+
let src = src.cast_pat_ty_to_base(fx.layout_of(*a));
136+
let dst = dst.place_transmute_type(fx, *b);
137+
return coerce_unsized_into(fx, src, dst);
138+
}
134139
(&ty::Ref(..), &ty::Ref(..))
135140
| (&ty::Ref(..), &ty::RawPtr(..))
136141
| (&ty::RawPtr(..), &ty::RawPtr(..)) => coerce_ptr(),

src/value_and_place.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ impl<'tcx> CValue<'tcx> {
342342
assert_eq!(self.layout().backend_repr, layout.backend_repr);
343343
CValue(self.0, layout)
344344
}
345+
346+
pub(crate) fn cast_pat_ty_to_base(self, layout: TyAndLayout<'tcx>) -> Self {
347+
let ty::Pat(base, _) = *self.layout().ty.kind() else {
348+
panic!("not a pattern type: {:#?}", self.layout())
349+
};
350+
assert_eq!(layout.ty, base);
351+
CValue(self.0, layout)
352+
}
345353
}
346354

347355
/// A place where you can write a value to or read a value from

0 commit comments

Comments
 (0)