Skip to content

Commit c8911e8

Browse files
theotherphilmatklad
authored andcommitted
Remove reliance on expr ordering
1 parent 4f6f393 commit c8911e8

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

crates/ra_hir/src/expr/validation.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,15 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
3434
pub(crate) fn validate_body(&mut self, db: &impl HirDatabase) {
3535
let body = self.func.body(db);
3636

37-
// The final expr in the function body is the whole body,
38-
// so the expression being returned is the penultimate expr.
39-
let mut penultimate_expr = None;
40-
let mut final_expr = None;
41-
4237
for e in body.exprs() {
43-
penultimate_expr = final_expr;
44-
final_expr = Some(e);
45-
4638
if let (id, Expr::RecordLit { path, fields, spread }) = e {
4739
self.validate_record_literal(id, path, fields, *spread, db);
4840
}
4941
}
50-
if let Some(e) = penultimate_expr {
51-
self.validate_results_in_tail_expr(e.0, db);
42+
43+
let body_expr = &body[body.body_expr()];
44+
if let Expr::Block { statements: _, tail: Some(t) } = body_expr {
45+
self.validate_results_in_tail_expr(*t, db);
5246
}
5347
}
5448

0 commit comments

Comments
 (0)