From 480561bf049390e07c40cb3e1bc77566e57c23b9 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Sun, 23 Nov 2025 16:20:24 +0800 Subject: [PATCH] Fix not fill guarded match arm for add_missing_match_arms Example --- ```rust enum Foo { A, B } fn main() { match Foo::A { Foo::A if false => todo!(), } } ``` **Before this PR** ```rust enum Foo { A, B } fn main() { match Foo::A { Foo::A if false => todo!(), Foo::B => todo!(), } } ``` **After this PR** ```rust enum Foo { A, B } fn main() { match Foo::A { Foo::A if false => todo!(), Foo::A => todo!(), Foo::B => todo!(), } } ``` --- crates/ide-assists/src/handlers/add_missing_match_arms.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/crates/ide-assists/src/handlers/add_missing_match_arms.rs index 7843ab9e8f25..3eeff2ad6074 100644 --- a/crates/ide-assists/src/handlers/add_missing_match_arms.rs +++ b/crates/ide-assists/src/handlers/add_missing_match_arms.rs @@ -67,9 +67,9 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) } .map(move |pat| (pat, has_guard)) }) - .map(|(pat, has_guard)| { + .filter_map(|(pat, has_guard)| { has_catch_all_arm |= !has_guard && matches!(pat, Pat::WildcardPat(_)); - pat + (!has_guard).then_some(pat) }) // Exclude top level wildcards so that they are expanded by this assist, retains status quo in #8129. .filter(|pat| !matches!(pat, Pat::WildcardPat(_))) @@ -998,7 +998,8 @@ fn main() { A::Ds(_value) => { let x = 1; } A::Es(B::Xs) => (), A::As => ${1:todo!()}, - A::Cs => ${2:todo!()},$0 + A::Bs => ${2:todo!()}, + A::Cs => ${3:todo!()},$0 } } "#,