Skip to content

Commit 44edf63

Browse files
committed
Add pattern when there's no else branch
1 parent 2bd2960 commit 44edf63

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crates/ide_assists/src/handlers/move_guard.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
9696
// fn handle(action: Action) {
9797
// match action {
9898
// Action::Move { distance } if distance > 10 => foo(),
99+
// Action::Move { distance } => {}
99100
// _ => (),
100101
// }
101102
// }
@@ -175,7 +176,9 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex
175176
}
176177
}
177178
} else {
179+
// There's no else branch. Add a pattern without guard
178180
cov_mark::hit!(move_guard_ifelse_notail);
181+
edit.insert(then_arm_end, format!("\n{}{} => {{}}", spaces, match_pat));
179182
}
180183
},
181184
)
@@ -309,6 +312,7 @@ fn main() {
309312
fn main() {
310313
match 92 {
311314
x if x > 10 => false,
315+
x => {}
312316
_ => true
313317
}
314318
}
@@ -336,6 +340,7 @@ fn main() {
336340
fn main() {
337341
match 92 {
338342
x if x > 10 => false,
343+
x => {}
339344
_ => true
340345
}
341346
}
@@ -363,6 +368,7 @@ fn main() {
363368
fn main() {
364369
match 92 {
365370
x if x > 10 => false,
371+
x => {}
366372
_ => true
367373
}
368374
}
@@ -401,6 +407,7 @@ fn main() {
401407
fn main() {
402408
match 92 {
403409
x if x > 10 => { }
410+
x => {}
404411
_ => true
405412
}
406413
}
@@ -430,6 +437,7 @@ fn main() {
430437
92;
431438
false
432439
}
440+
x => {}
433441
_ => true
434442
}
435443
}
@@ -461,6 +469,7 @@ fn main() {
461469
92;
462470
false
463471
}
472+
x => {}
464473
_ => true
465474
}
466475
}
@@ -881,6 +890,7 @@ fn main() {
881890
42;
882891
3
883892
}
893+
x => {}
884894
}
885895
}
886896
"#,

crates/ide_assists/src/tests/generated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,7 @@ enum Action { Move { distance: u32 }, Stop }
14031403
fn handle(action: Action) {
14041404
match action {
14051405
Action::Move { distance } if distance > 10 => foo(),
1406+
Action::Move { distance } => {}
14061407
_ => (),
14071408
}
14081409
}

0 commit comments

Comments
 (0)