Skip to content

Commit 43d9c3f

Browse files
committed
Auto merge of rust-lang#12460 - Veykril:move-guard, r=Veykril
minor: Reduce move-guard trigger range
2 parents 58b6d46 + b34e27d commit 43d9c3f

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

crates/ide-assists/src/handlers/move_guard.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
106106
None
107107
}
108108
})?;
109+
if ctx.offset() > if_expr.then_branch()?.syntax().text_range().start() {
110+
return None;
111+
}
112+
109113
let replace_node = replace_node.unwrap_or_else(|| if_expr.syntax().clone());
110114
let needs_dedent = replace_node != *if_expr.syntax();
111115
let (conds_blocks, tail) = parse_if_chain(if_expr)?;
@@ -323,7 +327,7 @@ fn main() {
323327
r#"
324328
fn main() {
325329
match 92 {
326-
x => if x > 10 { $0false },
330+
x => if x > 10$0 { false },
327331
_ => true
328332
}
329333
}
@@ -457,7 +461,7 @@ fn main() {
457461
r#"
458462
fn main() {
459463
match 92 {
460-
x => if let 62 = x && true { $0false },
464+
x => if let 62 = x $0&& true { false },
461465
_ => true
462466
}
463467
}
@@ -480,7 +484,7 @@ fn main() {
480484
r#"
481485
fn main() {
482486
match 92 {
483-
x => if x > 10 { $0 },
487+
x => if x $0> 10 { },
484488
_ => true
485489
}
486490
}
@@ -503,8 +507,8 @@ fn main() {
503507
r#"
504508
fn main() {
505509
match 92 {
506-
x => if x > 10 {
507-
92;$0
510+
x => if$0 x > 10 {
511+
92;
508512
false
509513
},
510514
_ => true
@@ -533,8 +537,8 @@ fn main() {
533537
fn main() {
534538
match 92 {
535539
x => {
536-
if x > 10 {
537-
92;$0
540+
if x > $010 {
541+
92;
538542
false
539543
}
540544
}
@@ -563,7 +567,7 @@ fn main() {
563567
r#"
564568
fn main() {
565569
match 92 {
566-
x => if x > 10 {$0
570+
x => if x > $010 {
567571
false
568572
} else {
569573
true
@@ -593,7 +597,7 @@ fn main() {
593597
fn main() {
594598
match 92 {
595599
x => {
596-
if x > 10 {$0
600+
if x $0> 10 {
597601
false
598602
} else {
599603
true
@@ -622,7 +626,7 @@ fn main() {
622626
r#"
623627
fn main() {
624628
match 92 {
625-
x => if x > 10 { $0 } else { },
629+
x => if x > $010 { } else { },
626630
_ => true
627631
}
628632
}
@@ -646,8 +650,8 @@ fn main() {
646650
r#"
647651
fn main() {
648652
match 92 {
649-
x => if x > 10 {
650-
92;$0
653+
x => if$0 x > 10 {
654+
92;
651655
false
652656
} else {
653657
true
@@ -679,7 +683,7 @@ fn main() {
679683
r#"
680684
fn main() {
681685
match 92 {
682-
x => if x > 10 {$0
686+
x => if x $0> 10 {
683687
false
684688
} else {
685689
42;
@@ -713,7 +717,7 @@ fn main() {
713717
fn main() {
714718
match 92 {
715719
x => {
716-
if x > 10 {$0
720+
if x > $010 {
717721
false
718722
} else {
719723
42;
@@ -748,7 +752,7 @@ fn main() {
748752
match 92 {
749753
3 => true,
750754
x => {
751-
if x > 10 {$0
755+
if x > $010 {
752756
false
753757
} else {
754758
92;
@@ -781,7 +785,7 @@ fn main() {
781785
fn main() {
782786
match 92 {
783787
3 => true,
784-
x => if x > 10 {$0
788+
x => if x > $010 {
785789
false
786790
} else {
787791
92;
@@ -813,7 +817,7 @@ fn main() {
813817
fn main() {
814818
match 92 {
815819
3 => true,
816-
x => if x > 10 {$0
820+
x => if x $0> 10 {
817821
false
818822
} else if x > 5 {
819823
true
@@ -849,7 +853,7 @@ fn main() {
849853
match 92 {
850854
3 => true,
851855
x => {
852-
if x > 10 {$0
856+
if x > $010 {
853857
false
854858
} else if x > 5 {
855859
true
@@ -885,7 +889,7 @@ fn main() {
885889
fn main() {
886890
match 92 {
887891
3 => 0,
888-
x => if x > 10 {$0
892+
x => if x $0> 10 {
889893
1
890894
} else if x > 5 {
891895
2
@@ -923,7 +927,7 @@ fn main() {
923927
fn main() {
924928
match 92 {
925929
3 => 0,
926-
x => if x > 10 {$0
930+
x => if x $0> 10 {
927931
1
928932
} else if x > 5 {
929933
2
@@ -960,7 +964,7 @@ fn main() {
960964
fn main() {
961965
match 92 {
962966
3 => 0,
963-
x => if x > 10 {$0
967+
x => if x > $010 {
964968
1
965969
} else if x > 5 {
966970
2

0 commit comments

Comments
 (0)