@@ -175,8 +175,9 @@ impl ExprValidator {
175
175
} ) ;
176
176
}
177
177
178
- let receiver_ty = self . infer [ * receiver] . clone ( ) ;
179
- checker. prev_receiver_ty = Some ( receiver_ty) ;
178
+ if let Some ( receiver_ty) = self . infer . type_of_expr_with_adjust ( * receiver) {
179
+ checker. prev_receiver_ty = Some ( receiver_ty. clone ( ) ) ;
180
+ }
180
181
}
181
182
}
182
183
@@ -187,7 +188,9 @@ impl ExprValidator {
187
188
arms : & [ MatchArm ] ,
188
189
db : & dyn HirDatabase ,
189
190
) {
190
- let scrut_ty = & self . infer [ scrutinee_expr] ;
191
+ let Some ( scrut_ty) = self . infer . type_of_expr_with_adjust ( scrutinee_expr) else {
192
+ return ;
193
+ } ;
191
194
if scrut_ty. contains_unknown ( ) {
192
195
return ;
193
196
}
@@ -200,7 +203,7 @@ impl ExprValidator {
200
203
// Note: Skipping the entire diagnostic rather than just not including a faulty match arm is
201
204
// preferred to avoid the chance of false positives.
202
205
for arm in arms {
203
- let Some ( pat_ty) = self . infer . type_of_pat . get ( arm. pat ) else {
206
+ let Some ( pat_ty) = self . infer . type_of_pat_with_adjust ( arm. pat ) else {
204
207
return ;
205
208
} ;
206
209
if pat_ty. contains_unknown ( ) {
@@ -328,7 +331,7 @@ impl ExprValidator {
328
331
continue ;
329
332
}
330
333
let Some ( initializer) = initializer else { continue } ;
331
- let ty = & self . infer [ initializer] ;
334
+ let Some ( ty ) = self . infer . type_of_expr_with_adjust ( initializer) else { continue } ;
332
335
if ty. contains_unknown ( ) {
333
336
continue ;
334
337
}
@@ -433,44 +436,44 @@ impl ExprValidator {
433
436
Statement :: Expr { expr, .. } => Some ( * expr) ,
434
437
_ => None ,
435
438
} ) ;
436
- if let Some ( last_then_expr) = last_then_expr {
437
- let last_then_expr_ty = & self . infer [ last_then_expr] ;
438
- if last_then_expr_ty. is_never ( ) {
439
- // Only look at sources if the then branch diverges and we have an else branch.
440
- let source_map = db. body_with_source_map ( self . owner ) . 1 ;
441
- let Ok ( source_ptr) = source_map. expr_syntax ( id) else {
442
- return ;
443
- } ;
444
- let root = source_ptr. file_syntax ( db) ;
445
- let either:: Left ( ast:: Expr :: IfExpr ( if_expr) ) =
446
- source_ptr. value . to_node ( & root)
447
- else {
439
+ if let Some ( last_then_expr) = last_then_expr
440
+ && let Some ( last_then_expr_ty) =
441
+ self . infer . type_of_expr_with_adjust ( last_then_expr)
442
+ && last_then_expr_ty. is_never ( )
443
+ {
444
+ // Only look at sources if the then branch diverges and we have an else branch.
445
+ let source_map = db. body_with_source_map ( self . owner ) . 1 ;
446
+ let Ok ( source_ptr) = source_map. expr_syntax ( id) else {
447
+ return ;
448
+ } ;
449
+ let root = source_ptr. file_syntax ( db) ;
450
+ let either:: Left ( ast:: Expr :: IfExpr ( if_expr) ) = source_ptr. value . to_node ( & root)
451
+ else {
452
+ return ;
453
+ } ;
454
+ let mut top_if_expr = if_expr;
455
+ loop {
456
+ let parent = top_if_expr. syntax ( ) . parent ( ) ;
457
+ let has_parent_expr_stmt_or_stmt_list =
458
+ parent. as_ref ( ) . is_some_and ( |node| {
459
+ ast:: ExprStmt :: can_cast ( node. kind ( ) )
460
+ | ast:: StmtList :: can_cast ( node. kind ( ) )
461
+ } ) ;
462
+ if has_parent_expr_stmt_or_stmt_list {
463
+ // Only emit diagnostic if parent or direct ancestor is either
464
+ // an expr stmt or a stmt list.
465
+ break ;
466
+ }
467
+ let Some ( parent_if_expr) = parent. and_then ( ast:: IfExpr :: cast) else {
468
+ // Bail if parent is neither an if expr, an expr stmt nor a stmt list.
448
469
return ;
449
470
} ;
450
- let mut top_if_expr = if_expr;
451
- loop {
452
- let parent = top_if_expr. syntax ( ) . parent ( ) ;
453
- let has_parent_expr_stmt_or_stmt_list =
454
- parent. as_ref ( ) . is_some_and ( |node| {
455
- ast:: ExprStmt :: can_cast ( node. kind ( ) )
456
- | ast:: StmtList :: can_cast ( node. kind ( ) )
457
- } ) ;
458
- if has_parent_expr_stmt_or_stmt_list {
459
- // Only emit diagnostic if parent or direct ancestor is either
460
- // an expr stmt or a stmt list.
461
- break ;
462
- }
463
- let Some ( parent_if_expr) = parent. and_then ( ast:: IfExpr :: cast) else {
464
- // Bail if parent is neither an if expr, an expr stmt nor a stmt list.
465
- return ;
466
- } ;
467
- // Check parent if expr.
468
- top_if_expr = parent_if_expr;
469
- }
470
-
471
- self . diagnostics
472
- . push ( BodyValidationDiagnostic :: RemoveUnnecessaryElse { if_expr : id } )
471
+ // Check parent if expr.
472
+ top_if_expr = parent_if_expr;
473
473
}
474
+
475
+ self . diagnostics
476
+ . push ( BodyValidationDiagnostic :: RemoveUnnecessaryElse { if_expr : id } )
474
477
}
475
478
}
476
479
}
0 commit comments