@@ -26,15 +26,7 @@ use rustc_index::Idx;
26
26
use rustc_middle:: ty:: Ty ;
27
27
28
28
use crate :: constructor:: { Constructor , ConstructorSet } ;
29
- #[ cfg( feature = "rustc" ) ]
30
- use crate :: lints:: {
31
- lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints, PatternColumn ,
32
- } ;
33
29
use crate :: pat:: DeconstructedPat ;
34
- #[ cfg( feature = "rustc" ) ]
35
- use crate :: rustc:: RustcMatchCheckCtxt ;
36
- #[ cfg( feature = "rustc" ) ]
37
- use crate :: usefulness:: { compute_match_usefulness, ValidityConstraint } ;
38
30
39
31
// It's not possible to only enable the `typed_arena` dependency when the `rustc` feature is off, so
40
32
// we use another feature instead. The crate won't compile if one of these isn't enabled.
@@ -107,27 +99,33 @@ pub struct MatchArm<'p, Cx: TypeCx> {
107
99
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
108
100
/// useful, and runs some lints.
109
101
#[ cfg( feature = "rustc" ) ]
110
- pub fn analyze_match < ' p , ' thir , ' tcx > (
111
- tycx : & RustcMatchCheckCtxt < ' p , ' thir , ' tcx > ,
102
+ pub fn analyze_match < ' p , ' thir , ' tcx : ' thir > (
103
+ tycx : & rustc :: RustcMatchCheckCtxt < ' p , ' thir , ' tcx > ,
112
104
arms : & [ rustc:: MatchArm < ' p , ' thir , ' tcx > ] ,
113
105
scrut_ty : Ty < ' tcx > ,
114
106
) -> rustc:: UsefulnessReport < ' p , ' thir , ' tcx > {
107
+ use crate :: lints:: PatternColumn ;
108
+ use crate :: usefulness:: ValidityConstraint ;
109
+
115
110
// Arena to store the extra wildcards we construct during analysis.
116
111
let wildcard_arena = tycx. pattern_arena ;
117
112
let scrut_validity = ValidityConstraint :: from_bool ( tycx. known_valid_scrutinee ) ;
118
113
let cx = MatchCtxt { tycx, wildcard_arena } ;
119
114
120
- let report = compute_match_usefulness ( cx, arms, scrut_ty, scrut_validity) ;
115
+ let report = usefulness :: compute_match_usefulness ( cx, arms, scrut_ty, scrut_validity) ;
121
116
122
- let pat_column = PatternColumn :: new ( arms) ;
117
+ // Only run the lints if the match is exhaustive.
118
+ if report. non_exhaustiveness_witnesses . is_empty ( ) {
119
+ let pat_column = PatternColumn :: new ( arms) ;
123
120
124
- // Lint on ranges that overlap on their endpoints, which is likely a mistake .
125
- lint_overlapping_range_endpoints ( cx, & pat_column) ;
121
+ // Detect possible range-related mistakes .
122
+ lints :: lint_likely_range_mistakes ( cx, & pat_column) ;
126
123
127
- // Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid hitting
128
- // `if let`s. Only run if the match is exhaustive otherwise the error is redundant.
129
- if tycx. refutable && report. non_exhaustiveness_witnesses . is_empty ( ) {
130
- lint_nonexhaustive_missing_variants ( cx, arms, & pat_column, scrut_ty)
124
+ // Run the non_exhaustive_omitted_patterns lint. Only run on refutable patterns to avoid
125
+ // hitting `if let`s.
126
+ if tycx. refutable {
127
+ lints:: lint_nonexhaustive_missing_variants ( cx, arms, & pat_column, scrut_ty)
128
+ }
131
129
}
132
130
133
131
report
0 commit comments