mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 19:17:12 +00:00
Merge pull request #20722 from A4-Tacks/pull-assign-up-inner-if
Fix apply in inner if for pull_assignment_up
This commit is contained in:
commit
d6e14cc457
1 changed files with 35 additions and 0 deletions
|
|
@ -53,6 +53,10 @@ pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||||
};
|
};
|
||||||
|
|
||||||
let tgt: ast::Expr = if let Some(if_expr) = ctx.find_node_at_offset::<ast::IfExpr>() {
|
let tgt: ast::Expr = if let Some(if_expr) = ctx.find_node_at_offset::<ast::IfExpr>() {
|
||||||
|
let if_expr = std::iter::successors(Some(if_expr), |it| {
|
||||||
|
it.syntax().parent().and_then(ast::IfExpr::cast)
|
||||||
|
})
|
||||||
|
.last()?;
|
||||||
collector.collect_if(&if_expr)?;
|
collector.collect_if(&if_expr)?;
|
||||||
if_expr.into()
|
if_expr.into()
|
||||||
} else if let Some(match_expr) = ctx.find_node_at_offset::<ast::MatchExpr>() {
|
} else if let Some(match_expr) = ctx.find_node_at_offset::<ast::MatchExpr>() {
|
||||||
|
|
@ -237,6 +241,37 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_pull_assignment_up_inner_if() {
|
||||||
|
check_assist(
|
||||||
|
pull_assignment_up,
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
let mut a = 1;
|
||||||
|
|
||||||
|
if true {
|
||||||
|
a = 2;
|
||||||
|
} else if true {
|
||||||
|
$0a = 3;
|
||||||
|
} else {
|
||||||
|
a = 4;
|
||||||
|
}
|
||||||
|
}"#,
|
||||||
|
r#"
|
||||||
|
fn foo() {
|
||||||
|
let mut a = 1;
|
||||||
|
|
||||||
|
a = if true {
|
||||||
|
2
|
||||||
|
} else if true {
|
||||||
|
3
|
||||||
|
} else {
|
||||||
|
4
|
||||||
|
};
|
||||||
|
}"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pull_assignment_up_match() {
|
fn test_pull_assignment_up_match() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue