Skip to content

Commit abbc1dd

Browse files
committed
rustc: make TyLayout::field(NonZero<*T>, 0) return &T.
1 parent de3e581 commit abbc1dd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/librustc/ty/layout.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,17 @@ impl<'a, 'tcx> TyLayout<'tcx> {
20332033
ty::TyAdt(def, substs) => {
20342034
match self.variants {
20352035
Variants::Single { index } => {
2036-
def.variants[index].fields[i].ty(tcx, substs)
2036+
let mut field_ty = def.variants[index].fields[i].ty(tcx, substs);
2037+
2038+
// Treat NonZero<*T> as containing &T.
2039+
// This is especially useful for fat pointers.
2040+
if Some(def.did) == tcx.lang_items().non_zero() {
2041+
if let ty::TyRawPtr(mt) = field_ty.sty {
2042+
field_ty = tcx.mk_ref(tcx.types.re_erased, mt);
2043+
}
2044+
}
2045+
2046+
field_ty
20372047
}
20382048

20392049
// Discriminant field for enums (where applicable).
@@ -2109,10 +2119,6 @@ impl<'a, 'tcx> TyLayout<'tcx> {
21092119
let offset = self.fields.offset(0);
21102120
if let Abi::Scalar(value) = field.abi {
21112121
Ok(Some((offset, value)))
2112-
} else if let ty::TyRawPtr(_) = field.ty.sty {
2113-
// If `NonZero` contains a non-scalar `*T`, it's
2114-
// a fat pointer, which starts with a thin pointer.
2115-
Ok(Some((offset, Pointer)))
21162122
} else {
21172123
Ok(None)
21182124
}

0 commit comments

Comments
 (0)