mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
remove flavor
This commit is contained in:
parent
5287a2506c
commit
f3a82c372c
3 changed files with 10 additions and 10 deletions
|
@ -11,8 +11,8 @@ pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) ->
|
||||||
let expr = cond.expr()?;
|
let expr = cond.expr()?;
|
||||||
let then_block = if_expr.then_branch()?;
|
let then_block = if_expr.then_branch()?;
|
||||||
let else_block = match if_expr.else_branch()? {
|
let else_block = match if_expr.else_branch()? {
|
||||||
ast::ElseBranchFlavor::Block(it) => it,
|
ast::ElseBranch::Block(it) => it,
|
||||||
ast::ElseBranchFlavor::IfExpr(_) => return None,
|
ast::ElseBranch::IfExpr(_) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
ctx.add_action(AssistId("replace_if_let_with_match"), "replace with match", |edit| {
|
ctx.add_action(AssistId("replace_if_let_with_match"), "replace with match", |edit| {
|
||||||
|
|
|
@ -516,8 +516,8 @@ impl ExprCollector {
|
||||||
let else_branch = e
|
let else_branch = e
|
||||||
.else_branch()
|
.else_branch()
|
||||||
.map(|b| match b {
|
.map(|b| match b {
|
||||||
ast::ElseBranchFlavor::Block(it) => self.collect_block(it),
|
ast::ElseBranch::Block(it) => self.collect_block(it),
|
||||||
ast::ElseBranchFlavor::IfExpr(elif) => {
|
ast::ElseBranch::IfExpr(elif) => {
|
||||||
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
||||||
self.collect_expr(expr)
|
self.collect_expr(expr)
|
||||||
}
|
}
|
||||||
|
@ -533,8 +533,8 @@ impl ExprCollector {
|
||||||
let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr()));
|
let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr()));
|
||||||
let then_branch = self.collect_block_opt(e.then_branch());
|
let then_branch = self.collect_block_opt(e.then_branch());
|
||||||
let else_branch = e.else_branch().map(|b| match b {
|
let else_branch = e.else_branch().map(|b| match b {
|
||||||
ast::ElseBranchFlavor::Block(it) => self.collect_block(it),
|
ast::ElseBranch::Block(it) => self.collect_block(it),
|
||||||
ast::ElseBranchFlavor::IfExpr(elif) => {
|
ast::ElseBranch::IfExpr(elif) => {
|
||||||
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
let expr: &ast::Expr = ast::Expr::cast(elif.syntax()).unwrap();
|
||||||
self.collect_expr(expr)
|
self.collect_expr(expr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ impl LetStmt {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum ElseBranchFlavor<'a> {
|
pub enum ElseBranch<'a> {
|
||||||
Block(&'a Block),
|
Block(&'a Block),
|
||||||
IfExpr(&'a IfExpr),
|
IfExpr(&'a IfExpr),
|
||||||
}
|
}
|
||||||
|
@ -173,12 +173,12 @@ impl IfExpr {
|
||||||
pub fn then_branch(&self) -> Option<&Block> {
|
pub fn then_branch(&self) -> Option<&Block> {
|
||||||
self.blocks().nth(0)
|
self.blocks().nth(0)
|
||||||
}
|
}
|
||||||
pub fn else_branch(&self) -> Option<ElseBranchFlavor> {
|
pub fn else_branch(&self) -> Option<ElseBranch> {
|
||||||
let res = match self.blocks().nth(1) {
|
let res = match self.blocks().nth(1) {
|
||||||
Some(block) => ElseBranchFlavor::Block(block),
|
Some(block) => ElseBranch::Block(block),
|
||||||
None => {
|
None => {
|
||||||
let elif: &IfExpr = child_opt(self)?;
|
let elif: &IfExpr = child_opt(self)?;
|
||||||
ElseBranchFlavor::IfExpr(elif)
|
ElseBranch::IfExpr(elif)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Some(res)
|
Some(res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue