@@ -53,22 +53,20 @@ use smallvec::{smallvec, SmallVec};
5353use rustc_apfloat:: ieee:: { DoubleS , IeeeFloat , SingleS } ;
5454use rustc_data_structures:: captures:: Captures ;
5555use rustc_data_structures:: fx:: FxHashSet ;
56- use rustc_hir:: { HirId , RangeEnd } ;
56+ use rustc_hir:: RangeEnd ;
5757use rustc_index:: Idx ;
5858use rustc_middle:: middle:: stability:: EvalResult ;
5959use rustc_middle:: mir;
6060use rustc_middle:: thir:: { FieldPat , Pat , PatKind , PatRange } ;
6161use rustc_middle:: ty:: layout:: IntegerExt ;
6262use rustc_middle:: ty:: { self , Ty , TyCtxt , VariantDef } ;
63- use rustc_session:: lint;
6463use rustc_span:: { Span , DUMMY_SP } ;
6564use rustc_target:: abi:: { FieldIdx , Integer , VariantIdx , FIRST_VARIANT } ;
6665
6766use self :: Constructor :: * ;
6867use self :: SliceKind :: * ;
6968
7069use super :: usefulness:: { MatchCheckCtxt , PatCtxt } ;
71- use crate :: errors:: { Overlap , OverlappingRangeEndpoints } ;
7270
7371/// Recursively expand this pattern into its subpatterns. Only useful for or-patterns.
7472fn expand_or_pat < ' p , ' tcx > ( pat : & ' p Pat < ' tcx > ) -> Vec < & ' p Pat < ' tcx > > {
@@ -111,15 +109,15 @@ pub(crate) struct IntRange {
111109
112110impl IntRange {
113111 #[ inline]
114- fn is_integral ( ty : Ty < ' _ > ) -> bool {
112+ pub ( super ) fn is_integral ( ty : Ty < ' _ > ) -> bool {
115113 matches ! ( ty. kind( ) , ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Bool )
116114 }
117115
118- fn is_singleton ( & self ) -> bool {
116+ pub ( super ) fn is_singleton ( & self ) -> bool {
119117 self . range . start ( ) == self . range . end ( )
120118 }
121119
122- fn boundaries ( & self ) -> ( u128 , u128 ) {
120+ pub ( super ) fn boundaries ( & self ) -> ( u128 , u128 ) {
123121 ( * self . range . start ( ) , * self . range . end ( ) )
124122 }
125123
@@ -177,23 +175,6 @@ impl IntRange {
177175 }
178176 }
179177
180- fn suspicious_intersection ( & self , other : & Self ) -> bool {
181- // `false` in the following cases:
182- // 1 ---- // 1 ---------- // 1 ---- // 1 ----
183- // 2 ---------- // 2 ---- // 2 ---- // 2 ----
184- //
185- // The following are currently `false`, but could be `true` in the future (#64007):
186- // 1 --------- // 1 ---------
187- // 2 ---------- // 2 ----------
188- //
189- // `true` in the following cases:
190- // 1 ------- // 1 -------
191- // 2 -------- // 2 -------
192- let ( lo, hi) = self . boundaries ( ) ;
193- let ( other_lo, other_hi) = other. boundaries ( ) ;
194- ( lo == other_hi || hi == other_lo) && !self . is_singleton ( ) && !other. is_singleton ( )
195- }
196-
197178 /// Partition a range of integers into disjoint subranges. This does constructor splitting for
198179 /// integer ranges as explained at the top of the file.
199180 ///
@@ -293,7 +274,7 @@ impl IntRange {
293274 }
294275
295276 /// Only used for displaying the range.
296- fn to_pat < ' tcx > ( & self , tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Pat < ' tcx > {
277+ pub ( super ) fn to_pat < ' tcx > ( & self , tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Pat < ' tcx > {
297278 let ( lo, hi) = self . boundaries ( ) ;
298279
299280 let bias = IntRange :: signed_bias ( tcx, ty) ;
@@ -315,51 +296,6 @@ impl IntRange {
315296
316297 Pat { ty, span : DUMMY_SP , kind }
317298 }
318-
319- /// Lint on likely incorrect range patterns (#63987)
320- pub ( super ) fn lint_overlapping_range_endpoints < ' a , ' p : ' a , ' tcx : ' a > (
321- & self ,
322- pcx : & PatCtxt < ' _ , ' p , ' tcx > ,
323- pats : impl Iterator < Item = & ' a DeconstructedPat < ' p , ' tcx > > ,
324- column_count : usize ,
325- lint_root : HirId ,
326- ) {
327- if self . is_singleton ( ) {
328- return ;
329- }
330-
331- if column_count != 1 {
332- // FIXME: for now, only check for overlapping ranges on simple range
333- // patterns. Otherwise with the current logic the following is detected
334- // as overlapping:
335- // ```
336- // match (0u8, true) {
337- // (0 ..= 125, false) => {}
338- // (125 ..= 255, true) => {}
339- // _ => {}
340- // }
341- // ```
342- return ;
343- }
344-
345- let overlap: Vec < _ > = pats
346- . filter_map ( |pat| Some ( ( pat. ctor ( ) . as_int_range ( ) ?, pat. span ( ) ) ) )
347- . filter ( |( range, _) | self . suspicious_intersection ( range) )
348- . map ( |( range, span) | Overlap {
349- range : self . intersection ( & range) . unwrap ( ) . to_pat ( pcx. cx . tcx , pcx. ty ) ,
350- span,
351- } )
352- . collect ( ) ;
353-
354- if !overlap. is_empty ( ) {
355- pcx. cx . tcx . emit_spanned_lint (
356- lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
357- lint_root,
358- pcx. span ,
359- OverlappingRangeEndpoints { overlap, range : pcx. span } ,
360- ) ;
361- }
362- }
363299}
364300
365301/// Note: this is often not what we want: e.g. `false` is converted into the range `0..=0` and
@@ -651,7 +587,7 @@ impl<'tcx> Constructor<'tcx> {
651587 _ => None ,
652588 }
653589 }
654- fn as_int_range ( & self ) -> Option < & IntRange > {
590+ pub ( super ) fn as_int_range ( & self ) -> Option < & IntRange > {
655591 match self {
656592 IntRange ( range) => Some ( range) ,
657593 _ => None ,
@@ -905,9 +841,9 @@ pub(super) enum ConstructorSet {
905841/// either fully included in or disjoint from each constructor in the column. This avoids
906842/// non-trivial intersections like between `0..10` and `5..15`.
907843#[ derive( Debug ) ]
908- struct SplitConstructorSet < ' tcx > {
909- present : SmallVec < [ Constructor < ' tcx > ; 1 ] > ,
910- missing : Vec < Constructor < ' tcx > > ,
844+ pub ( super ) struct SplitConstructorSet < ' tcx > {
845+ pub ( super ) present : SmallVec < [ Constructor < ' tcx > ; 1 ] > ,
846+ pub ( super ) missing : Vec < Constructor < ' tcx > > ,
911847 /// For the `non_exhaustive_omitted_patterns` lint.
912848 nonexhaustive_enum_missing_visible_variants : bool ,
913849}
@@ -1039,7 +975,7 @@ impl ConstructorSet {
1039975 /// constructors to 1/ determine which constructors of the type (if any) are missing; 2/ split
1040976 /// constructors to handle non-trivial intersections e.g. on ranges or slices.
1041977 #[ instrument( level = "debug" , skip( self , pcx, ctors) , ret) ]
1042- fn split < ' a , ' tcx > (
978+ pub ( super ) fn split < ' a , ' tcx > (
1043979 & self ,
1044980 pcx : & PatCtxt < ' _ , ' _ , ' tcx > ,
1045981 ctors : impl Iterator < Item = & ' a Constructor < ' tcx > > + Clone ,
@@ -1621,6 +1557,13 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
16211557 pub ( super ) fn is_or_pat ( & self ) -> bool {
16221558 matches ! ( self . ctor, Or )
16231559 }
1560+ pub ( super ) fn flatten_or_pat ( & ' p self ) -> SmallVec < [ & ' p Self ; 1 ] > {
1561+ if self . is_or_pat ( ) {
1562+ self . iter_fields ( ) . flat_map ( |p| p. flatten_or_pat ( ) ) . collect ( )
1563+ } else {
1564+ smallvec ! [ self ]
1565+ }
1566+ }
16241567
16251568 pub ( super ) fn ctor ( & self ) -> & Constructor < ' tcx > {
16261569 & self . ctor
0 commit comments