mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Merge #10759
10759: make `add_missing_match_arms` applicable at the end of the match r=Veykril a=rainy-me close #10740 Co-authored-by: rainy-me <github@yue.coffee>
This commit is contained in:
commit
4b9b714b5c
1 changed files with 48 additions and 0 deletions
|
@ -197,6 +197,19 @@ fn cursor_at_trivial_match_arm_list(
|
||||||
return Some(());
|
return Some(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// match x {
|
||||||
|
// bar => baz,
|
||||||
|
// $0
|
||||||
|
// }
|
||||||
|
if let Some(last_arm) = match_arm_list.arms().last() {
|
||||||
|
let last_arm_range = last_arm.syntax().text_range();
|
||||||
|
let match_expr_range = match_expr.syntax().text_range();
|
||||||
|
if last_arm_range.end() <= ctx.offset() && ctx.offset() < match_expr_range.end() {
|
||||||
|
cov_mark::hit!(add_missing_match_arms_end_of_last_arm);
|
||||||
|
return Some(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// match { _$0 => {...} }
|
// match { _$0 => {...} }
|
||||||
let wild_pat = ctx.find_node_at_offset_with_descend::<ast::WildcardPat>()?;
|
let wild_pat = ctx.find_node_at_offset_with_descend::<ast::WildcardPat>()?;
|
||||||
let arm = wild_pat.syntax().parent().and_then(ast::MatchArm::cast)?;
|
let arm = wild_pat.syntax().parent().and_then(ast::MatchArm::cast)?;
|
||||||
|
@ -676,6 +689,41 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_missing_match_arms_end_of_last_arm() {
|
||||||
|
cov_mark::check!(add_missing_match_arms_end_of_last_arm);
|
||||||
|
check_assist(
|
||||||
|
add_missing_match_arms,
|
||||||
|
r#"
|
||||||
|
enum A { One, Two }
|
||||||
|
enum B { One, Two }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = A::One;
|
||||||
|
let b = B::One;
|
||||||
|
match (a, b) {
|
||||||
|
(A::Two, B::One) => {},$0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
enum A { One, Two }
|
||||||
|
enum B { One, Two }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = A::One;
|
||||||
|
let b = B::One;
|
||||||
|
match (a, b) {
|
||||||
|
(A::Two, B::One) => {},
|
||||||
|
$0(A::One, B::One) => todo!(),
|
||||||
|
(A::One, B::Two) => todo!(),
|
||||||
|
(A::Two, B::Two) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_missing_match_arms_tuple_of_enum() {
|
fn add_missing_match_arms_tuple_of_enum() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue