1
- use smallvec:: SmallVec ;
2
-
3
- use rustc_data_structures:: captures:: Captures ;
4
- use rustc_middle:: ty:: { self , Ty } ;
1
+ use rustc_middle:: ty:: Ty ;
5
2
use rustc_session:: lint;
6
3
use rustc_session:: lint:: builtin:: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
7
4
8
- use crate :: constructor:: MaybeInfiniteInt ;
9
5
use crate :: errors:: {
10
6
NonExhaustiveOmittedPattern , NonExhaustiveOmittedPatternLintOnArm , Overlap ,
11
7
OverlappingRangeEndpoints , Uncovered ,
@@ -14,7 +10,6 @@ use crate::rustc::{
14
10
self , Constructor , DeconstructedPat , MatchArm , MatchCtxt , PlaceCtxt , RustcMatchCheckCtxt ,
15
11
SplitConstructorSet , WitnessPat ,
16
12
} ;
17
- use crate :: usefulness:: OverlappingRanges ;
18
13
use crate :: TypeCx ;
19
14
20
15
/// A column of patterns in the matrix, where a column is the intuitive notion of "subpatterns that
@@ -64,10 +59,6 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
64
59
pcx. ctors_for_ty ( ) . split ( pcx, column_ctors)
65
60
}
66
61
67
- fn iter ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , ' tcx > > + Captures < ' _ > {
68
- self . patterns . iter ( ) . copied ( )
69
- }
70
-
71
62
/// Does specialization: given a constructor, this takes the patterns from the column that match
72
63
/// the constructor, and outputs their fields.
73
64
/// This returns one column per field of the constructor. They usually all have the same length
@@ -212,81 +203,10 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
212
203
}
213
204
}
214
205
215
- /// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
216
- #[ instrument( level = "debug" , skip( cx) ) ]
217
- pub ( crate ) fn collect_overlapping_range_endpoints < ' a , ' p , ' tcx > (
218
- cx : MatchCtxt < ' a , ' p , ' tcx > ,
219
- column : & PatternColumn < ' p , ' tcx > ,
220
- overlapping_range_endpoints : & mut Vec < rustc:: OverlappingRanges < ' p , ' tcx > > ,
221
- ) {
222
- let Some ( ty) = column. head_ty ( cx) else {
223
- return ;
224
- } ;
225
- let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
226
-
227
- let set = column. analyze_ctors ( pcx) ;
228
-
229
- if matches ! ( ty. kind( ) , ty:: Char | ty:: Int ( _) | ty:: Uint ( _) ) {
230
- // If two ranges overlapped, the split set will contain their intersection as a singleton.
231
- let split_int_ranges = set. present . iter ( ) . filter_map ( |c| c. as_int_range ( ) ) ;
232
- for overlap_range in split_int_ranges. clone ( ) {
233
- if overlap_range. is_singleton ( ) {
234
- let overlap: MaybeInfiniteInt = overlap_range. lo ;
235
- // Ranges that look like `lo..=overlap`.
236
- let mut prefixes: SmallVec < [ _ ; 1 ] > = Default :: default ( ) ;
237
- // Ranges that look like `overlap..=hi`.
238
- let mut suffixes: SmallVec < [ _ ; 1 ] > = Default :: default ( ) ;
239
- // Iterate on patterns that contained `overlap`.
240
- for pat in column. iter ( ) {
241
- let Constructor :: IntRange ( this_range) = pat. ctor ( ) else { continue } ;
242
- if this_range. is_singleton ( ) {
243
- // Don't lint when one of the ranges is a singleton.
244
- continue ;
245
- }
246
- if this_range. lo == overlap {
247
- // `this_range` looks like `overlap..=this_range.hi`; it overlaps with any
248
- // ranges that look like `lo..=overlap`.
249
- if !prefixes. is_empty ( ) {
250
- overlapping_range_endpoints. push ( OverlappingRanges {
251
- pat,
252
- overlaps_on : * overlap_range,
253
- overlaps_with : prefixes. as_slice ( ) . to_vec ( ) ,
254
- } ) ;
255
- }
256
- suffixes. push ( pat)
257
- } else if this_range. hi == overlap. plus_one ( ) {
258
- // `this_range` looks like `this_range.lo..=overlap`; it overlaps with any
259
- // ranges that look like `overlap..=hi`.
260
- if !suffixes. is_empty ( ) {
261
- overlapping_range_endpoints. push ( OverlappingRanges {
262
- pat,
263
- overlaps_on : * overlap_range,
264
- overlaps_with : suffixes. as_slice ( ) . to_vec ( ) ,
265
- } ) ;
266
- }
267
- prefixes. push ( pat)
268
- }
269
- }
270
- }
271
- }
272
- } else {
273
- // Recurse into the fields.
274
- for ctor in set. present {
275
- for col in column. specialize ( pcx, & ctor) {
276
- collect_overlapping_range_endpoints ( cx, & col, overlapping_range_endpoints) ;
277
- }
278
- }
279
- }
280
- }
281
-
282
- #[ instrument( level = "debug" , skip( cx) ) ]
283
206
pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
284
207
cx : MatchCtxt < ' a , ' p , ' tcx > ,
285
- column : & PatternColumn < ' p , ' tcx > ,
208
+ overlapping_range_endpoints : & [ rustc :: OverlappingRanges < ' p , ' tcx > ] ,
286
209
) {
287
- let mut overlapping_range_endpoints = Vec :: new ( ) ;
288
- collect_overlapping_range_endpoints ( cx, column, & mut overlapping_range_endpoints) ;
289
-
290
210
let rcx = cx. tycx ;
291
211
for overlap in overlapping_range_endpoints {
292
212
let overlap_as_pat = rcx. hoist_pat_range ( & overlap. overlaps_on , overlap. pat . ty ( ) ) ;
0 commit comments