mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
fix AST for if expressions
then is not always a block...
This commit is contained in:
parent
2d337c88b0
commit
619af1e22c
6 changed files with 112 additions and 5 deletions
|
@ -498,7 +498,13 @@ impl ExprCollector {
|
|||
let then_branch = self.collect_block_opt(e.then_branch());
|
||||
let else_branch = e
|
||||
.else_branch()
|
||||
.map(|e| self.collect_block(e))
|
||||
.map(|b| match b {
|
||||
ast::ElseBranchFlavor::Block(it) => self.collect_block(it),
|
||||
ast::ElseBranchFlavor::IfExpr(elif) => {
|
||||
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
||||
self.collect_expr(expr)
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| self.empty_block());
|
||||
let placeholder_pat = self.pats.alloc(Pat::Missing);
|
||||
let arms = vec![
|
||||
|
@ -521,7 +527,13 @@ impl ExprCollector {
|
|||
} else {
|
||||
let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr()));
|
||||
let then_branch = self.collect_block_opt(e.then_branch());
|
||||
let else_branch = e.else_branch().map(|e| self.collect_block(e));
|
||||
let else_branch = e.else_branch().map(|b| match b {
|
||||
ast::ElseBranchFlavor::Block(it) => self.collect_block(it),
|
||||
ast::ElseBranchFlavor::IfExpr(elif) => {
|
||||
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
||||
self.collect_expr(expr)
|
||||
}
|
||||
});
|
||||
self.alloc_expr(
|
||||
Expr::If {
|
||||
condition,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue