Skip to content

Commit

Permalink
Auto merge of rust-lang#12460 - Veykril:move-guard, r=Veykril
Browse files Browse the repository at this point in the history
minor: Reduce move-guard trigger range
  • Loading branch information
bors committed Jun 3, 2022
2 parents 58b6d46 + b34e27d commit 43d9c3f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions crates/ide-assists/src/handlers/move_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
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 needs_dedent = replace_node != *if_expr.syntax();
let (conds_blocks, tail) = parse_if_chain(if_expr)?;
Expand Down Expand Up @@ -323,7 +327,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 { $0false },
x => if x > 10$0 { false },
_ => true
}
}
Expand Down Expand Up @@ -457,7 +461,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if let 62 = x && true { $0false },
x => if let 62 = x $0&& true { false },
_ => true
}
}
Expand All @@ -480,7 +484,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 { $0 },
x => if x $0> 10 { },
_ => true
}
}
Expand All @@ -503,8 +507,8 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 {
92;$0
x => if$0 x > 10 {
92;
false
},
_ => true
Expand Down Expand Up @@ -533,8 +537,8 @@ fn main() {
fn main() {
match 92 {
x => {
if x > 10 {
92;$0
if x > $010 {
92;
false
}
}
Expand Down Expand Up @@ -563,7 +567,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 {$0
x => if x > $010 {
false
} else {
true
Expand Down Expand Up @@ -593,7 +597,7 @@ fn main() {
fn main() {
match 92 {
x => {
if x > 10 {$0
if x $0> 10 {
false
} else {
true
Expand Down Expand Up @@ -622,7 +626,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 { $0 } else { },
x => if x > $010 { } else { },
_ => true
}
}
Expand All @@ -646,8 +650,8 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 {
92;$0
x => if$0 x > 10 {
92;
false
} else {
true
Expand Down Expand Up @@ -679,7 +683,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 {$0
x => if x $0> 10 {
false
} else {
42;
Expand Down Expand Up @@ -713,7 +717,7 @@ fn main() {
fn main() {
match 92 {
x => {
if x > 10 {$0
if x > $010 {
false
} else {
42;
Expand Down Expand Up @@ -748,7 +752,7 @@ fn main() {
match 92 {
3 => true,
x => {
if x > 10 {$0
if x > $010 {
false
} else {
92;
Expand Down Expand Up @@ -781,7 +785,7 @@ fn main() {
fn main() {
match 92 {
3 => true,
x => if x > 10 {$0
x => if x > $010 {
false
} else {
92;
Expand Down Expand Up @@ -813,7 +817,7 @@ fn main() {
fn main() {
match 92 {
3 => true,
x => if x > 10 {$0
x => if x $0> 10 {
false
} else if x > 5 {
true
Expand Down Expand Up @@ -849,7 +853,7 @@ fn main() {
match 92 {
3 => true,
x => {
if x > 10 {$0
if x > $010 {
false
} else if x > 5 {
true
Expand Down Expand Up @@ -885,7 +889,7 @@ fn main() {
fn main() {
match 92 {
3 => 0,
x => if x > 10 {$0
x => if x $0> 10 {
1
} else if x > 5 {
2
Expand Down Expand Up @@ -923,7 +927,7 @@ fn main() {
fn main() {
match 92 {
3 => 0,
x => if x > 10 {$0
x => if x $0> 10 {
1
} else if x > 5 {
2
Expand Down Expand Up @@ -960,7 +964,7 @@ fn main() {
fn main() {
match 92 {
3 => 0,
x => if x > 10 {$0
x => if x > $010 {
1
} else if x > 5 {
2
Expand Down

0 comments on commit 43d9c3f

Please sign in to comment.