@@ -1389,20 +1389,15 @@ impl<'tcx> IntRange<'tcx> {
1389
1389
}
1390
1390
}
1391
1391
1392
- /// Converts a `RangeInclusive` to a `ConstantValue` or inclusive `ConstantRange`.
1393
- fn range_to_ctor (
1394
- tcx : TyCtxt < ' tcx > ,
1395
- ty : Ty < ' tcx > ,
1396
- r : RangeInclusive < u128 > ,
1397
- span : Span ,
1398
- ) -> Constructor < ' tcx > {
1399
- let bias = IntRange :: signed_bias ( tcx, ty) ;
1400
- let ( lo, hi) = r. into_inner ( ) ;
1392
+ /// Converts an `IntRange` to a `ConstantValue` or inclusive `ConstantRange`.
1393
+ fn into_ctor ( self , tcx : TyCtxt < ' tcx > ) -> Constructor < ' tcx > {
1394
+ let bias = IntRange :: signed_bias ( tcx, self . ty ) ;
1395
+ let ( lo, hi) = self . range . into_inner ( ) ;
1401
1396
if lo == hi {
1402
- let ty = ty:: ParamEnv :: empty ( ) . and ( ty) ;
1403
- ConstantValue ( ty:: Const :: from_bits ( tcx, lo ^ bias, ty) , span)
1397
+ let ty = ty:: ParamEnv :: empty ( ) . and ( self . ty ) ;
1398
+ ConstantValue ( ty:: Const :: from_bits ( tcx, lo ^ bias, ty) , self . span )
1404
1399
} else {
1405
- ConstantRange ( lo ^ bias, hi ^ bias, ty, RangeEnd :: Included , span)
1400
+ ConstantRange ( lo ^ bias, hi ^ bias, self . ty , RangeEnd :: Included , self . span )
1406
1401
}
1407
1402
}
1408
1403
@@ -1419,38 +1414,27 @@ impl<'tcx> IntRange<'tcx> {
1419
1414
. filter_map ( |r| IntRange :: from_ctor ( tcx, param_env, & r) . map ( |i| i. range ) ) ;
1420
1415
let mut remaining_ranges = vec ! [ ] ;
1421
1416
let ty = self . ty ;
1417
+ let span = self . span ;
1422
1418
let ( lo, hi) = self . range . into_inner ( ) ;
1423
1419
for subrange in ranges {
1424
1420
let ( subrange_lo, subrange_hi) = subrange. into_inner ( ) ;
1425
1421
if lo > subrange_hi || subrange_lo > hi {
1426
1422
// The pattern doesn't intersect with the subrange at all,
1427
1423
// so the subrange remains untouched.
1428
- remaining_ranges. push ( Self :: range_to_ctor (
1429
- tcx,
1430
- ty,
1431
- subrange_lo..=subrange_hi,
1432
- self . span ,
1433
- ) ) ;
1424
+ remaining_ranges
1425
+ . push ( IntRange { range : subrange_lo..=subrange_hi, ty, span } . into_ctor ( tcx) ) ;
1434
1426
} else {
1435
1427
if lo > subrange_lo {
1436
1428
// The pattern intersects an upper section of the
1437
1429
// subrange, so a lower section will remain.
1438
- remaining_ranges. push ( Self :: range_to_ctor (
1439
- tcx,
1440
- ty,
1441
- subrange_lo..=( lo - 1 ) ,
1442
- self . span ,
1443
- ) ) ;
1430
+ remaining_ranges
1431
+ . push ( IntRange { range : subrange_lo..=( lo - 1 ) , ty, span } . into_ctor ( tcx) ) ;
1444
1432
}
1445
1433
if hi < subrange_hi {
1446
1434
// The pattern intersects a lower section of the
1447
1435
// subrange, so an upper section will remain.
1448
- remaining_ranges. push ( Self :: range_to_ctor (
1449
- tcx,
1450
- ty,
1451
- ( hi + 1 ) ..=subrange_hi,
1452
- self . span ,
1453
- ) ) ;
1436
+ remaining_ranges
1437
+ . push ( IntRange { range : ( hi + 1 ) ..=subrange_hi, ty, span } . into_ctor ( tcx) ) ;
1454
1438
}
1455
1439
}
1456
1440
}
@@ -1964,23 +1948,24 @@ fn split_grouped_constructors<'p, 'tcx>(
1964
1948
// We're going to iterate through every adjacent pair of borders, making sure that
1965
1949
// each represents an interval of nonnegative length, and convert each such
1966
1950
// interval into a constructor.
1967
- for IntRange { range, .. } in
1968
- borders. windows ( 2 ) . filter_map ( |window| match ( window[ 0 ] , window[ 1 ] ) {
1969
- ( Border :: JustBefore ( n) , Border :: JustBefore ( m) ) => {
1970
- if n < m {
1971
- Some ( IntRange { range : n..=( m - 1 ) , ty, span } )
1972
- } else {
1973
- None
1951
+ split_ctors. extend (
1952
+ borders
1953
+ . windows ( 2 )
1954
+ . filter_map ( |window| match ( window[ 0 ] , window[ 1 ] ) {
1955
+ ( Border :: JustBefore ( n) , Border :: JustBefore ( m) ) => {
1956
+ if n < m {
1957
+ Some ( IntRange { range : n..=( m - 1 ) , ty, span } )
1958
+ } else {
1959
+ None
1960
+ }
1974
1961
}
1975
- }
1976
- ( Border :: JustBefore ( n) , Border :: AfterMax ) => {
1977
- Some ( IntRange { range : n..=u128:: MAX , ty, span } )
1978
- }
1979
- ( Border :: AfterMax , _) => None ,
1980
- } )
1981
- {
1982
- split_ctors. push ( IntRange :: range_to_ctor ( tcx, ty, range, span) ) ;
1983
- }
1962
+ ( Border :: JustBefore ( n) , Border :: AfterMax ) => {
1963
+ Some ( IntRange { range : n..=u128:: MAX , ty, span } )
1964
+ }
1965
+ ( Border :: AfterMax , _) => None ,
1966
+ } )
1967
+ . map ( |range| range. into_ctor ( tcx) ) ,
1968
+ ) ;
1984
1969
}
1985
1970
VarLenSlice ( self_prefix, self_suffix) => {
1986
1971
// The exhaustiveness-checking paper does not include any details on
@@ -2127,7 +2112,9 @@ fn lint_overlapping_patterns(
2127
2112
int_range. span ,
2128
2113
& format ! (
2129
2114
"this range overlaps on `{}`" ,
2130
- IntRange :: range_to_ctor( tcx, ty, int_range. range, DUMMY_SP ) . display( tcx) ,
2115
+ IntRange { range: int_range. range, ty, span: DUMMY_SP }
2116
+ . into_ctor( tcx)
2117
+ . display( tcx) ,
2131
2118
) ,
2132
2119
) ;
2133
2120
}
0 commit comments