@@ -12,7 +12,7 @@ use std::iter;
1212use std:: mem;
1313use std:: ops:: Bound ;
1414
15- use hir;
15+ use crate :: hir;
1616use crate :: ich:: StableHashingContext ;
1717use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
1818use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher ,
@@ -1892,25 +1892,27 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
18921892
18931893 _ => {
18941894 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) ,
19141916 } ;
19151917
19161918 if let Some ( variant) = data_variant {
@@ -1931,9 +1933,8 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
19311933 result = field. ok ( )
19321934 . and_then ( |field| {
19331935 if ptr_end <= field_start + field. size {
1934- let off = offset - field_start;
19351936 // 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)
19371938 } else {
19381939 None
19391940 }
0 commit comments