@@ -1374,29 +1374,10 @@ impl<'tcx> IntRange<'tcx> {
1374
1374
fn from_pat (
1375
1375
tcx : TyCtxt < ' tcx > ,
1376
1376
param_env : ty:: ParamEnv < ' tcx > ,
1377
- mut pat : & Pat < ' tcx > ,
1377
+ pat : & Pat < ' tcx > ,
1378
1378
) -> Option < IntRange < ' tcx > > {
1379
- loop {
1380
- match pat. kind {
1381
- box PatKind :: Constant { value } => {
1382
- return Self :: from_const ( tcx, param_env, value, pat. span ) ;
1383
- }
1384
- box PatKind :: Range ( PatRange { lo, hi, end } ) => {
1385
- return Self :: from_range (
1386
- tcx,
1387
- lo. eval_bits ( tcx, param_env, lo. ty ) ,
1388
- hi. eval_bits ( tcx, param_env, hi. ty ) ,
1389
- & lo. ty ,
1390
- & end,
1391
- pat. span ,
1392
- ) ;
1393
- }
1394
- box PatKind :: AscribeUserType { ref subpattern, .. } => {
1395
- pat = subpattern;
1396
- }
1397
- _ => return None ,
1398
- }
1399
- }
1379
+ let ctor = pat_constructor ( tcx, param_env, pat) ?;
1380
+ IntRange :: from_ctor ( tcx, param_env, & ctor)
1400
1381
}
1401
1382
1402
1383
// The return value of `signed_bias` should be XORed with an endpoint to encode/decode it.
@@ -1632,7 +1613,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1632
1613
1633
1614
debug ! ( "is_useful_expand_first_col: pcx={:#?}, expanding {:#?}" , pcx, v. head( ) ) ;
1634
1615
1635
- if let Some ( constructor) = pat_constructor ( cx, v. head ( ) ) {
1616
+ if let Some ( constructor) = pat_constructor ( cx. tcx , cx . param_env , v. head ( ) ) {
1636
1617
debug ! ( "is_useful - expanding constructor: {:#?}" , constructor) ;
1637
1618
split_grouped_constructors (
1638
1619
cx. tcx ,
@@ -1651,7 +1632,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1651
1632
debug ! ( "is_useful - expanding wildcard" ) ;
1652
1633
1653
1634
let used_ctors: Vec < Constructor < ' _ > > =
1654
- matrix. heads ( ) . filter_map ( |p| pat_constructor ( cx, p) ) . collect ( ) ;
1635
+ matrix. heads ( ) . filter_map ( |p| pat_constructor ( cx. tcx , cx . param_env , p) ) . collect ( ) ;
1655
1636
debug ! ( "used_ctors = {:#?}" , used_ctors) ;
1656
1637
// `all_ctors` are all the constructors for the given type, which
1657
1638
// should all be represented (or caught with the wild pattern `_`).
@@ -1754,26 +1735,29 @@ fn is_useful_specialized<'p, 'a, 'tcx>(
1754
1735
/// Determines the constructor that the given pattern can be specialized to.
1755
1736
/// Returns `None` in case of a catch-all, which can't be specialized.
1756
1737
fn pat_constructor < ' tcx > (
1757
- cx : & mut MatchCheckCtxt < ' _ , ' tcx > ,
1738
+ tcx : TyCtxt < ' tcx > ,
1739
+ param_env : ty:: ParamEnv < ' tcx > ,
1758
1740
pat : & Pat < ' tcx > ,
1759
1741
) -> Option < Constructor < ' tcx > > {
1760
1742
match * pat. kind {
1761
- PatKind :: AscribeUserType { ref subpattern, .. } => pat_constructor ( cx, subpattern) ,
1743
+ PatKind :: AscribeUserType { ref subpattern, .. } => {
1744
+ pat_constructor ( tcx, param_env, subpattern)
1745
+ }
1762
1746
PatKind :: Binding { .. } | PatKind :: Wild => None ,
1763
1747
PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Some ( Single ) ,
1764
1748
PatKind :: Variant { adt_def, variant_index, .. } => {
1765
1749
Some ( Variant ( adt_def. variants [ variant_index] . def_id ) )
1766
1750
}
1767
1751
PatKind :: Constant { value } => Some ( ConstantValue ( value, pat. span ) ) ,
1768
1752
PatKind :: Range ( PatRange { lo, hi, end } ) => Some ( ConstantRange (
1769
- lo. eval_bits ( cx . tcx , cx . param_env , lo. ty ) ,
1770
- hi. eval_bits ( cx . tcx , cx . param_env , hi. ty ) ,
1753
+ lo. eval_bits ( tcx, param_env, lo. ty ) ,
1754
+ hi. eval_bits ( tcx, param_env, hi. ty ) ,
1771
1755
lo. ty ,
1772
1756
end,
1773
1757
pat. span ,
1774
1758
) ) ,
1775
1759
PatKind :: Array { .. } => match pat. ty . kind {
1776
- ty:: Array ( _, length) => Some ( FixedLenSlice ( length. eval_usize ( cx . tcx , cx . param_env ) ) ) ,
1760
+ ty:: Array ( _, length) => Some ( FixedLenSlice ( length. eval_usize ( tcx, param_env) ) ) ,
1777
1761
_ => span_bug ! ( pat. span, "bad ty {:?} for array pattern" , pat. ty) ,
1778
1762
} ,
1779
1763
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
0 commit comments