mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 15:14:02 +00:00
Auto merge of #12467 - Veykril:assist-fix, r=Veykril
fix: Fix match to if let assist for wildcard pats
This commit is contained in:
commit
02c6c19152
1 changed files with 25 additions and 0 deletions
|
@ -256,6 +256,7 @@ fn pick_pattern_and_expr_order(
|
||||||
) -> Option<(ast::Pat, ast::Expr, ast::Expr)> {
|
) -> Option<(ast::Pat, ast::Expr, ast::Expr)> {
|
||||||
let res = match (pat, pat2) {
|
let res = match (pat, pat2) {
|
||||||
(ast::Pat::WildcardPat(_), _) => return None,
|
(ast::Pat::WildcardPat(_), _) => return None,
|
||||||
|
(pat, ast::Pat::WildcardPat(_)) => (pat, expr, expr2),
|
||||||
(pat, _) if is_empty_expr(&expr2) => (pat, expr, expr2),
|
(pat, _) if is_empty_expr(&expr2) => (pat, expr, expr2),
|
||||||
(_, pat) if is_empty_expr(&expr) => (pat, expr2, expr),
|
(_, pat) if is_empty_expr(&expr) => (pat, expr2, expr),
|
||||||
(pat, pat2) => match (binds_name(sema, &pat), binds_name(sema, &pat2)) {
|
(pat, pat2) => match (binds_name(sema, &pat), binds_name(sema, &pat2)) {
|
||||||
|
@ -971,4 +972,28 @@ impl VariantData {
|
||||||
} "#,
|
} "#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_replace_match_with_if_let_forces_else() {
|
||||||
|
check_assist(
|
||||||
|
replace_match_with_if_let,
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
match$0 0 {
|
||||||
|
0 => (),
|
||||||
|
_ => code(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
if let 0 = 0 {
|
||||||
|
()
|
||||||
|
} else {
|
||||||
|
code()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue