mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
Add support for deref assignments to "pull assignment up" assist.
Fixes #7867
This commit is contained in:
parent
16a76aa158
commit
ab84a4746b
@ -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
|
||||
};
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user