7869: Add support for deref assignments to "pull assignment up" assist. r=Veykril a=Jesse-Bakker

Fixes #7867


Co-authored-by: Jesse Bakker <github@jessebakker.com>
This commit is contained in:
bors[bot] 2021-03-05 19:52:15 +00:00 committed by GitHub
commit 7199d5b56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,6 +156,17 @@ fn is_equivalent(
false
}
}
(ast::Expr::PrefixExpr(prefix0), ast::Expr::PrefixExpr(prefix1))
if prefix0.op_kind() == Some(ast::PrefixOp::Deref)
&& prefix1.op_kind() == Some(ast::PrefixOp::Deref) =>
{
mark::hit!(test_pull_assignment_up_deref);
if let (Some(prefix0), Some(prefix1)) = (prefix0.expr(), prefix1.expr()) {
is_equivalent(sema, &prefix0, &prefix1)
} else {
false
}
}
_ => false,
}
}
@ -397,4 +408,36 @@ fn foo() {
}"#,
)
}
#[test]
fn test_pull_assignment_up_deref() {
mark::check!(test_pull_assignment_up_deref);
check_assist(
pull_assignment_up,
r#"
fn foo() {
let mut a = 1;
let b = &mut a;
if true {
$0*b = 2;
} else {
*b = 3;
}
}
"#,
r#"
fn foo() {
let mut a = 1;
let b = &mut a;
*b = if true {
2
} else {
3
};
}
"#,
)
}
}