@@ -19,7 +19,7 @@ use rustc_middle::mir::Field;
1919use rustc_middle:: ty:: layout:: IntegerExt ;
2020use rustc_middle:: ty:: { self , Const , Ty , TyCtxt } ;
2121use rustc_session:: lint;
22- use rustc_span:: DUMMY_SP ;
22+ use rustc_span:: { Span , DUMMY_SP } ;
2323use rustc_target:: abi:: { Integer , Size , VariantIdx } ;
2424
2525use smallvec:: { smallvec, SmallVec } ;
@@ -184,12 +184,18 @@ impl IntRange {
184184 }
185185
186186 /// Lint on likely incorrect range patterns (#63987)
187- pub ( super ) fn lint_overlapping_range_endpoints ( & self , pcx : PatCtxt < ' _ , ' _ , ' _ > , hir_id : HirId ) {
187+ pub ( super ) fn lint_overlapping_range_endpoints < ' a , ' tcx : ' a > (
188+ & self ,
189+ pcx : PatCtxt < ' _ , ' _ , ' tcx > ,
190+ ctors : impl Iterator < Item = ( & ' a Constructor < ' tcx > , Span ) > ,
191+ column_count : usize ,
192+ hir_id : HirId ,
193+ ) {
188194 if self . is_singleton ( ) {
189195 return ;
190196 }
191197
192- if pcx . matrix . column_count ( ) . unwrap_or ( 0 ) != 1 {
198+ if column_count != 1 {
193199 // FIXME: for now, only check for overlapping ranges on simple range
194200 // patterns. Otherwise with the current logic the following is detected
195201 // as overlapping:
@@ -203,9 +209,7 @@ impl IntRange {
203209 return ;
204210 }
205211
206- let overlaps: Vec < _ > = pcx
207- . matrix
208- . head_ctors_and_spans ( pcx. cx )
212+ let overlaps: Vec < _ > = ctors
209213 . filter_map ( |( ctor, span) | Some ( ( ctor. as_int_range ( ) ?, span) ) )
210214 . filter ( |( range, _) | self . suspicious_intersection ( range) )
211215 . map ( |( range, span) | ( self . intersection ( & range) . unwrap ( ) , span) )
@@ -655,28 +659,33 @@ impl<'tcx> Constructor<'tcx> {
655659 /// This function may discard some irrelevant constructors if this preserves behavior and
656660 /// diagnostics. Eg. for the `_` case, we ignore the constructors already present in the
657661 /// matrix, unless all of them are.
658- pub ( super ) fn split < ' p > ( & self , pcx : PatCtxt < ' _ , ' p , ' tcx > ) -> SmallVec < [ Self ; 1 ] > {
659- debug ! ( "Constructor::split({:#?}, {:#?})" , self , pcx. matrix) ;
662+ pub ( super ) fn split < ' a > (
663+ & self ,
664+ pcx : PatCtxt < ' _ , ' _ , ' tcx > ,
665+ ctors : impl Iterator < Item = & ' a Constructor < ' tcx > > + Clone ,
666+ ) -> SmallVec < [ Self ; 1 ] >
667+ where
668+ ' tcx : ' a ,
669+ {
670+ debug ! ( "Constructor::split({:#?})" , self ) ;
660671
661672 match self {
662673 Wildcard => {
663674 let mut split_wildcard = SplitWildcard :: new ( pcx) ;
664- split_wildcard. split ( pcx) ;
675+ split_wildcard. split ( pcx, ctors ) ;
665676 split_wildcard. into_ctors ( pcx)
666677 }
667678 // Fast-track if the range is trivial. In particular, we don't do the overlapping
668679 // ranges check.
669680 IntRange ( ctor_range) if !ctor_range. is_singleton ( ) => {
670681 let mut split_range = SplitIntRange :: new ( ctor_range. clone ( ) ) ;
671- let intranges =
672- pcx. matrix . head_ctors ( pcx. cx ) . filter_map ( |ctor| ctor. as_int_range ( ) ) ;
682+ let intranges = ctors. filter_map ( |ctor| ctor. as_int_range ( ) ) ;
673683 split_range. split ( intranges. cloned ( ) ) ;
674684 split_range. iter ( ) . map ( IntRange ) . collect ( )
675685 }
676686 & Slice ( Slice { kind : VarLen ( self_prefix, self_suffix) , array_len } ) => {
677687 let mut split_self = SplitVarLenSlice :: new ( self_prefix, self_suffix, array_len) ;
678- let slices =
679- pcx. matrix . head_ctors ( pcx. cx ) . filter_map ( |c| c. as_slice ( ) ) . map ( |s| s. kind ) ;
688+ let slices = ctors. filter_map ( |c| c. as_slice ( ) ) . map ( |s| s. kind ) ;
680689 split_self. split ( slices) ;
681690 split_self. iter ( ) . map ( Slice ) . collect ( )
682691 }
@@ -912,11 +921,17 @@ impl<'tcx> SplitWildcard<'tcx> {
912921
913922 /// Pass a set of constructors relative to which to split this one. Don't call twice, it won't
914923 /// do what you want.
915- pub ( super ) fn split ( & mut self , pcx : PatCtxt < ' _ , ' _ , ' tcx > ) {
916- self . matrix_ctors =
917- pcx. matrix . head_ctors ( pcx. cx ) . cloned ( ) . filter ( |c| !c. is_wildcard ( ) ) . collect ( ) ;
924+ pub ( super ) fn split < ' a > (
925+ & mut self ,
926+ pcx : PatCtxt < ' _ , ' _ , ' tcx > ,
927+ ctors : impl Iterator < Item = & ' a Constructor < ' tcx > > + Clone ,
928+ ) where
929+ ' tcx : ' a ,
930+ {
918931 // Since `all_ctors` never contains wildcards, this won't recurse further.
919- self . all_ctors = self . all_ctors . iter ( ) . flat_map ( |ctor| ctor. split ( pcx) ) . collect ( ) ;
932+ self . all_ctors =
933+ self . all_ctors . iter ( ) . flat_map ( |ctor| ctor. split ( pcx, ctors. clone ( ) ) ) . collect ( ) ;
934+ self . matrix_ctors = ctors. filter ( |c| !c. is_wildcard ( ) ) . cloned ( ) . collect ( ) ;
920935 }
921936
922937 /// Whether there are any value constructors for this type that are not present in the matrix.
0 commit comments