aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-05 19:52:15 +0000
committerGitHub <[email protected]>2021-03-05 19:52:15 +0000
commit7199d5b56d47378bb09aab1be718c29ae0284369 (patch)
tree16ad0d7fd964f0520cc7b39d4f4e101e15453418 /crates/ide_assists
parent3d662e320b97fdc50d8cc1721983661900da22d3 (diff)
parentab84a4746ba7489f7bd0c1fdc0b9387bf38fdda8 (diff)
Merge #7869
7869: Add support for deref assignments to "pull assignment up" assist. r=Veykril a=Jesse-Bakker Fixes #7867 Co-authored-by: Jesse Bakker <[email protected]>
Diffstat (limited to 'crates/ide_assists')
-rw-r--r--crates/ide_assists/src/handlers/pull_assignment_up.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/ide_assists/src/handlers/pull_assignment_up.rs b/crates/ide_assists/src/handlers/pull_assignment_up.rs
index 13e1cb754..377ed4f2f 100644
--- a/crates/ide_assists/src/handlers/pull_assignment_up.rs
+++ b/crates/ide_assists/src/handlers/pull_assignment_up.rs
@@ -156,6 +156,17 @@ fn is_equivalent(
156 false 156 false
157 } 157 }
158 } 158 }
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 }
159 _ => false, 170 _ => false,
160 } 171 }
161} 172}
@@ -397,4 +408,36 @@ fn foo() {
397}"#, 408}"#,
398 ) 409 )
399 } 410 }
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#"
418fn 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#"
430fn 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 }
400} 443}