@@ -499,7 +499,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
499499 let scalar_unit = |value : Primitive | {
500500 let bits = value. size ( dl) . bits ( ) ;
501501 assert ! ( bits <= 128 ) ;
502- Scalar { value, valid_range : 0 ..= ( !0 >> ( 128 - bits) ) }
502+ Scalar { value, valid_range : WrappingRange { start : 0 , end : ( !0 >> ( 128 - bits) ) } }
503503 } ;
504504 let scalar = |value : Primitive | tcx. intern_layout ( Layout :: scalar ( self , scalar_unit ( value) ) ) ;
505505
@@ -512,11 +512,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
512512 // Basic scalars.
513513 ty:: Bool => tcx. intern_layout ( Layout :: scalar (
514514 self ,
515- Scalar { value : Int ( I8 , false ) , valid_range : 0 ..= 1 } ,
515+ Scalar { value : Int ( I8 , false ) , valid_range : WrappingRange { start : 0 , end : 1 } } ,
516516 ) ) ,
517517 ty:: Char => tcx. intern_layout ( Layout :: scalar (
518518 self ,
519- Scalar { value : Int ( I32 , false ) , valid_range : 0 ..=0x10FFFF } ,
519+ Scalar {
520+ value : Int ( I32 , false ) ,
521+ valid_range : WrappingRange { start : 0 , end : 0x10FFFF } ,
522+ } ,
520523 ) ) ,
521524 ty:: Int ( ity) => scalar ( Int ( Integer :: from_int_ty ( dl, ity) , true ) ) ,
522525 ty:: Uint ( ity) => scalar ( Int ( Integer :: from_uint_ty ( dl, ity) , false ) ) ,
@@ -526,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
526529 } ) ,
527530 ty:: FnPtr ( _) => {
528531 let mut ptr = scalar_unit ( Pointer ) ;
529- ptr. valid_range = 1 ..= * ptr. valid_range . end ( ) ;
532+ ptr. valid_range = ptr. valid_range . with_start ( 1 ) ;
530533 tcx. intern_layout ( Layout :: scalar ( self , ptr) )
531534 }
532535
@@ -544,7 +547,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
544547 ty:: Ref ( _, pointee, _) | ty:: RawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
545548 let mut data_ptr = scalar_unit ( Pointer ) ;
546549 if !ty. is_unsafe_ptr ( ) {
547- data_ptr. valid_range = 1 ..= * data_ptr. valid_range . end ( ) ;
550+ data_ptr. valid_range = data_ptr. valid_range . with_start ( 1 ) ;
548551 }
549552
550553 let pointee = tcx. normalize_erasing_regions ( param_env, pointee) ;
@@ -560,7 +563,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
560563 ty:: Slice ( _) | ty:: Str => scalar_unit ( Int ( dl. ptr_sized_integer ( ) , false ) ) ,
561564 ty:: Dynamic ( ..) => {
562565 let mut vtable = scalar_unit ( Pointer ) ;
563- vtable. valid_range = 1 ..= * vtable. valid_range . end ( ) ;
566+ vtable. valid_range = vtable. valid_range . with_start ( 1 ) ;
564567 vtable
565568 }
566569 _ => return Err ( LayoutError :: Unknown ( unsized_part) ) ,
@@ -933,14 +936,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
933936 if let Bound :: Included ( start) = start {
934937 // FIXME(eddyb) this might be incorrect - it doesn't
935938 // account for wrap-around (end < start) ranges.
936- assert ! ( * scalar. valid_range. start( ) <= start) ;
937- scalar. valid_range = start..= * scalar . valid_range . end ( ) ;
939+ assert ! ( scalar. valid_range. start <= start) ;
940+ scalar. valid_range . start = start;
938941 }
939942 if let Bound :: Included ( end) = end {
940943 // FIXME(eddyb) this might be incorrect - it doesn't
941944 // account for wrap-around (end < start) ranges.
942- assert ! ( * scalar. valid_range. end( ) >= end) ;
943- scalar. valid_range = * scalar . valid_range . start ( ) ..= end;
945+ assert ! ( scalar. valid_range. end >= end) ;
946+ scalar. valid_range . end = end;
944947 }
945948
946949 // Update `largest_niche` if we have introduced a larger niche.
@@ -1256,7 +1259,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12561259 let tag_mask = !0u128 >> ( 128 - ity. size ( ) . bits ( ) ) ;
12571260 let tag = Scalar {
12581261 value : Int ( ity, signed) ,
1259- valid_range : ( min as u128 & tag_mask) ..=( max as u128 & tag_mask) ,
1262+ valid_range : WrappingRange {
1263+ start : ( min as u128 & tag_mask) ,
1264+ end : ( max as u128 & tag_mask) ,
1265+ } ,
12601266 } ;
12611267 let mut abi = Abi :: Aggregate { sized : true } ;
12621268 if tag. value . size ( dl) == size {
@@ -1535,7 +1541,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
15351541 let max_discr = ( info. variant_fields . len ( ) - 1 ) as u128 ;
15361542 let discr_int = Integer :: fit_unsigned ( max_discr) ;
15371543 let discr_int_ty = discr_int. to_ty ( tcx, false ) ;
1538- let tag = Scalar { value : Primitive :: Int ( discr_int, false ) , valid_range : 0 ..=max_discr } ;
1544+ let tag = Scalar {
1545+ value : Primitive :: Int ( discr_int, false ) ,
1546+ valid_range : WrappingRange { start : 0 , end : max_discr } ,
1547+ } ;
15391548 let tag_layout = self . tcx . intern_layout ( Layout :: scalar ( self , tag. clone ( ) ) ) ;
15401549 let tag_layout = TyAndLayout { ty : discr_int_ty, layout : tag_layout } ;
15411550
@@ -2846,10 +2855,8 @@ where
28462855 return ;
28472856 }
28482857
2849- if scalar. valid_range . start ( ) < scalar. valid_range . end ( ) {
2850- if * scalar. valid_range . start ( ) > 0 {
2851- attrs. set ( ArgAttribute :: NonNull ) ;
2852- }
2858+ if !scalar. valid_range . contains_zero ( ) {
2859+ attrs. set ( ArgAttribute :: NonNull ) ;
28532860 }
28542861
28552862 if let Some ( pointee) = layout. pointee_info_at ( cx, offset) {
0 commit comments