@@ -719,7 +719,7 @@ use std::fmt;
719719
720720use crate :: constructor:: { Constructor , ConstructorSet , IntRange } ;
721721use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
722- use crate :: { Captures , MatchArm , MatchCtxt , TypeCx } ;
722+ use crate :: { Captures , MatchArm , TypeCx } ;
723723
724724use self :: ValidityConstraint :: * ;
725725
@@ -730,9 +730,22 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
730730 f ( )
731731}
732732
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+
733746/// Context that provides information local to a place under investigation.
734747struct PlaceCtxt < ' a , Cx : TypeCx > {
735- mcx : MatchCtxt < ' a , Cx > ,
748+ mcx : UsefulnessCtxt < ' a , Cx > ,
736749 /// Type of the place under investigation.
737750 ty : & ' a Cx :: Ty ,
738751}
@@ -1358,7 +1371,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13581371/// We can however get false negatives because exhaustiveness does not explore all cases. See the
13591372/// section on relevancy at the top of the file.
13601373fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1361- mcx : MatchCtxt < ' _ , Cx > ,
1374+ mcx : UsefulnessCtxt < ' _ , Cx > ,
13621375 overlap_range : IntRange ,
13631376 matrix : & Matrix < ' p , Cx > ,
13641377 specialized_matrix : & Matrix < ' p , Cx > ,
@@ -1431,7 +1444,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
14311444/// This is all explained at the top of the file.
14321445#[ instrument( level = "debug" , skip( mcx, is_top_level) , ret) ]
14331446fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1434- mcx : MatchCtxt < ' a , Cx > ,
1447+ mcx : UsefulnessCtxt < ' a , Cx > ,
14351448 matrix : & mut Matrix < ' p , Cx > ,
14361449 is_top_level : bool ,
14371450) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
@@ -1588,13 +1601,14 @@ pub struct UsefulnessReport<'p, Cx: TypeCx> {
15881601}
15891602
15901603/// 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" ) ]
15921605pub fn compute_match_usefulness < ' p , Cx : TypeCx > (
1593- cx : MatchCtxt < ' _ , Cx > ,
1606+ tycx : & Cx ,
15941607 arms : & [ MatchArm < ' p , Cx > ] ,
15951608 scrut_ty : Cx :: Ty ,
15961609 scrut_validity : ValidityConstraint ,
15971610) -> Result < UsefulnessReport < ' p , Cx > , Cx :: Error > {
1611+ let cx = UsefulnessCtxt { tycx } ;
15981612 let mut matrix = Matrix :: new ( arms, scrut_ty, scrut_validity) ;
15991613 let non_exhaustiveness_witnesses =
16001614 compute_exhaustiveness_and_usefulness ( cx, & mut matrix, true ) ?;
0 commit comments