@@ -956,8 +956,7 @@ impl<'tcx> Constructor<'tcx> {
956
956
end,
957
957
} ) ,
958
958
IntRange ( range) => {
959
- // TODO: do it more directly
960
- return range. clone ( ) . into_ctor ( cx. tcx ) . apply ( cx, ty, None . into_iter ( ) ) ;
959
+ return range. to_pat ( cx. tcx ) ;
961
960
}
962
961
NonExhaustive => PatKind :: Wild ,
963
962
} ;
@@ -1398,19 +1397,6 @@ impl<'tcx> IntRange<'tcx> {
1398
1397
}
1399
1398
}
1400
1399
1401
- /// Converts an `IntRange` to a `ConstantValue` or inclusive `ConstantRange`.
1402
- /// TODO: Deprecated
1403
- fn into_ctor ( self , tcx : TyCtxt < ' tcx > ) -> Constructor < ' tcx > {
1404
- let bias = IntRange :: signed_bias ( tcx, self . ty ) ;
1405
- let ( lo, hi) = self . range . into_inner ( ) ;
1406
- if lo == hi {
1407
- let ty = ty:: ParamEnv :: empty ( ) . and ( self . ty ) ;
1408
- ConstantValue ( ty:: Const :: from_bits ( tcx, lo ^ bias, ty) , self . span )
1409
- } else {
1410
- ConstantRange ( lo ^ bias, hi ^ bias, self . ty , RangeEnd :: Included , self . span )
1411
- }
1412
- }
1413
-
1414
1400
/// Returns a collection of ranges that spans the values covered by `ranges`, subtracted
1415
1401
/// by the values covered by `self`: i.e., `ranges \ self` (in set notation).
1416
1402
fn subtract_from ( self , ranges : Vec < IntRange < ' tcx > > ) -> Vec < IntRange < ' tcx > > {
@@ -1474,7 +1460,7 @@ impl<'tcx> IntRange<'tcx> {
1474
1460
( lo == other_hi || hi == other_lo)
1475
1461
}
1476
1462
1477
- fn display ( & self , tcx : TyCtxt < ' tcx > ) -> String {
1463
+ fn to_pat ( & self , tcx : TyCtxt < ' tcx > ) -> Pat < ' tcx > {
1478
1464
let ( lo, hi) = ( self . range . start ( ) , self . range . end ( ) ) ;
1479
1465
1480
1466
let bias = IntRange :: signed_bias ( tcx, self . ty ) ;
@@ -1484,11 +1470,14 @@ impl<'tcx> IntRange<'tcx> {
1484
1470
let lo_const = ty:: Const :: from_bits ( tcx, lo, ty) ;
1485
1471
let hi_const = ty:: Const :: from_bits ( tcx, hi, ty) ;
1486
1472
1487
- if lo == hi {
1488
- format ! ( "{}" , lo_const)
1473
+ let kind = if lo == hi {
1474
+ PatKind :: Constant { value : lo_const }
1489
1475
} else {
1490
- format ! ( "{}{}{}" , lo_const, RangeEnd :: Included , hi_const)
1491
- }
1476
+ PatKind :: Range ( PatRange { lo : lo_const, hi : hi_const, end : RangeEnd :: Included } )
1477
+ } ;
1478
+
1479
+ // This is a brand new pattern, so we don't reuse `self.span`.
1480
+ Pat { ty : self . ty , span : DUMMY_SP , kind : Box :: new ( kind) }
1492
1481
}
1493
1482
}
1494
1483
@@ -2137,7 +2126,7 @@ fn lint_overlapping_patterns(
2137
2126
int_range. span ,
2138
2127
& format ! (
2139
2128
"this range overlaps on `{}`" ,
2140
- IntRange { range: int_range. range, ty, span: DUMMY_SP } . display ( tcx) ,
2129
+ IntRange { range: int_range. range, ty, span: DUMMY_SP } . to_pat ( tcx) ,
2141
2130
) ,
2142
2131
) ;
2143
2132
}
0 commit comments