@@ -818,125 +818,114 @@ where
818818 let tcx = cx. tcx ( ) ;
819819 let param_env = cx. param_env ( ) ;
820820
821- let pointee_info =
822- match * this. ty . kind ( ) {
823- ty:: RawPtr ( mt) if offset. bytes ( ) == 0 => {
824- tcx. layout_of ( param_env. and ( mt. ty ) ) . ok ( ) . map ( |layout| PointeeInfo {
825- size : layout. size ,
826- align : layout. align . abi ,
827- safe : None ,
828- } )
829- }
830- ty:: FnPtr ( fn_sig) if offset. bytes ( ) == 0 => {
831- tcx. layout_of ( param_env. and ( tcx. mk_fn_ptr ( fn_sig) ) ) . ok ( ) . map ( |layout| {
832- PointeeInfo { size : layout. size , align : layout. align . abi , safe : None }
833- } )
834- }
835- ty:: Ref ( _, ty, mt) if offset. bytes ( ) == 0 => {
836- let kind = if tcx. sess . opts . optimize == OptLevel :: No {
837- // Use conservative pointer kind if not optimizing. This saves us the
838- // Freeze/Unpin queries, and can save time in the codegen backend (noalias
839- // attributes in LLVM have compile-time cost even in unoptimized builds).
840- PointerKind :: SharedMutable
841- } else {
842- match mt {
843- hir:: Mutability :: Not => {
844- if ty. is_freeze ( tcx, cx. param_env ( ) ) {
845- PointerKind :: Frozen
846- } else {
847- PointerKind :: SharedMutable
848- }
849- }
850- hir:: Mutability :: Mut => {
851- // References to self-referential structures should not be considered
852- // noalias, as another pointer to the structure can be obtained, that
853- // is not based-on the original reference. We consider all !Unpin
854- // types to be potentially self-referential here.
855- if ty. is_unpin ( tcx, cx. param_env ( ) ) {
856- PointerKind :: UniqueBorrowed
857- } else {
858- PointerKind :: UniqueBorrowedPinned
859- }
860- }
861- }
862- } ;
821+ let pointee_info = match * this. ty . kind ( ) {
822+ ty:: RawPtr ( mt) if offset. bytes ( ) == 0 => {
823+ tcx. layout_of ( param_env. and ( mt. ty ) ) . ok ( ) . map ( |layout| PointeeInfo {
824+ size : layout. size ,
825+ align : layout. align . abi ,
826+ safe : None ,
827+ } )
828+ }
829+ ty:: FnPtr ( fn_sig) if offset. bytes ( ) == 0 => {
830+ tcx. layout_of ( param_env. and ( tcx. mk_fn_ptr ( fn_sig) ) ) . ok ( ) . map ( |layout| PointeeInfo {
831+ size : layout. size ,
832+ align : layout. align . abi ,
833+ safe : None ,
834+ } )
835+ }
836+ ty:: Ref ( _, ty, mt) if offset. bytes ( ) == 0 => {
837+ // Use conservative pointer kind if not optimizing. This saves us the
838+ // Freeze/Unpin queries, and can save time in the codegen backend (noalias
839+ // attributes in LLVM have compile-time cost even in unoptimized builds).
840+ let optimize = tcx. sess . opts . optimize != OptLevel :: No ;
841+ let kind = match mt {
842+ hir:: Mutability :: Not => PointerKind :: SharedRef {
843+ frozen : optimize && ty. is_freeze ( tcx, cx. param_env ( ) ) ,
844+ } ,
845+ hir:: Mutability :: Mut => PointerKind :: MutableRef {
846+ unpin : optimize && ty. is_unpin ( tcx, cx. param_env ( ) ) ,
847+ } ,
848+ } ;
863849
864- tcx. layout_of ( param_env. and ( ty) ) . ok ( ) . map ( |layout| PointeeInfo {
865- size : layout. size ,
866- align : layout. align . abi ,
867- safe : Some ( kind) ,
868- } )
869- }
850+ tcx. layout_of ( param_env. and ( ty) ) . ok ( ) . map ( |layout| PointeeInfo {
851+ size : layout. size ,
852+ align : layout. align . abi ,
853+ safe : Some ( kind) ,
854+ } )
855+ }
870856
871- _ => {
872- let mut data_variant = match this. variants {
873- // Within the discriminant field, only the niche itself is
874- // always initialized, so we only check for a pointer at its
875- // offset.
876- //
877- // If the niche is a pointer, it's either valid (according
878- // to its type), or null (which the niche field's scalar
879- // validity range encodes). This allows using
880- // `dereferenceable_or_null` for e.g., `Option<&T>`, and
881- // this will continue to work as long as we don't start
882- // using more niches than just null (e.g., the first page of
883- // the address space, or unaligned pointers).
884- Variants :: Multiple {
885- tag_encoding : TagEncoding :: Niche { untagged_variant, .. } ,
886- tag_field,
887- ..
888- } if this. fields . offset ( tag_field) == offset => {
889- Some ( this. for_variant ( cx, untagged_variant) )
890- }
891- _ => Some ( this) ,
892- } ;
857+ _ => {
858+ let mut data_variant = match this. variants {
859+ // Within the discriminant field, only the niche itself is
860+ // always initialized, so we only check for a pointer at its
861+ // offset.
862+ //
863+ // If the niche is a pointer, it's either valid (according
864+ // to its type), or null (which the niche field's scalar
865+ // validity range encodes). This allows using
866+ // `dereferenceable_or_null` for e.g., `Option<&T>`, and
867+ // this will continue to work as long as we don't start
868+ // using more niches than just null (e.g., the first page of
869+ // the address space, or unaligned pointers).
870+ Variants :: Multiple {
871+ tag_encoding : TagEncoding :: Niche { untagged_variant, .. } ,
872+ tag_field,
873+ ..
874+ } if this. fields . offset ( tag_field) == offset => {
875+ Some ( this. for_variant ( cx, untagged_variant) )
876+ }
877+ _ => Some ( this) ,
878+ } ;
893879
894- if let Some ( variant) = data_variant {
895- // We're not interested in any unions.
896- if let FieldsShape :: Union ( _) = variant. fields {
897- data_variant = None ;
898- }
880+ if let Some ( variant) = data_variant {
881+ // We're not interested in any unions.
882+ if let FieldsShape :: Union ( _) = variant. fields {
883+ data_variant = None ;
899884 }
885+ }
900886
901- let mut result = None ;
902-
903- if let Some ( variant) = data_variant {
904- // FIXME(erikdesjardins): handle non-default addrspace ptr sizes
905- // (requires passing in the expected address space from the caller)
906- let ptr_end = offset + Pointer ( AddressSpace :: DATA ) . size ( cx) ;
907- for i in 0 ..variant. fields . count ( ) {
908- let field_start = variant. fields . offset ( i) ;
909- if field_start <= offset {
910- let field = variant. field ( cx, i) ;
911- result = field. to_result ( ) . ok ( ) . and_then ( |field| {
912- if ptr_end <= field_start + field. size {
913- // We found the right field, look inside it.
914- let field_info =
915- field. pointee_info_at ( cx, offset - field_start) ;
916- field_info
917- } else {
918- None
919- }
920- } ) ;
921- if result. is_some ( ) {
922- break ;
887+ let mut result = None ;
888+
889+ if let Some ( variant) = data_variant {
890+ // FIXME(erikdesjardins): handle non-default addrspace ptr sizes
891+ // (requires passing in the expected address space from the caller)
892+ let ptr_end = offset + Pointer ( AddressSpace :: DATA ) . size ( cx) ;
893+ for i in 0 ..variant. fields . count ( ) {
894+ let field_start = variant. fields . offset ( i) ;
895+ if field_start <= offset {
896+ let field = variant. field ( cx, i) ;
897+ result = field. to_result ( ) . ok ( ) . and_then ( |field| {
898+ if ptr_end <= field_start + field. size {
899+ // We found the right field, look inside it.
900+ let field_info =
901+ field. pointee_info_at ( cx, offset - field_start) ;
902+ field_info
903+ } else {
904+ None
923905 }
906+ } ) ;
907+ if result. is_some ( ) {
908+ break ;
924909 }
925910 }
926911 }
912+ }
927913
928- // FIXME(eddyb) This should be for `ptr::Unique<T>`, not `Box<T>`.
929- if let Some ( ref mut pointee) = result {
930- if let ty:: Adt ( def, _) = this. ty . kind ( ) {
931- if def. is_box ( ) && offset. bytes ( ) == 0 {
932- pointee. safe = Some ( PointerKind :: UniqueOwned ) ;
933- }
914+ // FIXME(eddyb) This should be for `ptr::Unique<T>`, not `Box<T>`.
915+ if let Some ( ref mut pointee) = result {
916+ if let ty:: Adt ( def, _) = this. ty . kind ( ) {
917+ if def. is_box ( ) && offset. bytes ( ) == 0 {
918+ let optimize = tcx. sess . opts . optimize != OptLevel :: No ;
919+ pointee. safe = Some ( PointerKind :: Box {
920+ unpin : optimize && this. ty . boxed_ty ( ) . is_unpin ( tcx, cx. param_env ( ) ) ,
921+ } ) ;
934922 }
935923 }
936-
937- result
938924 }
939- } ;
925+
926+ result
927+ }
928+ } ;
940929
941930 debug ! (
942931 "pointee_info_at (offset={:?}, type kind: {:?}) => {:?}" ,
0 commit comments