@@ -719,7 +719,7 @@ use std::fmt;
719
719
720
720
use crate :: constructor:: { Constructor , ConstructorSet , IntRange } ;
721
721
use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
722
- use crate :: { Captures , MatchArm , MatchCtxt , TypeCx } ;
722
+ use crate :: { Captures , MatchArm , TypeCx } ;
723
723
724
724
use self :: ValidityConstraint :: * ;
725
725
@@ -730,9 +730,22 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
730
730
f ( )
731
731
}
732
732
733
+ /// Context that provides information for usefulness checking.
734
+ pub struct UsefulnessCtxt < ' a , Cx : TypeCx > {
735
+ /// The context for type information.
736
+ pub tycx : & ' a Cx ,
737
+ }
738
+
739
+ impl < ' a , Cx : TypeCx > Copy for UsefulnessCtxt < ' a , Cx > { }
740
+ impl < ' a , Cx : TypeCx > Clone for UsefulnessCtxt < ' a , Cx > {
741
+ fn clone ( & self ) -> Self {
742
+ Self { tycx : self . tycx }
743
+ }
744
+ }
745
+
733
746
/// Context that provides information local to a place under investigation.
734
747
struct PlaceCtxt < ' a , Cx : TypeCx > {
735
- mcx : MatchCtxt < ' a , Cx > ,
748
+ mcx : UsefulnessCtxt < ' a , Cx > ,
736
749
/// Type of the place under investigation.
737
750
ty : & ' a Cx :: Ty ,
738
751
}
@@ -1358,7 +1371,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
1358
1371
/// We can however get false negatives because exhaustiveness does not explore all cases. See the
1359
1372
/// section on relevancy at the top of the file.
1360
1373
fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1361
- mcx : MatchCtxt < ' _ , Cx > ,
1374
+ mcx : UsefulnessCtxt < ' _ , Cx > ,
1362
1375
overlap_range : IntRange ,
1363
1376
matrix : & Matrix < ' p , Cx > ,
1364
1377
specialized_matrix : & Matrix < ' p , Cx > ,
@@ -1431,7 +1444,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1431
1444
/// This is all explained at the top of the file.
1432
1445
#[ instrument( level = "debug" , skip( mcx, is_top_level) , ret) ]
1433
1446
fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1434
- mcx : MatchCtxt < ' a , Cx > ,
1447
+ mcx : UsefulnessCtxt < ' a , Cx > ,
1435
1448
matrix : & mut Matrix < ' p , Cx > ,
1436
1449
is_top_level : bool ,
1437
1450
) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
@@ -1588,13 +1601,14 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
1588
1601
}
1589
1602
1590
1603
/// Computes whether a match is exhaustive and which of its arms are useful.
1591
- #[ instrument( skip( cx , arms) , level = "debug" ) ]
1604
+ #[ instrument( skip( tycx , arms) , level = "debug" ) ]
1592
1605
pub fn compute_match_usefulness < ' p , Cx : TypeCx > (
1593
- cx : MatchCtxt < ' _ , Cx > ,
1606
+ tycx : & Cx ,
1594
1607
arms : & [ MatchArm < ' p , Cx > ] ,
1595
1608
scrut_ty : Cx :: Ty ,
1596
1609
scrut_validity : ValidityConstraint ,
1597
1610
) -> Result < UsefulnessReport < ' p , Cx > , Cx :: Error > {
1611
+ let cx = UsefulnessCtxt { tycx } ;
1598
1612
let mut matrix = Matrix :: new ( arms, scrut_ty, scrut_validity) ;
1599
1613
let non_exhaustiveness_witnesses =
1600
1614
compute_exhaustiveness_and_usefulness ( cx, & mut matrix, true ) ?;
0 commit comments