@@ -4,8 +4,7 @@ use rustc_span::ErrorGuaranteed;
44use crate :: constructor:: { Constructor , SplitConstructorSet } ;
55use crate :: errors:: { NonExhaustiveOmittedPattern , NonExhaustiveOmittedPatternLintOnArm , Uncovered } ;
66use crate :: pat:: { DeconstructedPat , PatOrWild } ;
7- use crate :: rustc:: { MatchCtxt , RevealedTy , RustcMatchCheckCtxt , WitnessPat } ;
8- use crate :: usefulness:: PlaceCtxt ;
7+ use crate :: rustc:: { RevealedTy , RustcMatchCheckCtxt , WitnessPat } ;
98use crate :: { MatchArm , TypeCx } ;
109
1110/// A column of patterns in the matrix, where a column is the intuitive notion of "subpatterns that
@@ -50,9 +49,9 @@ impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
5049 }
5150
5251 /// Do constructor splitting on the constructors of the column.
53- fn analyze_ctors ( & self , pcx : & PlaceCtxt < ' _ , Cx > ) -> Result < SplitConstructorSet < Cx > , Cx :: Error > {
52+ fn analyze_ctors ( & self , cx : & Cx , ty : & Cx :: Ty ) -> Result < SplitConstructorSet < Cx > , Cx :: Error > {
5453 let column_ctors = self . patterns . iter ( ) . map ( |p| p. ctor ( ) ) ;
55- let ctors_for_ty = & pcx . ctors_for_ty ( ) ?;
54+ let ctors_for_ty = cx . ctors_for_ty ( ty ) ?;
5655 Ok ( ctors_for_ty. split ( column_ctors) )
5756 }
5857
@@ -63,10 +62,11 @@ impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
6362 /// which may change the lengths.
6463 fn specialize (
6564 & self ,
66- pcx : & PlaceCtxt < ' _ , Cx > ,
65+ cx : & Cx ,
66+ ty : & Cx :: Ty ,
6767 ctor : & Constructor < Cx > ,
6868 ) -> Vec < PatternColumn < ' p , Cx > > {
69- let arity = ctor. arity ( pcx ) ;
69+ let arity = ctor. arity ( cx , ty ) ;
7070 if arity == 0 {
7171 return Vec :: new ( ) ;
7272 }
@@ -77,7 +77,7 @@ impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
7777 let mut specialized_columns: Vec < _ > =
7878 ( 0 ..arity) . map ( |_| Self { patterns : Vec :: new ( ) } ) . collect ( ) ;
7979 let relevant_patterns =
80- self . patterns . iter ( ) . filter ( |pat| ctor. is_covered_by ( pcx , pat. ctor ( ) ) ) ;
80+ self . patterns . iter ( ) . filter ( |pat| ctor. is_covered_by ( cx , pat. ctor ( ) ) ) ;
8181 for pat in relevant_patterns {
8282 let specialized = pat. specialize ( ctor, arity) ;
8383 for ( subpat, column) in specialized. into_iter ( ) . zip ( & mut specialized_columns) {
@@ -92,15 +92,14 @@ impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
9292/// in a given column.
9393#[ instrument( level = "debug" , skip( cx) , ret) ]
9494fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
95- cx : MatchCtxt < ' a , ' p , ' tcx > ,
95+ cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
9696 column : & PatternColumn < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ,
9797) -> Result < Vec < WitnessPat < ' p , ' tcx > > , ErrorGuaranteed > {
9898 let Some ( & ty) = column. head_ty ( ) else {
9999 return Ok ( Vec :: new ( ) ) ;
100100 } ;
101- let pcx = & PlaceCtxt :: new_dummy ( cx, & ty) ;
102101
103- let set = column. analyze_ctors ( pcx ) ?;
102+ let set = column. analyze_ctors ( cx , & ty ) ?;
104103 if set. present . is_empty ( ) {
105104 // We can't consistently handle the case where no constructors are present (since this would
106105 // require digging deep through any type in case there's a non_exhaustive enum somewhere),
@@ -109,20 +108,20 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
109108 }
110109
111110 let mut witnesses = Vec :: new ( ) ;
112- if cx. tycx . is_foreign_non_exhaustive_enum ( ty) {
111+ if cx. is_foreign_non_exhaustive_enum ( ty) {
113112 witnesses. extend (
114113 set. missing
115114 . into_iter ( )
116115 // This will list missing visible variants.
117116 . filter ( |c| !matches ! ( c, Constructor :: Hidden | Constructor :: NonExhaustive ) )
118- . map ( |missing_ctor| WitnessPat :: wild_from_ctor ( pcx , missing_ctor) ) ,
117+ . map ( |missing_ctor| WitnessPat :: wild_from_ctor ( cx , missing_ctor, ty ) ) ,
119118 )
120119 }
121120
122121 // Recurse into the fields.
123122 for ctor in set. present {
124- let specialized_columns = column. specialize ( pcx , & ctor) ;
125- let wild_pat = WitnessPat :: wild_from_ctor ( pcx , ctor) ;
123+ let specialized_columns = column. specialize ( cx , & ty , & ctor) ;
124+ let wild_pat = WitnessPat :: wild_from_ctor ( cx , ctor, ty ) ;
126125 for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
127126 // Compute witnesses for each column.
128127 let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ?;
@@ -138,18 +137,17 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
138137 Ok ( witnesses)
139138}
140139
141- pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
142- cx : MatchCtxt < ' a , ' p , ' tcx > ,
140+ pub ( crate ) fn lint_nonexhaustive_missing_variants < ' p , ' tcx > (
141+ rcx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
143142 arms : & [ MatchArm < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ] ,
144143 pat_column : & PatternColumn < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ,
145144 scrut_ty : RevealedTy < ' tcx > ,
146145) -> Result < ( ) , ErrorGuaranteed > {
147- let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
148146 if !matches ! (
149147 rcx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , rcx. match_lint_level) . 0 ,
150148 rustc_session:: lint:: Level :: Allow
151149 ) {
152- let witnesses = collect_nonexhaustive_missing_variants ( cx , pat_column) ?;
150+ let witnesses = collect_nonexhaustive_missing_variants ( rcx , pat_column) ?;
153151 if !witnesses. is_empty ( ) {
154152 // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
155153 // is not exhaustive enough.
0 commit comments