aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authorivan770 <[email protected]>2020-12-09 08:17:28 +0000
committerGitHub <[email protected]>2020-12-09 08:17:28 +0000
commit86c183716cc6dfd44da15c86a7726d0a117c214e (patch)
tree9f3214d0207261999df1169fc3c7ab7e5d0fc8ed /crates/hir_ty
parent7738467e0a11c9878d9e9486daeb0dc18d93b8e8 (diff)
Apply suggestions from code review
Co-authored-by: bjorn3 <[email protected]>
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/diagnostics/expr.rs37
1 files changed, 20 insertions, 17 deletions
diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs
index 98b3cade2..27ffcf291 100644
--- a/crates/hir_ty/src/diagnostics/expr.rs
+++ b/crates/hir_ty/src/diagnostics/expr.rs
@@ -77,13 +77,11 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
77 } 77 }
78 } 78 }
79 let body_expr = &body[body.body_expr]; 79 let body_expr = &body[body.body_expr];
80 if let Expr::Block { tail: Some(t), .. } = body_expr { 80 if let Expr::Block { statements, tail, .. } = body_expr {
81 self.validate_results_in_tail_expr(body.body_expr, *t, db); 81 if let Some(t) = tail {
82 } else { 82 self.validate_results_in_tail_expr(body.body_expr, *t, db);
83 if let Expr::Block { statements, .. } = body_expr { 83 } else if let Some(Statement::Expr(id)) = statements.last() {
84 if let Some(Statement::Expr(id)) = statements.last() { 84 self.validate_missing_tail_expr(body.body_expr, *id, db);
85 self.validate_missing_tail_expr(body.body_expr, *id, db);
86 }
87 } 85 }
88 } 86 }
89 } 87 }
@@ -336,17 +334,22 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
336 None => return, 334 None => return,
337 }; 335 };
338 336
339 if let Some(possible_tail_ty) = self.infer.type_of_expr.get(possible_tail_id) { 337 let possible_tail_ty = if let Some(possible_tail_ty) = self.infer.type_of_expr.get(possible_tail_id) {
340 if mismatch.actual == Ty::unit() && mismatch.expected == *possible_tail_ty { 338 possible_tail_ty
341 let (_, source_map) = db.body_with_source_map(self.owner.into()); 339 } else {
340 return;
341 };
342 342
343 if let Ok(source_ptr) = source_map.expr_syntax(possible_tail_id) { 343 if mismatch.actual != Ty::unit() || mismatch.expected != *possible_tail_ty {
344 self.sink.push(RemoveThisSemicolon { 344 return;
345 file: source_ptr.file_id, 345 }
346 expr: source_ptr.value, 346
347 }); 347 let (_, source_map) = db.body_with_source_map(self.owner.into());
348 } 348 if let Ok(source_ptr) = source_map.expr_syntax(possible_tail_id) {
349 } 349 self.sink.push(RemoveThisSemicolon {
350 file: source_ptr.file_id,
351 expr: source_ptr.value,
352 });
350 } 353 }
351 } 354 }
352} 355}