Skip to content

Commit ab84a47

Browse files
committed
Add support for deref assignments to "pull assignment up" assist.
Fixes #7867
1 parent 16a76aa commit ab84a47

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

crates/ide_assists/src/handlers/pull_assignment_up.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ fn is_equivalent(
156156
false
157157
}
158158
}
159+
(ast::Expr::PrefixExpr(prefix0), ast::Expr::PrefixExpr(prefix1))
160+
if prefix0.op_kind() == Some(ast::PrefixOp::Deref)
161+
&& prefix1.op_kind() == Some(ast::PrefixOp::Deref) =>
162+
{
163+
mark::hit!(test_pull_assignment_up_deref);
164+
if let (Some(prefix0), Some(prefix1)) = (prefix0.expr(), prefix1.expr()) {
165+
is_equivalent(sema, &prefix0, &prefix1)
166+
} else {
167+
false
168+
}
169+
}
159170
_ => false,
160171
}
161172
}
@@ -397,4 +408,36 @@ fn foo() {
397408
}"#,
398409
)
399410
}
411+
412+
#[test]
413+
fn test_pull_assignment_up_deref() {
414+
mark::check!(test_pull_assignment_up_deref);
415+
check_assist(
416+
pull_assignment_up,
417+
r#"
418+
fn foo() {
419+
let mut a = 1;
420+
let b = &mut a;
421+
422+
if true {
423+
$0*b = 2;
424+
} else {
425+
*b = 3;
426+
}
427+
}
428+
"#,
429+
r#"
430+
fn foo() {
431+
let mut a = 1;
432+
let b = &mut a;
433+
434+
*b = if true {
435+
2
436+
} else {
437+
3
438+
};
439+
}
440+
"#,
441+
)
442+
}
400443
}

0 commit comments

Comments
 (0)