@@ -84,7 +84,7 @@ impl ExprValidator {
8484
8585 match expr {
8686 Expr :: Match { expr, arms } => {
87- self . validate_match ( id, * expr, arms, db, self . infer . clone ( ) ) ;
87+ self . validate_match ( id, * expr, arms, db) ;
8888 }
8989 Expr :: Call { .. } | Expr :: MethodCall { .. } => {
9090 self . validate_call ( db, id, expr, & mut filter_map_next_checker) ;
@@ -147,16 +147,15 @@ impl ExprValidator {
147147
148148 fn validate_match (
149149 & mut self ,
150- id : ExprId ,
151150 match_expr : ExprId ,
151+ scrutinee_expr : ExprId ,
152152 arms : & [ MatchArm ] ,
153153 db : & dyn HirDatabase ,
154- infer : Arc < InferenceResult > ,
155154 ) {
156155 let body = db. body ( self . owner ) ;
157156
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 ( ) {
160159 return ;
161160 }
162161
@@ -166,23 +165,23 @@ impl ExprValidator {
166165 let mut m_arms = Vec :: with_capacity ( arms. len ( ) ) ;
167166 let mut has_lowering_errors = false ;
168167 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 ) {
170169 // 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
172171 // diagnostic or similar we could raise that in an else
173172 // block here.
174173 //
175174 // 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
177176 // necessary.
178177 //
179178 // 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
182181 . as_reference ( )
183182 . map ( |( match_expr_ty, ..) | match_expr_ty == pat_ty)
184183 . unwrap_or ( false ) )
185- && types_of_subpatterns_do_match ( arm. pat , & body, & infer)
184+ && types_of_subpatterns_do_match ( arm. pat , & body, & self . infer )
186185 {
187186 // If we had a NotUsefulMatchArm diagnostic, we could
188187 // check the usefulness of each pattern as we added it
@@ -206,16 +205,16 @@ impl ExprValidator {
206205 return ;
207206 }
208207
209- let report = compute_match_usefulness ( & cx, & m_arms, match_expr_ty ) ;
208+ let report = compute_match_usefulness ( & cx, & m_arms, scrut_ty ) ;
210209
211210 // FIXME Report unreacheble arms
212211 // https://github.com/rust-lang/rust/blob/f31622a50/compiler/rustc_mir_build/src/thir/pattern/check_match.rs#L200
213212
214213 let witnesses = report. non_exhaustiveness_witnesses ;
215214 if !witnesses. is_empty ( ) {
216215 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) ,
219218 } ) ;
220219 }
221220 }
@@ -379,7 +378,7 @@ fn missing_match_arms<'p>(
379378 arms : & [ MatchArm ] ,
380379) -> String {
381380 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 < ' _ , ' _ > {
383382 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
384383 let DisplayWitness ( witness, cx) = * self ;
385384 let pat = witness. to_pat ( cx) ;
0 commit comments