fix: Improve label on add_missing_match_arms assist#21920
fix: Improve label on add_missing_match_arms assist#21920ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
Conversation
| return None; | ||
| } | ||
|
|
||
| let first = missing_pats.next(); |
There was a problem hiding this comment.
I prefer to have missing_pats: Vec<_> by collecting beforehand.
There was a problem hiding this comment.
Funny, that's what my first attempt did! The other nice thing about collecting is that I can show the exact number of missing arms in the label.
My concern was that most assists are deliberately lazy, hence me trying to just consume a bit of the iterator. What do you think?
There was a problem hiding this comment.
This allocates anyway, so it doesn't really matter IMO.
| let first = missing_pats.next(); | ||
| let label = match (&first, missing_pats.peek()) { | ||
| (Some((pat, false)), None) => format!("Add missing match arm `{pat}`"), | ||
| (Some((_, true)), None) => "Add missing match arm `_`".to_owned(), |
There was a problem hiding this comment.
I think this arm will never hit. Also we may filter hidden patterns (that we do after) before this.
"Fill match arms" is an extremely helpful assist, but the name is pretty opaque to new users (at least it was to me). We actually renamed the file in rust-lang#10299 from `fill_match_arms.rs` to `add_missing_match_arms.rs` but the label hasn't changed from its original text in rust-lang#733. Instead, show "Add N missing match arms" if there are multiple missing match arms, and show "Add missing match arm `Foo::Bar`" when there's only a single missing match arm. Partially generated by Claude Opus.
2c9d993 to
fd92d9d
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Rebased, changed to use .collect() and show the exact number of missing arms, added test for the catch-all case. |
"Fill match arms" is an extremely helpful assist, but the name is pretty opaque to new users (at least it was to me). We actually renamed the file in #10299 from
fill_match_arms.rstoadd_missing_match_arms.rsbut the label hasn't changed from its original text in #733.Instead, show "Add missing match arms" if there are multiple missing match arms, and show "Add missing match arm
Foo::Bar" when there's only a single missing match arm.Partially generated by Claude Opus.