@@ -659,12 +659,7 @@ impl<'tcx> Constructor<'tcx> {
659659
660660 // Returns the set of constructors covered by `self` but not by
661661 // anything in `other_ctors`.
662- fn subtract_ctors (
663- & self ,
664- tcx : TyCtxt < ' tcx > ,
665- param_env : ty:: ParamEnv < ' tcx > ,
666- other_ctors : & Vec < Constructor < ' tcx > > ,
667- ) -> Vec < Constructor < ' tcx > > {
662+ fn subtract_ctors ( & self , other_ctors : & Vec < Constructor < ' tcx > > ) -> Vec < Constructor < ' tcx > > {
668663 match self {
669664 // Those constructors can only match themselves.
670665 Single | Variant ( _) => {
@@ -747,22 +742,22 @@ impl<'tcx> Constructor<'tcx> {
747742 }
748743 IntRange ( self_range) => {
749744 let mut remaining_ranges = vec ! [ self_range. clone( ) ] ;
750- let other_ranges =
751- other_ctors. into_iter ( ) . filter_map ( |c| IntRange :: from_ctor ( tcx, param_env, c) ) ;
752- for other_range in other_ranges {
753- if other_range == * self_range {
754- // If the `self` range appears directly in a `match` arm, we can
755- // eliminate it straight away.
756- remaining_ranges = vec ! [ ] ;
757- } else {
758- // Otherwise explicitely compute the remaining ranges.
759- remaining_ranges = other_range. subtract_from ( remaining_ranges) ;
760- }
745+ for other_ctor in other_ctors {
746+ if let IntRange ( other_range) = other_ctor {
747+ if other_range == self_range {
748+ // If the `self` range appears directly in a `match` arm, we can
749+ // eliminate it straight away.
750+ remaining_ranges = vec ! [ ] ;
751+ } else {
752+ // Otherwise explicitely compute the remaining ranges.
753+ remaining_ranges = other_range. subtract_from ( remaining_ranges) ;
754+ }
761755
762- // If the ranges that have been considered so far already cover the entire
763- // range of values, we can return early.
764- if remaining_ranges. is_empty ( ) {
765- break ;
756+ // If the ranges that have been considered so far already cover the entire
757+ // range of values, we can return early.
758+ if remaining_ranges. is_empty ( ) {
759+ break ;
760+ }
766761 }
767762 }
768763
@@ -773,7 +768,7 @@ impl<'tcx> Constructor<'tcx> {
773768 if other_ctors. iter ( ) . any ( |c| {
774769 c == self
775770 // FIXME(Nadrieril): This condition looks fishy
776- || IntRange :: from_ctor ( tcx , param_env , c ) . is_some ( )
771+ || c . is_integral_range ( )
777772 } ) {
778773 vec ! [ ]
779774 } else {
@@ -1364,26 +1359,15 @@ impl<'tcx> IntRange<'tcx> {
13641359 }
13651360 }
13661361
1367- fn from_ctor (
1368- _tcx : TyCtxt < ' tcx > ,
1369- _param_env : ty:: ParamEnv < ' tcx > ,
1370- ctor : & Constructor < ' tcx > ,
1371- ) -> Option < IntRange < ' tcx > > {
1372- // Floating-point ranges are permitted and we don't want
1373- // to consider them when constructing integer ranges.
1374- match ctor {
1375- IntRange ( range) => Some ( range. clone ( ) ) ,
1376- _ => None ,
1377- }
1378- }
1379-
13801362 fn from_pat (
13811363 tcx : TyCtxt < ' tcx > ,
13821364 param_env : ty:: ParamEnv < ' tcx > ,
13831365 pat : & Pat < ' tcx > ,
13841366 ) -> Option < IntRange < ' tcx > > {
1385- let ctor = pat_constructor ( tcx, param_env, pat) ?;
1386- IntRange :: from_ctor ( tcx, param_env, & ctor)
1367+ match pat_constructor ( tcx, param_env, pat) ? {
1368+ IntRange ( range) => Some ( range) ,
1369+ _ => None ,
1370+ }
13871371 }
13881372
13891373 // The return value of `signed_bias` should be XORed with an endpoint to encode/decode it.
@@ -1490,20 +1474,13 @@ impl<'tcx> std::cmp::PartialEq for IntRange<'tcx> {
14901474
14911475// A struct to compute a set of constructors equivalent to `all_ctors \ used_ctors`.
14921476struct MissingConstructors < ' tcx > {
1493- tcx : TyCtxt < ' tcx > ,
1494- param_env : ty:: ParamEnv < ' tcx > ,
14951477 all_ctors : Vec < Constructor < ' tcx > > ,
14961478 used_ctors : Vec < Constructor < ' tcx > > ,
14971479}
14981480
14991481impl < ' tcx > MissingConstructors < ' tcx > {
1500- fn new (
1501- tcx : TyCtxt < ' tcx > ,
1502- param_env : ty:: ParamEnv < ' tcx > ,
1503- all_ctors : Vec < Constructor < ' tcx > > ,
1504- used_ctors : Vec < Constructor < ' tcx > > ,
1505- ) -> Self {
1506- MissingConstructors { tcx, param_env, all_ctors, used_ctors }
1482+ fn new ( all_ctors : Vec < Constructor < ' tcx > > , used_ctors : Vec < Constructor < ' tcx > > ) -> Self {
1483+ MissingConstructors { all_ctors, used_ctors }
15071484 }
15081485
15091486 fn into_inner ( self ) -> ( Vec < Constructor < ' tcx > > , Vec < Constructor < ' tcx > > ) {
@@ -1521,9 +1498,7 @@ impl<'tcx> MissingConstructors<'tcx> {
15211498
15221499 /// Iterate over all_ctors \ used_ctors
15231500 fn iter < ' a > ( & ' a self ) -> impl Iterator < Item = Constructor < ' tcx > > + Captures < ' a > {
1524- self . all_ctors . iter ( ) . flat_map ( move |req_ctor| {
1525- req_ctor. subtract_ctors ( self . tcx , self . param_env , & self . used_ctors )
1526- } )
1501+ self . all_ctors . iter ( ) . flat_map ( move |req_ctor| req_ctor. subtract_ctors ( & self . used_ctors ) )
15271502 }
15281503}
15291504
@@ -1649,7 +1624,7 @@ pub fn is_useful<'p, 'a, 'tcx>(
16491624 // Missing constructors are those that are not matched by any non-wildcard patterns in the
16501625 // current column. We only fully construct them on-demand, because they're rarely used and
16511626 // can be big.
1652- let missing_ctors = MissingConstructors :: new ( cx . tcx , cx . param_env , all_ctors, used_ctors) ;
1627+ let missing_ctors = MissingConstructors :: new ( all_ctors, used_ctors) ;
16531628
16541629 debug ! ( "missing_ctors.empty()={:#?}" , missing_ctors. is_empty( ) , ) ;
16551630
@@ -2305,12 +2280,9 @@ fn specialize_one_pattern<'p, 'a: 'p, 'q: 'p, 'tcx>(
23052280 // If the constructor is a:
23062281 // - Single value: add a row if the pattern contains the constructor.
23072282 // - Range: add a row if the constructor intersects the pattern.
2308- if constructor. is_integral_range ( ) {
2309- match (
2310- IntRange :: from_ctor ( cx. tcx , cx. param_env , constructor) ,
2311- IntRange :: from_pat ( cx. tcx , cx. param_env , pat) ,
2312- ) {
2313- ( Some ( ctor) , Some ( pat) ) => ctor. intersection ( cx. tcx , & pat) . map ( |_| {
2283+ if let IntRange ( ctor) = constructor {
2284+ match IntRange :: from_pat ( cx. tcx , cx. param_env , pat) {
2285+ Some ( pat) => ctor. intersection ( cx. tcx , & pat) . map ( |_| {
23142286 // Constructor splitting should ensure that all intersections we encounter
23152287 // are actually inclusions.
23162288 let ( pat_lo, pat_hi) = pat. boundaries ( ) ;
0 commit comments