From ab84a4746ba7489f7bd0c1fdc0b9387bf38fdda8 Mon Sep 17 00:00:00 2001 From: Jesse Bakker Date: Thu, 4 Mar 2021 14:43:52 +0100 Subject: Add support for deref assignments to "pull assignment up" assist. Fixes #7867 --- .../ide_assists/src/handlers/pull_assignment_up.rs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'crates/ide_assists') 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( 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 + }; +} +"#, + ) + } } -- cgit v1.2.3