mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 21:25:25 +00:00
Merge pull request #20543 from sgasho/fix/19443_replace_match_with_if_let
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Fix "Replace match with if let" not to trigger when invalid transformations occur
This commit is contained in:
commit
905641f352
1 changed files with 23 additions and 1 deletions
|
|
@ -328,7 +328,14 @@ fn pick_pattern_and_expr_order(
|
|||
(pat, pat2) => match (binds_name(sema, &pat), binds_name(sema, &pat2)) {
|
||||
(true, true) => return None,
|
||||
(true, false) => (pat, guard, expr, expr2),
|
||||
(false, true) => (pat2, guard2, expr2, expr),
|
||||
(false, true) => {
|
||||
// This pattern triggers an invalid transformation.
|
||||
// See issues #11373, #19443
|
||||
if let ast::Pat::IdentPat(_) = pat2 {
|
||||
return None;
|
||||
}
|
||||
(pat2, guard2, expr2, expr)
|
||||
}
|
||||
_ if is_sad_pat(sema, &pat) => (pat2, guard2, expr2, expr),
|
||||
(false, false) => (pat, guard, expr, expr2),
|
||||
},
|
||||
|
|
@ -1892,4 +1899,19 @@ fn main() {
|
|||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_replace_match_with_if_let_not_applicable_pat2_is_ident_pat() {
|
||||
check_assist_not_applicable(
|
||||
replace_match_with_if_let,
|
||||
r"
|
||||
fn test(a: i32) {
|
||||
match$0 a {
|
||||
1 => code(),
|
||||
other => code(other),
|
||||
}
|
||||
}
|
||||
",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue