@@ -84,7 +84,7 @@ impl ExprValidator {
84
84
85
85
match expr {
86
86
Expr :: Match { expr, arms } => {
87
- self . validate_match ( id, * expr, arms, db, self . infer . clone ( ) ) ;
87
+ self . validate_match ( id, * expr, arms, db) ;
88
88
}
89
89
Expr :: Call { .. } | Expr :: MethodCall { .. } => {
90
90
self . validate_call ( db, id, expr, & mut filter_map_next_checker) ;
@@ -147,16 +147,15 @@ impl ExprValidator {
147
147
148
148
fn validate_match (
149
149
& mut self ,
150
- id : ExprId ,
151
150
match_expr : ExprId ,
151
+ scrutinee_expr : ExprId ,
152
152
arms : & [ MatchArm ] ,
153
153
db : & dyn HirDatabase ,
154
- infer : Arc < InferenceResult > ,
155
154
) {
156
155
let body = db. body ( self . owner ) ;
157
156
158
- let match_expr_ty = & infer[ match_expr ] ;
159
- if match_expr_ty . is_unknown ( ) {
157
+ let scrut_ty = & self . infer [ scrutinee_expr ] ;
158
+ if scrut_ty . is_unknown ( ) {
160
159
return ;
161
160
}
162
161
@@ -166,23 +165,23 @@ impl ExprValidator {
166
165
let mut m_arms = Vec :: with_capacity ( arms. len ( ) ) ;
167
166
let mut has_lowering_errors = false ;
168
167
for arm in arms {
169
- if let Some ( pat_ty) = infer. type_of_pat . get ( arm. pat ) {
168
+ if let Some ( pat_ty) = self . infer . type_of_pat . get ( arm. pat ) {
170
169
// We only include patterns whose type matches the type
171
- // of the match expression. If we had an InvalidMatchArmPattern
170
+ // of the scrutinee expression. If we had an InvalidMatchArmPattern
172
171
// diagnostic or similar we could raise that in an else
173
172
// block here.
174
173
//
175
174
// When comparing the types, we also have to consider that rustc
176
- // will automatically de-reference the match expression type if
175
+ // will automatically de-reference the scrutinee expression type if
177
176
// necessary.
178
177
//
179
178
// FIXME we should use the type checker for this.
180
- if ( pat_ty == match_expr_ty
181
- || match_expr_ty
179
+ if ( pat_ty == scrut_ty
180
+ || scrut_ty
182
181
. as_reference ( )
183
182
. map ( |( match_expr_ty, ..) | match_expr_ty == pat_ty)
184
183
. unwrap_or ( false ) )
185
- && types_of_subpatterns_do_match ( arm. pat , & body, & infer)
184
+ && types_of_subpatterns_do_match ( arm. pat , & body, & self . infer )
186
185
{
187
186
// If we had a NotUsefulMatchArm diagnostic, we could
188
187
// check the usefulness of each pattern as we added it
@@ -206,16 +205,16 @@ impl ExprValidator {
206
205
return ;
207
206
}
208
207
209
- let report = compute_match_usefulness ( & cx, & m_arms, match_expr_ty ) ;
208
+ let report = compute_match_usefulness ( & cx, & m_arms, scrut_ty ) ;
210
209
211
210
// FIXME Report unreacheble arms
212
211
// https://github.com/rust-lang/rust/blob/f31622a50/compiler/rustc_mir_build/src/thir/pattern/check_match.rs#L200
213
212
214
213
let witnesses = report. non_exhaustiveness_witnesses ;
215
214
if !witnesses. is_empty ( ) {
216
215
self . diagnostics . push ( BodyValidationDiagnostic :: MissingMatchArms {
217
- match_expr : id ,
218
- uncovered_patterns : missing_match_arms ( & cx, match_expr_ty , witnesses, arms) ,
216
+ match_expr,
217
+ uncovered_patterns : missing_match_arms ( & cx, scrut_ty , witnesses, arms) ,
219
218
} ) ;
220
219
}
221
220
}
@@ -379,7 +378,7 @@ fn missing_match_arms<'p>(
379
378
arms : & [ MatchArm ] ,
380
379
) -> String {
381
380
struct DisplayWitness < ' a , ' p > ( & ' a DeconstructedPat < ' p > , & ' a MatchCheckCtx < ' a , ' p > ) ;
382
- impl < ' a , ' p > fmt:: Display for DisplayWitness < ' a , ' p > {
381
+ impl fmt:: Display for DisplayWitness < ' _ , ' _ > {
383
382
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
384
383
let DisplayWitness ( witness, cx) = * self ;
385
384
let pat = witness. to_pat ( cx) ;
0 commit comments