@@ -499,7 +499,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
499
499
let scalar_unit = |value : Primitive | {
500
500
let bits = value. size ( dl) . bits ( ) ;
501
501
assert ! ( bits <= 128 ) ;
502
- Scalar { value, valid_range : 0 ..= ( !0 >> ( 128 - bits) ) }
502
+ Scalar { value, valid_range : WrappingRange { start : 0 , end : ( !0 >> ( 128 - bits) ) } }
503
503
} ;
504
504
let scalar = |value : Primitive | tcx. intern_layout ( Layout :: scalar ( self , scalar_unit ( value) ) ) ;
505
505
@@ -512,11 +512,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
512
512
// Basic scalars.
513
513
ty:: Bool => tcx. intern_layout ( Layout :: scalar (
514
514
self ,
515
- Scalar { value : Int ( I8 , false ) , valid_range : 0 ..= 1 } ,
515
+ Scalar { value : Int ( I8 , false ) , valid_range : WrappingRange { start : 0 , end : 1 } } ,
516
516
) ) ,
517
517
ty:: Char => tcx. intern_layout ( Layout :: scalar (
518
518
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
+ } ,
520
523
) ) ,
521
524
ty:: Int ( ity) => scalar ( Int ( Integer :: from_int_ty ( dl, ity) , true ) ) ,
522
525
ty:: Uint ( ity) => scalar ( Int ( Integer :: from_uint_ty ( dl, ity) , false ) ) ,
@@ -526,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
526
529
} ) ,
527
530
ty:: FnPtr ( _) => {
528
531
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 ) ;
530
533
tcx. intern_layout ( Layout :: scalar ( self , ptr) )
531
534
}
532
535
@@ -544,7 +547,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
544
547
ty:: Ref ( _, pointee, _) | ty:: RawPtr ( ty:: TypeAndMut { ty : pointee, .. } ) => {
545
548
let mut data_ptr = scalar_unit ( Pointer ) ;
546
549
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 ) ;
548
551
}
549
552
550
553
let pointee = tcx. normalize_erasing_regions ( param_env, pointee) ;
@@ -560,7 +563,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
560
563
ty:: Slice ( _) | ty:: Str => scalar_unit ( Int ( dl. ptr_sized_integer ( ) , false ) ) ,
561
564
ty:: Dynamic ( ..) => {
562
565
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 ) ;
564
567
vtable
565
568
}
566
569
_ => return Err ( LayoutError :: Unknown ( unsized_part) ) ,
@@ -933,14 +936,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
933
936
if let Bound :: Included ( start) = start {
934
937
// FIXME(eddyb) this might be incorrect - it doesn't
935
938
// 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;
938
941
}
939
942
if let Bound :: Included ( end) = end {
940
943
// FIXME(eddyb) this might be incorrect - it doesn't
941
944
// 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;
944
947
}
945
948
946
949
// Update `largest_niche` if we have introduced a larger niche.
@@ -1256,7 +1259,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1256
1259
let tag_mask = !0u128 >> ( 128 - ity. size ( ) . bits ( ) ) ;
1257
1260
let tag = Scalar {
1258
1261
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
+ } ,
1260
1266
} ;
1261
1267
let mut abi = Abi :: Aggregate { sized : true } ;
1262
1268
if tag. value . size ( dl) == size {
@@ -1535,7 +1541,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
1535
1541
let max_discr = ( info. variant_fields . len ( ) - 1 ) as u128 ;
1536
1542
let discr_int = Integer :: fit_unsigned ( max_discr) ;
1537
1543
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
+ } ;
1539
1548
let tag_layout = self . tcx . intern_layout ( Layout :: scalar ( self , tag. clone ( ) ) ) ;
1540
1549
let tag_layout = TyAndLayout { ty : discr_int_ty, layout : tag_layout } ;
1541
1550
@@ -2846,10 +2855,8 @@ where
2846
2855
return ;
2847
2856
}
2848
2857
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 ) ;
2853
2860
}
2854
2861
2855
2862
if let Some ( pointee) = layout. pointee_info_at ( cx, offset) {
0 commit comments