Auto merge of #12460 - Veykril:move-guard, r=Veykril

minor: Reduce move-guard trigger range
This commit is contained in:
bors 2022-06-03 15:00:26 +00:00
commit 43d9c3f649

View File

@ -106,6 +106,10 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
None None
} }
})?; })?;
if ctx.offset() > if_expr.then_branch()?.syntax().text_range().start() {
return None;
}
let replace_node = replace_node.unwrap_or_else(|| if_expr.syntax().clone()); let replace_node = replace_node.unwrap_or_else(|| if_expr.syntax().clone());
let needs_dedent = replace_node != *if_expr.syntax(); let needs_dedent = replace_node != *if_expr.syntax();
let (conds_blocks, tail) = parse_if_chain(if_expr)?; let (conds_blocks, tail) = parse_if_chain(if_expr)?;
@ -323,7 +327,7 @@ fn move_arm_cond_to_match_guard_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 { $0false }, x => if x > 10$0 { false },
_ => true _ => true
} }
} }
@ -457,7 +461,7 @@ fn move_arm_cond_to_match_guard_if_let_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if let 62 = x && true { $0false }, x => if let 62 = x $0&& true { false },
_ => true _ => true
} }
} }
@ -480,7 +484,7 @@ fn move_arm_cond_to_match_guard_if_empty_body_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 { $0 }, x => if x $0> 10 { },
_ => true _ => true
} }
} }
@ -503,8 +507,8 @@ fn move_arm_cond_to_match_guard_if_multiline_body_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 { x => if$0 x > 10 {
92;$0 92;
false false
}, },
_ => true _ => true
@ -533,8 +537,8 @@ fn move_arm_cond_in_block_to_match_guard_if_multiline_body_works() {
fn main() { fn main() {
match 92 { match 92 {
x => { x => {
if x > 10 { if x > $010 {
92;$0 92;
false false
} }
} }
@ -563,7 +567,7 @@ fn move_arm_cond_to_match_guard_with_else_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 {$0 x => if x > $010 {
false false
} else { } else {
true true
@ -593,7 +597,7 @@ fn move_arm_cond_to_match_guard_with_else_block_works() {
fn main() { fn main() {
match 92 { match 92 {
x => { x => {
if x > 10 {$0 if x $0> 10 {
false false
} else { } else {
true true
@ -622,7 +626,7 @@ fn move_arm_cond_to_match_guard_else_if_empty_body_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 { $0 } else { }, x => if x > $010 { } else { },
_ => true _ => true
} }
} }
@ -646,8 +650,8 @@ fn move_arm_cond_to_match_guard_with_else_multiline_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 { x => if$0 x > 10 {
92;$0 92;
false false
} else { } else {
true true
@ -679,7 +683,7 @@ fn move_arm_cond_to_match_guard_with_else_multiline_else_works() {
r#" r#"
fn main() { fn main() {
match 92 { match 92 {
x => if x > 10 {$0 x => if x $0> 10 {
false false
} else { } else {
42; 42;
@ -713,7 +717,7 @@ fn move_arm_cond_to_match_guard_with_else_multiline_else_block_works() {
fn main() { fn main() {
match 92 { match 92 {
x => { x => {
if x > 10 {$0 if x > $010 {
false false
} else { } else {
42; 42;
@ -748,7 +752,7 @@ fn main() {
match 92 { match 92 {
3 => true, 3 => true,
x => { x => {
if x > 10 {$0 if x > $010 {
false false
} else { } else {
92; 92;
@ -781,7 +785,7 @@ fn move_arm_cond_to_match_guard_with_else_comma_works() {
fn main() { fn main() {
match 92 { match 92 {
3 => true, 3 => true,
x => if x > 10 {$0 x => if x > $010 {
false false
} else { } else {
92; 92;
@ -813,7 +817,7 @@ fn move_arm_cond_to_match_guard_elseif() {
fn main() { fn main() {
match 92 { match 92 {
3 => true, 3 => true,
x => if x > 10 {$0 x => if x $0> 10 {
false false
} else if x > 5 { } else if x > 5 {
true true
@ -849,7 +853,7 @@ fn main() {
match 92 { match 92 {
3 => true, 3 => true,
x => { x => {
if x > 10 {$0 if x > $010 {
false false
} else if x > 5 { } else if x > 5 {
true true
@ -885,7 +889,7 @@ fn move_arm_cond_to_match_guard_elseif_chain() {
fn main() { fn main() {
match 92 { match 92 {
3 => 0, 3 => 0,
x => if x > 10 {$0 x => if x $0> 10 {
1 1
} else if x > 5 { } else if x > 5 {
2 2
@ -923,7 +927,7 @@ fn move_arm_cond_to_match_guard_elseif_iflet() {
fn main() { fn main() {
match 92 { match 92 {
3 => 0, 3 => 0,
x => if x > 10 {$0 x => if x $0> 10 {
1 1
} else if x > 5 { } else if x > 5 {
2 2
@ -960,7 +964,7 @@ fn move_arm_cond_to_match_guard_elseif_notail() {
fn main() { fn main() {
match 92 { match 92 {
3 => 0, 3 => 0,
x => if x > 10 {$0 x => if x > $010 {
1 1
} else if x > 5 { } else if x > 5 {
2 2