@@ -1615,13 +1615,13 @@ pub fn is_useful<'p, 'a, 'tcx>(
1615
1615
1616
1616
debug ! ( "is_useful_expand_first_col: pcx={:#?}, expanding {:#?}" , pcx, v. head( ) ) ;
1617
1617
1618
- if let Some ( constructors ) = pat_constructors ( cx, v. head ( ) , pcx) {
1619
- debug ! ( "is_useful - expanding constructors : {:#?}" , constructors ) ;
1618
+ if let Some ( constructor ) = pat_constructor ( cx, v. head ( ) , pcx) {
1619
+ debug ! ( "is_useful - expanding constructor : {:#?}" , constructor ) ;
1620
1620
split_grouped_constructors (
1621
1621
cx. tcx ,
1622
1622
cx. param_env ,
1623
1623
pcx,
1624
- constructors ,
1624
+ vec ! [ constructor ] ,
1625
1625
matrix,
1626
1626
pcx. span ,
1627
1627
Some ( hir_id) ,
@@ -1634,7 +1634,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
1634
1634
debug ! ( "is_useful - expanding wildcard" ) ;
1635
1635
1636
1636
let used_ctors: Vec < Constructor < ' _ > > =
1637
- matrix. heads ( ) . flat_map ( |p| pat_constructors ( cx, p, pcx) . unwrap_or ( vec ! [ ] ) ) . collect ( ) ;
1637
+ matrix. heads ( ) . filter_map ( |p| pat_constructor ( cx, p, pcx) ) . collect ( ) ;
1638
1638
debug ! ( "used_ctors = {:#?}" , used_ctors) ;
1639
1639
// `all_ctors` are all the constructors for the given type, which
1640
1640
// should all be represented (or caught with the wild pattern `_`).
@@ -1777,47 +1777,39 @@ fn is_useful_specialized<'p, 'a, 'tcx>(
1777
1777
. unwrap_or ( NotUseful )
1778
1778
}
1779
1779
1780
- /// Determines the constructors that the given pattern can be specialized to.
1781
- ///
1782
- /// In most cases, there's only one constructor that a specific pattern
1783
- /// represents, such as a specific enum variant or a specific literal value.
1784
- /// Slice patterns, however, can match slices of different lengths. For instance,
1785
- /// `[a, b, tail @ ..]` can match a slice of length 2, 3, 4 and so on.
1786
- ///
1780
+ /// Determines the constructor that the given pattern can be specialized to.
1787
1781
/// Returns `None` in case of a catch-all, which can't be specialized.
1788
- fn pat_constructors < ' tcx > (
1782
+ fn pat_constructor < ' tcx > (
1789
1783
cx : & mut MatchCheckCtxt < ' _ , ' tcx > ,
1790
1784
pat : & Pat < ' tcx > ,
1791
1785
pcx : PatCtxt < ' tcx > ,
1792
- ) -> Option < Vec < Constructor < ' tcx > > > {
1786
+ ) -> Option < Constructor < ' tcx > > {
1793
1787
match * pat. kind {
1794
- PatKind :: AscribeUserType { ref subpattern, .. } => pat_constructors ( cx, subpattern, pcx) ,
1788
+ PatKind :: AscribeUserType { ref subpattern, .. } => pat_constructor ( cx, subpattern, pcx) ,
1795
1789
PatKind :: Binding { .. } | PatKind :: Wild => None ,
1796
- PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Some ( vec ! [ Single ] ) ,
1790
+ PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Some ( Single ) ,
1797
1791
PatKind :: Variant { adt_def, variant_index, .. } => {
1798
- Some ( vec ! [ Variant ( adt_def. variants[ variant_index] . def_id) ] )
1792
+ Some ( Variant ( adt_def. variants [ variant_index] . def_id ) )
1799
1793
}
1800
- PatKind :: Constant { value } => Some ( vec ! [ ConstantValue ( value, pat. span) ] ) ,
1801
- PatKind :: Range ( PatRange { lo, hi, end } ) => Some ( vec ! [ ConstantRange (
1794
+ PatKind :: Constant { value } => Some ( ConstantValue ( value, pat. span ) ) ,
1795
+ PatKind :: Range ( PatRange { lo, hi, end } ) => Some ( ConstantRange (
1802
1796
lo. eval_bits ( cx. tcx , cx. param_env , lo. ty ) ,
1803
1797
hi. eval_bits ( cx. tcx , cx. param_env , hi. ty ) ,
1804
1798
lo. ty ,
1805
1799
end,
1806
1800
pat. span ,
1807
- ) ] ) ,
1801
+ ) ) ,
1808
1802
PatKind :: Array { .. } => match pcx. ty . kind {
1809
- ty:: Array ( _, length) => {
1810
- Some ( vec ! [ FixedLenSlice ( length. eval_usize( cx. tcx, cx. param_env) ) ] )
1811
- }
1803
+ ty:: Array ( _, length) => Some ( FixedLenSlice ( length. eval_usize ( cx. tcx , cx. param_env ) ) ) ,
1812
1804
_ => span_bug ! ( pat. span, "bad ty {:?} for array pattern" , pcx. ty) ,
1813
1805
} ,
1814
1806
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
1815
1807
let prefix = prefix. len ( ) as u64 ;
1816
1808
let suffix = suffix. len ( ) as u64 ;
1817
1809
if slice. is_some ( ) {
1818
- Some ( vec ! [ VarLenSlice ( prefix, suffix) ] )
1810
+ Some ( VarLenSlice ( prefix, suffix) )
1819
1811
} else {
1820
- Some ( vec ! [ FixedLenSlice ( prefix + suffix) ] )
1812
+ Some ( FixedLenSlice ( prefix + suffix) )
1821
1813
}
1822
1814
}
1823
1815
PatKind :: Or { .. } => {
0 commit comments