mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 09:13:07 +03:00
rustc: make TyLayout::field(NonZero<*T>, 0) return &T.
This commit is contained in:
@@ -2033,7 +2033,17 @@ pub fn field<C>(&self, cx: C, i: usize) -> C::TyLayout
|
||||
ty::TyAdt(def, substs) => {
|
||||
match self.variants {
|
||||
Variants::Single { index } => {
|
||||
def.variants[index].fields[i].ty(tcx, substs)
|
||||
let mut field_ty = def.variants[index].fields[i].ty(tcx, substs);
|
||||
|
||||
// Treat NonZero<*T> as containing &T.
|
||||
// This is especially useful for fat pointers.
|
||||
if Some(def.did) == tcx.lang_items().non_zero() {
|
||||
if let ty::TyRawPtr(mt) = field_ty.sty {
|
||||
field_ty = tcx.mk_ref(tcx.types.re_erased, mt);
|
||||
}
|
||||
}
|
||||
|
||||
field_ty
|
||||
}
|
||||
|
||||
// Discriminant field for enums (where applicable).
|
||||
@@ -2109,10 +2119,6 @@ fn non_zero_field<C>(&self, cx: C)
|
||||
let offset = self.fields.offset(0);
|
||||
if let Abi::Scalar(value) = field.abi {
|
||||
Ok(Some((offset, value)))
|
||||
} else if let ty::TyRawPtr(_) = field.ty.sty {
|
||||
// If `NonZero` contains a non-scalar `*T`, it's
|
||||
// a fat pointer, which starts with a thin pointer.
|
||||
Ok(Some((offset, Pointer)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user