@@ -19,7 +19,7 @@ use rustc_middle::mir::Field;
19
19
use rustc_middle:: ty:: layout:: IntegerExt ;
20
20
use rustc_middle:: ty:: { self , Const , Ty , TyCtxt } ;
21
21
use rustc_session:: lint;
22
- use rustc_span:: DUMMY_SP ;
22
+ use rustc_span:: { Span , DUMMY_SP } ;
23
23
use rustc_target:: abi:: { Integer , Size , VariantIdx } ;
24
24
25
25
use smallvec:: { smallvec, SmallVec } ;
@@ -184,12 +184,18 @@ impl IntRange {
184
184
}
185
185
186
186
/// 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
+ ) {
188
194
if self . is_singleton ( ) {
189
195
return ;
190
196
}
191
197
192
- if pcx . matrix . column_count ( ) . unwrap_or ( 0 ) != 1 {
198
+ if column_count != 1 {
193
199
// FIXME: for now, only check for overlapping ranges on simple range
194
200
// patterns. Otherwise with the current logic the following is detected
195
201
// as overlapping:
@@ -203,9 +209,7 @@ impl IntRange {
203
209
return ;
204
210
}
205
211
206
- let overlaps: Vec < _ > = pcx
207
- . matrix
208
- . head_ctors_and_spans ( pcx. cx )
212
+ let overlaps: Vec < _ > = ctors
209
213
. filter_map ( |( ctor, span) | Some ( ( ctor. as_int_range ( ) ?, span) ) )
210
214
. filter ( |( range, _) | self . suspicious_intersection ( range) )
211
215
. map ( |( range, span) | ( self . intersection ( & range) . unwrap ( ) , span) )
@@ -655,28 +659,33 @@ impl<'tcx> Constructor<'tcx> {
655
659
/// This function may discard some irrelevant constructors if this preserves behavior and
656
660
/// diagnostics. Eg. for the `_` case, we ignore the constructors already present in the
657
661
/// 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 ) ;
660
671
661
672
match self {
662
673
Wildcard => {
663
674
let mut split_wildcard = SplitWildcard :: new ( pcx) ;
664
- split_wildcard. split ( pcx) ;
675
+ split_wildcard. split ( pcx, ctors ) ;
665
676
split_wildcard. into_ctors ( pcx)
666
677
}
667
678
// Fast-track if the range is trivial. In particular, we don't do the overlapping
668
679
// ranges check.
669
680
IntRange ( ctor_range) if !ctor_range. is_singleton ( ) => {
670
681
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 ( ) ) ;
673
683
split_range. split ( intranges. cloned ( ) ) ;
674
684
split_range. iter ( ) . map ( IntRange ) . collect ( )
675
685
}
676
686
& Slice ( Slice { kind : VarLen ( self_prefix, self_suffix) , array_len } ) => {
677
687
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 ) ;
680
689
split_self. split ( slices) ;
681
690
split_self. iter ( ) . map ( Slice ) . collect ( )
682
691
}
@@ -912,11 +921,17 @@ impl<'tcx> SplitWildcard<'tcx> {
912
921
913
922
/// Pass a set of constructors relative to which to split this one. Don't call twice, it won't
914
923
/// 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
+ {
918
931
// 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 ( ) ;
920
935
}
921
936
922
937
/// Whether there are any value constructors for this type that are not present in the matrix.
0 commit comments