mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
refactor: remove body parameter for "unnecessary else" diagnostic
This commit is contained in:
parent
7dfeb2cdcc
commit
f2218e7278
1 changed files with 3 additions and 9 deletions
|
@ -109,7 +109,7 @@ impl ExprValidator {
|
||||||
self.check_for_trailing_return(*body_expr, &body);
|
self.check_for_trailing_return(*body_expr, &body);
|
||||||
}
|
}
|
||||||
Expr::If { .. } => {
|
Expr::If { .. } => {
|
||||||
self.check_for_unnecessary_else(id, expr, &body, db);
|
self.check_for_unnecessary_else(id, expr, db);
|
||||||
}
|
}
|
||||||
Expr::Block { .. } => {
|
Expr::Block { .. } => {
|
||||||
self.validate_block(db, expr);
|
self.validate_block(db, expr);
|
||||||
|
@ -337,18 +337,12 @@ impl ExprValidator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_unnecessary_else(
|
fn check_for_unnecessary_else(&mut self, id: ExprId, expr: &Expr, db: &dyn HirDatabase) {
|
||||||
&mut self,
|
|
||||||
id: ExprId,
|
|
||||||
expr: &Expr,
|
|
||||||
body: &Body,
|
|
||||||
db: &dyn HirDatabase,
|
|
||||||
) {
|
|
||||||
if let Expr::If { condition: _, then_branch, else_branch } = expr {
|
if let Expr::If { condition: _, then_branch, else_branch } = expr {
|
||||||
if else_branch.is_none() {
|
if else_branch.is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Expr::Block { statements, tail, .. } = &body.exprs[*then_branch] {
|
if let Expr::Block { statements, tail, .. } = &self.body.exprs[*then_branch] {
|
||||||
let last_then_expr = tail.or_else(|| match statements.last()? {
|
let last_then_expr = tail.or_else(|| match statements.last()? {
|
||||||
Statement::Expr { expr, .. } => Some(*expr),
|
Statement::Expr { expr, .. } => Some(*expr),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue