@@ -718,7 +718,7 @@ use std::fmt;
718
718
719
719
use crate :: constructor:: { Constructor , ConstructorSet , IntRange } ;
720
720
use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
721
- use crate :: { Captures , MatchArm , MatchCtxt , TypeCx } ;
721
+ use crate :: { Captures , MatchArm , TypeCx } ;
722
722
723
723
use self :: ValidityConstraint :: * ;
724
724
@@ -729,12 +729,20 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
729
729
f ( )
730
730
}
731
731
732
+ /// Context that provides information for usefulness checking.
733
+ #[ derive( derivative:: Derivative ) ]
734
+ #[ derivative( Clone ( bound = "" ) , Copy ( bound = "" ) ) ]
735
+ pub struct UsefulnessCtxt < ' a , Cx : TypeCx > {
736
+ /// The context for type information.
737
+ pub tycx : & ' a Cx ,
738
+ }
739
+
732
740
/// Context that provides information local to a place under investigation.
733
741
#[ derive( derivative:: Derivative ) ]
734
742
#[ derivative( Debug ( bound = "" ) , Clone ( bound = "" ) , Copy ( bound = "" ) ) ]
735
743
struct PlaceCtxt < ' a , Cx : TypeCx > {
736
744
#[ derivative( Debug = "ignore" ) ]
737
- pub ( crate ) mcx : MatchCtxt < ' a , Cx > ,
745
+ pub ( crate ) mcx : UsefulnessCtxt < ' a , Cx > ,
738
746
/// Type of the place under investigation.
739
747
#[ derivative( Clone ( clone_with = "Clone::clone" ) ) ] // See rust-derivative#90
740
748
pub ( crate ) ty : & ' a Cx :: Ty ,
@@ -1322,7 +1330,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
1322
1330
/// We can however get false negatives because exhaustiveness does not explore all cases. See the
1323
1331
/// section on relevancy at the top of the file.
1324
1332
fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1325
- mcx : MatchCtxt < ' _ , Cx > ,
1333
+ mcx : UsefulnessCtxt < ' _ , Cx > ,
1326
1334
overlap_range : IntRange ,
1327
1335
matrix : & Matrix < ' p , Cx > ,
1328
1336
specialized_matrix : & Matrix < ' p , Cx > ,
@@ -1395,7 +1403,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1395
1403
/// This is all explained at the top of the file.
1396
1404
#[ instrument( level = "debug" , skip( mcx, is_top_level) , ret) ]
1397
1405
fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1398
- mcx : MatchCtxt < ' a , Cx > ,
1406
+ mcx : UsefulnessCtxt < ' a , Cx > ,
1399
1407
matrix : & mut Matrix < ' p , Cx > ,
1400
1408
is_top_level : bool ,
1401
1409
) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
@@ -1545,13 +1553,14 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
1545
1553
}
1546
1554
1547
1555
/// Computes whether a match is exhaustive and which of its arms are useful.
1548
- #[ instrument( skip( cx , arms) , level = "debug" ) ]
1556
+ #[ instrument( skip( tycx , arms) , level = "debug" ) ]
1549
1557
pub fn compute_match_usefulness < ' p , Cx : TypeCx > (
1550
- cx : MatchCtxt < ' _ , Cx > ,
1558
+ tycx : & Cx ,
1551
1559
arms : & [ MatchArm < ' p , Cx > ] ,
1552
1560
scrut_ty : Cx :: Ty ,
1553
1561
scrut_validity : ValidityConstraint ,
1554
1562
) -> Result < UsefulnessReport < ' p , Cx > , Cx :: Error > {
1563
+ let cx = UsefulnessCtxt { tycx } ;
1555
1564
let mut matrix = Matrix :: new ( arms, scrut_ty, scrut_validity) ;
1556
1565
let non_exhaustiveness_witnesses =
1557
1566
compute_exhaustiveness_and_usefulness ( cx, & mut matrix, true ) ?;
0 commit comments