@@ -12,7 +12,7 @@ use std::iter;
12
12
use std:: mem;
13
13
use std:: ops:: Bound ;
14
14
15
- use hir;
15
+ use crate :: hir;
16
16
use crate :: ich:: StableHashingContext ;
17
17
use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
18
18
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher ,
@@ -1892,25 +1892,27 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1892
1892
1893
1893
_ => {
1894
1894
let mut data_variant = match this. variants {
1895
- Variants :: NicheFilling { dataful_variant, .. } => {
1896
- // Only the niche in this is always initialized,
1897
- // so only check for a pointer at its offset.
1898
- //
1899
- // If the niche is a pointer, it's either valid
1900
- // (according to its type), or null (which the
1901
- // niche field's scalar validity range encodes).
1902
- // This allows using `dereferenceable_or_null`
1903
- // for e.g., `Option<&T>`, and this will continue
1904
- // to work as long as we don't start using more
1905
- // niches than just null (e.g., the first page
1906
- // of the address space, or unaligned pointers).
1907
- if this. fields . offset ( 0 ) == offset {
1908
- Some ( this. for_variant ( cx, dataful_variant) )
1909
- } else {
1910
- None
1911
- }
1912
- }
1913
- _ => Some ( this)
1895
+ // Within the discriminant field, only the niche itself is
1896
+ // always initialized, so we only check for a pointer at its
1897
+ // offset.
1898
+ //
1899
+ // If the niche is a pointer, it's either valid (according
1900
+ // to its type), or null (which the niche field's scalar
1901
+ // validity range encodes). This allows using
1902
+ // `dereferenceable_or_null` for e.g., `Option<&T>`, and
1903
+ // this will continue to work as long as we don't start
1904
+ // using more niches than just null (e.g., the first page of
1905
+ // the address space, or unaligned pointers).
1906
+ Variants :: Multiple {
1907
+ discr_kind : DiscriminantKind :: Niche {
1908
+ dataful_variant,
1909
+ ..
1910
+ } ,
1911
+ discr_index,
1912
+ ..
1913
+ } if this. fields . offset ( discr_index) == offset =>
1914
+ Some ( this. for_variant ( cx, dataful_variant) ) ,
1915
+ _ => Some ( this) ,
1914
1916
} ;
1915
1917
1916
1918
if let Some ( variant) = data_variant {
@@ -1931,9 +1933,8 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1931
1933
result = field. ok ( )
1932
1934
. and_then ( |field| {
1933
1935
if ptr_end <= field_start + field. size {
1934
- let off = offset - field_start;
1935
1936
// We found the right field, look inside it.
1936
- Self :: pointee_info_at ( field , cx, off , param_env)
1937
+ field . pointee_info_at ( cx, offset - field_start , param_env)
1937
1938
} else {
1938
1939
None
1939
1940
}
0 commit comments