242
242
//! Therefore `usefulness(tp_1, tp_2, tq)` returns the single witness-tuple `[Variant2(Some(true), 0)]`.
243
243
//!
244
244
//!
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
246
246
//! the following sections for more accurate versions of the algorithm and corresponding links.
247
247
//!
248
248
//!
@@ -557,7 +557,7 @@ use std::fmt;
557
557
558
558
use crate :: constructor:: { Constructor , ConstructorSet } ;
559
559
use crate :: pat:: { DeconstructedPat , WitnessPat } ;
560
- use crate :: { Captures , MatchArm , MatchCtxt , MatchCx , TypedArena } ;
560
+ use crate :: { Captures , MatchArm , MatchCtxt , TypeCx , TypedArena } ;
561
561
562
562
use self :: ValidityConstraint :: * ;
563
563
@@ -570,15 +570,15 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
570
570
571
571
/// Context that provides information local to a place under investigation.
572
572
#[ derive( Clone ) ]
573
- pub ( crate ) struct PlaceCtxt < ' a , ' p , Cx : MatchCx > {
573
+ pub ( crate ) struct PlaceCtxt < ' a , ' p , Cx : TypeCx > {
574
574
pub ( crate ) mcx : MatchCtxt < ' a , ' p , Cx > ,
575
575
/// Type of the place under investigation.
576
576
pub ( crate ) ty : Cx :: Ty ,
577
577
/// Whether the place is the original scrutinee place, as opposed to a subplace of it.
578
578
pub ( crate ) is_scrutinee : bool ,
579
579
}
580
580
581
- impl < ' a , ' p , Cx : MatchCx > PlaceCtxt < ' a , ' p , Cx > {
581
+ impl < ' a , ' p , Cx : TypeCx > PlaceCtxt < ' a , ' p , Cx > {
582
582
/// A `PlaceCtxt` when code other than `is_useful` needs one.
583
583
#[ cfg_attr( not( feature = "rustc" ) , allow( dead_code) ) ]
584
584
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> {
596
596
}
597
597
}
598
598
599
- impl < ' a , ' p , Cx : MatchCx > Copy for PlaceCtxt < ' a , ' p , Cx > { }
599
+ impl < ' a , ' p , Cx : TypeCx > Copy for PlaceCtxt < ' a , ' p , Cx > { }
600
600
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 > {
602
602
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
603
603
f. debug_struct ( "PlaceCtxt" ) . field ( "ty" , & self . ty ) . finish ( )
604
604
}
@@ -644,7 +644,7 @@ impl ValidityConstraint {
644
644
///
645
645
/// Pending further opsem decisions, the current behavior is: validity is preserved, except
646
646
/// 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 {
648
648
// We preserve validity except when we go inside a reference or a union field.
649
649
if matches ! ( ctor, Constructor :: Ref | Constructor :: UnionField ) {
650
650
// Validity of `x: &T` does not imply validity of `*x: T`.
@@ -671,12 +671,12 @@ impl fmt::Display for ValidityConstraint {
671
671
// - 'p coming from the input
672
672
// - Cx global compilation context
673
673
#[ derive( Clone ) ]
674
- struct PatStack < ' a , ' p , Cx : MatchCx > {
674
+ struct PatStack < ' a , ' p , Cx : TypeCx > {
675
675
// Rows of len 1 are very common, which is why `SmallVec[_; 2]` works well.
676
676
pats : SmallVec < [ & ' a DeconstructedPat < ' p , Cx > ; 2 ] > ,
677
677
}
678
678
679
- impl < ' a , ' p , Cx : MatchCx > PatStack < ' a , ' p , Cx > {
679
+ impl < ' a , ' p , Cx : TypeCx > PatStack < ' a , ' p , Cx > {
680
680
fn from_pattern ( pat : & ' a DeconstructedPat < ' p , Cx > ) -> Self {
681
681
PatStack { pats : smallvec ! [ pat] }
682
682
}
@@ -722,7 +722,7 @@ impl<'a, 'p, Cx: MatchCx> PatStack<'a, 'p, Cx> {
722
722
}
723
723
}
724
724
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 > {
726
726
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
727
727
// We pretty-print similarly to the `Debug` impl of `Matrix`.
728
728
write ! ( f, "+" ) ?;
@@ -735,7 +735,7 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatStack<'a, 'p, Cx> {
735
735
736
736
/// A row of the matrix.
737
737
#[ derive( Clone ) ]
738
- struct MatrixRow < ' a , ' p , Cx : MatchCx > {
738
+ struct MatrixRow < ' a , ' p , Cx : TypeCx > {
739
739
// The patterns in the row.
740
740
pats : PatStack < ' a , ' p , Cx > ,
741
741
/// Whether the original arm had a guard. This is inherited when specializing.
@@ -750,7 +750,7 @@ struct MatrixRow<'a, 'p, Cx: MatchCx> {
750
750
useful : bool ,
751
751
}
752
752
753
- impl < ' a , ' p , Cx : MatchCx > MatrixRow < ' a , ' p , Cx > {
753
+ impl < ' a , ' p , Cx : TypeCx > MatrixRow < ' a , ' p , Cx > {
754
754
fn is_empty ( & self ) -> bool {
755
755
self . pats . is_empty ( )
756
756
}
@@ -795,7 +795,7 @@ impl<'a, 'p, Cx: MatchCx> MatrixRow<'a, 'p, Cx> {
795
795
}
796
796
}
797
797
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 > {
799
799
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
800
800
self . pats . fmt ( f)
801
801
}
@@ -812,7 +812,7 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for MatrixRow<'a, 'p, Cx> {
812
812
/// specializing `(,)` and `Some` on a pattern of type `(Option<u32>, bool)`, the first column of
813
813
/// the matrix will correspond to `scrutinee.0.Some.0` and the second column to `scrutinee.1`.
814
814
#[ derive( Clone ) ]
815
- struct Matrix < ' a , ' p , Cx : MatchCx > {
815
+ struct Matrix < ' a , ' p , Cx : TypeCx > {
816
816
/// Vector of rows. The rows must form a rectangular 2D array. Moreover, all the patterns of
817
817
/// each column must have the same type. Each column corresponds to a place within the
818
818
/// scrutinee.
@@ -824,7 +824,7 @@ struct Matrix<'a, 'p, Cx: MatchCx> {
824
824
place_validity : SmallVec < [ ValidityConstraint ; 2 ] > ,
825
825
}
826
826
827
- impl < ' a , ' p , Cx : MatchCx > Matrix < ' a , ' p , Cx > {
827
+ impl < ' a , ' p , Cx : TypeCx > Matrix < ' a , ' p , Cx > {
828
828
/// Pushes a new row to the matrix. If the row starts with an or-pattern, this recursively
829
829
/// expands it. Internal method, prefer [`Matrix::new`].
830
830
fn expand_and_push ( & mut self , row : MatrixRow < ' a , ' p , Cx > ) {
@@ -942,7 +942,7 @@ impl<'a, 'p, Cx: MatchCx> Matrix<'a, 'p, Cx> {
942
942
/// + _ + [_, _, tail @ ..] +
943
943
/// | ✓ | ? | // column validity
944
944
/// ```
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 > {
946
946
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
947
947
write ! ( f, "\n " ) ?;
948
948
@@ -1033,9 +1033,9 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for Matrix<'a, 'p, Cx> {
1033
1033
///
1034
1034
/// See the top of the file for more detailed explanations and examples.
1035
1035
#[ derive( Debug , Clone ) ]
1036
- struct WitnessStack < Cx : MatchCx > ( Vec < WitnessPat < Cx > > ) ;
1036
+ struct WitnessStack < Cx : TypeCx > ( Vec < WitnessPat < Cx > > ) ;
1037
1037
1038
- impl < Cx : MatchCx > WitnessStack < Cx > {
1038
+ impl < Cx : TypeCx > WitnessStack < Cx > {
1039
1039
/// Asserts that the witness contains a single pattern, and returns it.
1040
1040
fn single_pattern ( self ) -> WitnessPat < Cx > {
1041
1041
assert_eq ! ( self . 0 . len( ) , 1 ) ;
@@ -1080,9 +1080,9 @@ impl<Cx: MatchCx> WitnessStack<Cx> {
1080
1080
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
1081
1081
/// column, which contains the patterns that are missing for the match to be exhaustive.
1082
1082
#[ derive( Debug , Clone ) ]
1083
- struct WitnessMatrix < Cx : MatchCx > ( Vec < WitnessStack < Cx > > ) ;
1083
+ struct WitnessMatrix < Cx : TypeCx > ( Vec < WitnessStack < Cx > > ) ;
1084
1084
1085
- impl < Cx : MatchCx > WitnessMatrix < Cx > {
1085
+ impl < Cx : TypeCx > WitnessMatrix < Cx > {
1086
1086
/// New matrix with no witnesses.
1087
1087
fn empty ( ) -> Self {
1088
1088
WitnessMatrix ( vec ! [ ] )
@@ -1174,7 +1174,7 @@ impl<Cx: MatchCx> WitnessMatrix<Cx> {
1174
1174
/// (using `apply_constructor` and by updating `row.useful` for each parent row).
1175
1175
/// This is all explained at the top of the file.
1176
1176
#[ 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 > (
1178
1178
mcx : MatchCtxt < ' a , ' p , Cx > ,
1179
1179
matrix : & mut Matrix < ' a , ' p , Cx > ,
1180
1180
is_top_level : bool ,
@@ -1283,7 +1283,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: MatchCx>(
1283
1283
1284
1284
/// Indicates whether or not a given arm is useful.
1285
1285
#[ derive( Clone , Debug ) ]
1286
- pub enum Usefulness < ' p , Cx : MatchCx > {
1286
+ pub enum Usefulness < ' p , Cx : TypeCx > {
1287
1287
/// The arm is useful. This additionally carries a set of or-pattern branches that have been
1288
1288
/// found to be redundant despite the overall arm being useful. Used only in the presence of
1289
1289
/// or-patterns, otherwise it stays empty.
@@ -1294,7 +1294,7 @@ pub enum Usefulness<'p, Cx: MatchCx> {
1294
1294
}
1295
1295
1296
1296
/// 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 > {
1298
1298
/// For each arm of the input, whether that arm is useful after the arms above it.
1299
1299
pub arm_usefulness : Vec < ( MatchArm < ' p , Cx > , Usefulness < ' p , Cx > ) > ,
1300
1300
/// 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> {
1304
1304
1305
1305
/// Computes whether a match is exhaustive and which of its arms are useful.
1306
1306
#[ instrument( skip( cx, arms) , level = "debug" ) ]
1307
- pub fn compute_match_usefulness < ' p , Cx : MatchCx > (
1307
+ pub fn compute_match_usefulness < ' p , Cx : TypeCx > (
1308
1308
cx : MatchCtxt < ' _ , ' p , Cx > ,
1309
1309
arms : & [ MatchArm < ' p , Cx > ] ,
1310
1310
scrut_ty : Cx :: Ty ,
0 commit comments