mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-18 00:00:03 +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
|
@ -285,13 +285,27 @@ impl LetStmt {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ElseBranchFlavor<'a> {
|
||||
Block(&'a Block),
|
||||
IfExpr(&'a IfExpr),
|
||||
}
|
||||
|
||||
impl IfExpr {
|
||||
pub fn then_branch(&self) -> Option<&Block> {
|
||||
self.blocks().nth(0)
|
||||
}
|
||||
pub fn else_branch(&self) -> Option<&Block> {
|
||||
self.blocks().nth(1)
|
||||
pub fn else_branch(&self) -> Option<ElseBranchFlavor> {
|
||||
let res = match self.blocks().nth(1) {
|
||||
Some(block) => ElseBranchFlavor::Block(block),
|
||||
None => {
|
||||
let elif: &IfExpr = child_opt(self)?;
|
||||
ElseBranchFlavor::IfExpr(elif)
|
||||
}
|
||||
};
|
||||
Some(res)
|
||||
}
|
||||
|
||||
fn blocks(&self) -> AstChildren<Block> {
|
||||
children(self)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue