@@ -328,7 +328,14 @@ fn pick_pattern_and_expr_order(
328328 ( pat, pat2) => match ( binds_name ( sema, & pat) , binds_name ( sema, & pat2) ) {
329329 ( true , true ) => return None ,
330330 ( true , false ) => ( pat, guard, expr, expr2) ,
331- ( false , true ) => ( pat2, guard2, expr2, expr) ,
331+ ( false , true ) => {
332+ // This pattern triggers an invalid transformation.
333+ // See issues #11373, #19443
334+ if let ast:: Pat :: IdentPat ( _) = pat2 {
335+ return None ;
336+ }
337+ ( pat2, guard2, expr2, expr)
338+ }
332339 _ if is_sad_pat ( sema, & pat) => ( pat2, guard2, expr2, expr) ,
333340 ( false , false ) => ( pat, guard, expr, expr2) ,
334341 } ,
@@ -1892,4 +1899,19 @@ fn main() {
18921899"# ,
18931900 )
18941901 }
1902+
1903+ #[ test]
1904+ fn test_replace_match_with_if_let_not_applicable_pat2_is_ident_pat ( ) {
1905+ check_assist_not_applicable (
1906+ replace_match_with_if_let,
1907+ r"
1908+ fn test(a: i32) {
1909+ match$0 a {
1910+ 1 => code(),
1911+ other => code(other),
1912+ }
1913+ }
1914+ " ,
1915+ )
1916+ }
18951917}
0 commit comments