File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -2033,7 +2033,17 @@ impl<'a, 'tcx> TyLayout<'tcx> {
2033
2033
ty:: TyAdt ( def, substs) => {
2034
2034
match self . variants {
2035
2035
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
2037
2047
}
2038
2048
2039
2049
// Discriminant field for enums (where applicable).
@@ -2109,10 +2119,6 @@ impl<'a, 'tcx> TyLayout<'tcx> {
2109
2119
let offset = self . fields . offset ( 0 ) ;
2110
2120
if let Abi :: Scalar ( value) = field. abi {
2111
2121
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 ) ) )
2116
2122
} else {
2117
2123
Ok ( None )
2118
2124
}
You can’t perform that action at this time.
0 commit comments