242242//! Therefore `usefulness(tp_1, tp_2, tq)` returns the single witness-tuple `[Variant2(Some(true), 0)]`.
243243//!
244244//!
245- //! Computing the set of constructors for a type is done in [`MatchCx ::ctors_for_ty`]. See
245+ //! Computing the set of constructors for a type is done in [`TypeCx ::ctors_for_ty`]. See
246246//! the following sections for more accurate versions of the algorithm and corresponding links.
247247//!
248248//!
@@ -557,7 +557,7 @@ use std::fmt;
557557
558558use crate :: constructor:: { Constructor , ConstructorSet } ;
559559use crate :: pat:: { DeconstructedPat , WitnessPat } ;
560- use crate :: { Captures , MatchArm , MatchCtxt , MatchCx , TypedArena } ;
560+ use crate :: { Captures , MatchArm , MatchCtxt , TypeCx , TypedArena } ;
561561
562562use self :: ValidityConstraint :: * ;
563563
@@ -570,15 +570,15 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
570570
571571/// Context that provides information local to a place under investigation.
572572#[ derive( Clone ) ]
573- pub ( crate ) struct PlaceCtxt < ' a , ' p , Cx : MatchCx > {
573+ pub ( crate ) struct PlaceCtxt < ' a , ' p , Cx : TypeCx > {
574574 pub ( crate ) mcx : MatchCtxt < ' a , ' p , Cx > ,
575575 /// Type of the place under investigation.
576576 pub ( crate ) ty : Cx :: Ty ,
577577 /// Whether the place is the original scrutinee place, as opposed to a subplace of it.
578578 pub ( crate ) is_scrutinee : bool ,
579579}
580580
581- impl < ' a , ' p , Cx : MatchCx > PlaceCtxt < ' a , ' p , Cx > {
581+ impl < ' a , ' p , Cx : TypeCx > PlaceCtxt < ' a , ' p , Cx > {
582582 /// A `PlaceCtxt` when code other than `is_useful` needs one.
583583 #[ cfg_attr( not( feature = "rustc" ) , allow( dead_code) ) ]
584584 pub ( crate ) fn new_dummy ( mcx : MatchCtxt < ' a , ' p , Cx > , ty : Cx :: Ty ) -> Self {
@@ -596,9 +596,9 @@ impl<'a, 'p, Cx: MatchCx> PlaceCtxt<'a, 'p, Cx> {
596596 }
597597}
598598
599- impl < ' a , ' p , Cx : MatchCx > Copy for PlaceCtxt < ' a , ' p , Cx > { }
599+ impl < ' a , ' p , Cx : TypeCx > Copy for PlaceCtxt < ' a , ' p , Cx > { }
600600
601- impl < ' a , ' p , Cx : MatchCx > fmt:: Debug for PlaceCtxt < ' a , ' p , Cx > {
601+ impl < ' a , ' p , Cx : TypeCx > fmt:: Debug for PlaceCtxt < ' a , ' p , Cx > {
602602 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
603603 f. debug_struct ( "PlaceCtxt" ) . field ( "ty" , & self . ty ) . finish ( )
604604 }
@@ -644,7 +644,7 @@ impl ValidityConstraint {
644644 ///
645645 /// Pending further opsem decisions, the current behavior is: validity is preserved, except
646646 /// inside `&` and union fields where validity is reset to `MaybeInvalid`.
647- fn specialize < Cx : MatchCx > ( self , ctor : & Constructor < Cx > ) -> Self {
647+ fn specialize < Cx : TypeCx > ( self , ctor : & Constructor < Cx > ) -> Self {
648648 // We preserve validity except when we go inside a reference or a union field.
649649 if matches ! ( ctor, Constructor :: Ref | Constructor :: UnionField ) {
650650 // Validity of `x: &T` does not imply validity of `*x: T`.
@@ -671,12 +671,12 @@ impl fmt::Display for ValidityConstraint {
671671// - 'p coming from the input
672672// - Cx global compilation context
673673#[ derive( Clone ) ]
674- struct PatStack < ' a , ' p , Cx : MatchCx > {
674+ struct PatStack < ' a , ' p , Cx : TypeCx > {
675675 // Rows of len 1 are very common, which is why `SmallVec[_; 2]` works well.
676676 pats : SmallVec < [ & ' a DeconstructedPat < ' p , Cx > ; 2 ] > ,
677677}
678678
679- impl < ' a , ' p , Cx : MatchCx > PatStack < ' a , ' p , Cx > {
679+ impl < ' a , ' p , Cx : TypeCx > PatStack < ' a , ' p , Cx > {
680680 fn from_pattern ( pat : & ' a DeconstructedPat < ' p , Cx > ) -> Self {
681681 PatStack { pats : smallvec ! [ pat] }
682682 }
@@ -722,7 +722,7 @@ impl<'a, 'p, Cx: MatchCx> PatStack<'a, 'p, Cx> {
722722 }
723723}
724724
725- impl < ' a , ' p , Cx : MatchCx > fmt:: Debug for PatStack < ' a , ' p , Cx > {
725+ impl < ' a , ' p , Cx : TypeCx > fmt:: Debug for PatStack < ' a , ' p , Cx > {
726726 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
727727 // We pretty-print similarly to the `Debug` impl of `Matrix`.
728728 write ! ( f, "+" ) ?;
@@ -735,7 +735,7 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatStack<'a, 'p, Cx> {
735735
736736/// A row of the matrix.
737737#[ derive( Clone ) ]
738- struct MatrixRow < ' a , ' p , Cx : MatchCx > {
738+ struct MatrixRow < ' a , ' p , Cx : TypeCx > {
739739 // The patterns in the row.
740740 pats : PatStack < ' a , ' p , Cx > ,
741741 /// Whether the original arm had a guard. This is inherited when specializing.
@@ -750,7 +750,7 @@ struct MatrixRow<'a, 'p, Cx: MatchCx> {
750750 useful : bool ,
751751}
752752
753- impl < ' a , ' p , Cx : MatchCx > MatrixRow < ' a , ' p , Cx > {
753+ impl < ' a , ' p , Cx : TypeCx > MatrixRow < ' a , ' p , Cx > {
754754 fn is_empty ( & self ) -> bool {
755755 self . pats . is_empty ( )
756756 }
@@ -795,7 +795,7 @@ impl<'a, 'p, Cx: MatchCx> MatrixRow<'a, 'p, Cx> {
795795 }
796796}
797797
798- impl < ' a , ' p , Cx : MatchCx > fmt:: Debug for MatrixRow < ' a , ' p , Cx > {
798+ impl < ' a , ' p , Cx : TypeCx > fmt:: Debug for MatrixRow < ' a , ' p , Cx > {
799799 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
800800 self . pats . fmt ( f)
801801 }
@@ -812,7 +812,7 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for MatrixRow<'a, 'p, Cx> {
812812/// specializing `(,)` and `Some` on a pattern of type `(Option<u32>, bool)`, the first column of
813813/// the matrix will correspond to `scrutinee.0.Some.0` and the second column to `scrutinee.1`.
814814#[ derive( Clone ) ]
815- struct Matrix < ' a , ' p , Cx : MatchCx > {
815+ struct Matrix < ' a , ' p , Cx : TypeCx > {
816816 /// Vector of rows. The rows must form a rectangular 2D array. Moreover, all the patterns of
817817 /// each column must have the same type. Each column corresponds to a place within the
818818 /// scrutinee.
@@ -824,7 +824,7 @@ struct Matrix<'a, 'p, Cx: MatchCx> {
824824 place_validity : SmallVec < [ ValidityConstraint ; 2 ] > ,
825825}
826826
827- impl < ' a , ' p , Cx : MatchCx > Matrix < ' a , ' p , Cx > {
827+ impl < ' a , ' p , Cx : TypeCx > Matrix < ' a , ' p , Cx > {
828828 /// Pushes a new row to the matrix. If the row starts with an or-pattern, this recursively
829829 /// expands it. Internal method, prefer [`Matrix::new`].
830830 fn expand_and_push ( & mut self , row : MatrixRow < ' a , ' p , Cx > ) {
@@ -942,7 +942,7 @@ impl<'a, 'p, Cx: MatchCx> Matrix<'a, 'p, Cx> {
942942/// + _ + [_, _, tail @ ..] +
943943/// | ✓ | ? | // column validity
944944/// ```
945- impl < ' a , ' p , Cx : MatchCx > fmt:: Debug for Matrix < ' a , ' p , Cx > {
945+ impl < ' a , ' p , Cx : TypeCx > fmt:: Debug for Matrix < ' a , ' p , Cx > {
946946 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
947947 write ! ( f, "\n " ) ?;
948948
@@ -1033,9 +1033,9 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for Matrix<'a, 'p, Cx> {
10331033///
10341034/// See the top of the file for more detailed explanations and examples.
10351035#[ derive( Debug , Clone ) ]
1036- struct WitnessStack < Cx : MatchCx > ( Vec < WitnessPat < Cx > > ) ;
1036+ struct WitnessStack < Cx : TypeCx > ( Vec < WitnessPat < Cx > > ) ;
10371037
1038- impl < Cx : MatchCx > WitnessStack < Cx > {
1038+ impl < Cx : TypeCx > WitnessStack < Cx > {
10391039 /// Asserts that the witness contains a single pattern, and returns it.
10401040 fn single_pattern ( self ) -> WitnessPat < Cx > {
10411041 assert_eq ! ( self . 0 . len( ) , 1 ) ;
@@ -1080,9 +1080,9 @@ impl<Cx: MatchCx> WitnessStack<Cx> {
10801080/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
10811081/// column, which contains the patterns that are missing for the match to be exhaustive.
10821082#[ derive( Debug , Clone ) ]
1083- struct WitnessMatrix < Cx : MatchCx > ( Vec < WitnessStack < Cx > > ) ;
1083+ struct WitnessMatrix < Cx : TypeCx > ( Vec < WitnessStack < Cx > > ) ;
10841084
1085- impl < Cx : MatchCx > WitnessMatrix < Cx > {
1085+ impl < Cx : TypeCx > WitnessMatrix < Cx > {
10861086 /// New matrix with no witnesses.
10871087 fn empty ( ) -> Self {
10881088 WitnessMatrix ( vec ! [ ] )
@@ -1174,7 +1174,7 @@ impl<Cx: MatchCx> WitnessMatrix<Cx> {
11741174/// (using `apply_constructor` and by updating `row.useful` for each parent row).
11751175/// This is all explained at the top of the file.
11761176#[ instrument( level = "debug" , skip( mcx, is_top_level) , ret) ]
1177- fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : MatchCx > (
1177+ fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
11781178 mcx : MatchCtxt < ' a , ' p , Cx > ,
11791179 matrix : & mut Matrix < ' a , ' p , Cx > ,
11801180 is_top_level : bool ,
@@ -1283,7 +1283,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: MatchCx>(
12831283
12841284/// Indicates whether or not a given arm is useful.
12851285#[ derive( Clone , Debug ) ]
1286- pub enum Usefulness < ' p , Cx : MatchCx > {
1286+ pub enum Usefulness < ' p , Cx : TypeCx > {
12871287 /// The arm is useful. This additionally carries a set of or-pattern branches that have been
12881288 /// found to be redundant despite the overall arm being useful. Used only in the presence of
12891289 /// or-patterns, otherwise it stays empty.
@@ -1294,7 +1294,7 @@ pub enum Usefulness<'p, Cx: MatchCx> {
12941294}
12951295
12961296/// The output of checking a match for exhaustiveness and arm usefulness.
1297- pub struct UsefulnessReport < ' p , Cx : MatchCx > {
1297+ pub struct UsefulnessReport < ' p , Cx : TypeCx > {
12981298 /// For each arm of the input, whether that arm is useful after the arms above it.
12991299 pub arm_usefulness : Vec < ( MatchArm < ' p , Cx > , Usefulness < ' p , Cx > ) > ,
13001300 /// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of
@@ -1304,7 +1304,7 @@ pub struct UsefulnessReport<'p, Cx: MatchCx> {
13041304
13051305/// Computes whether a match is exhaustive and which of its arms are useful.
13061306#[ instrument( skip( cx, arms) , level = "debug" ) ]
1307- pub fn compute_match_usefulness < ' p , Cx : MatchCx > (
1307+ pub fn compute_match_usefulness < ' p , Cx : TypeCx > (
13081308 cx : MatchCtxt < ' _ , ' p , Cx > ,
13091309 arms : & [ MatchArm < ' p , Cx > ] ,
13101310 scrut_ty : Cx :: Ty ,
0 commit comments