10000 feat: In "Fill match arms", allow users to prefer `Self` to the enum name when possible by ChayimFriedman2 · Pull Request #19939 · rust-lang/rust-analyzer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
10000

feat: In "Fill match arms", allow users to prefer Self to the enum name when possible #19939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

ChayimFriedman2
Copy link
Contributor
@ChayimFriedman2 ChayimFriedman2 commented Jun 6, 2025

But default to not to.

I chose to have a more generic config name because maybe other assists could also use the same approach.

Closes #19927.

…hen possible

But default to not to.

I chose to have a more generic config name because maybe other assists could also use the same approach.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 6, 2025
@Veykril Veykril added this pull request to the merge queue Jun 17, 2025
Merged via the queue into rust-lang:master with commit 8661c59 Jun 17, 2025
15 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the fill-arms-self branch June 17, 2025 09:39
@fmease
Copy link
Member
fmease commented Jun 23, 2025

Highly appreciated, thanks a lot! This is huge for me :)

Copy link
Member
@fmease fmease Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I should probably scour the issue tracker and open a proper issue for this if there's none for this already)

r-a still seems to perform syntactic equality checks instead of semantic ones when trying to determine which variants are already present. Originally reported in #6404 (comment) (from 2021).

For example, let's assume we're in a method of enum Ty { A, B }. Them, if we have match self { Ty::A => {} $0 } and rust-analyzer.assist.preferSelf, r-a doesn't realize that Type::A and Self::A are semantically equal and thus generates

match self {
    Ty::A => {}
    Self::A => {}
    Self::B => {}
}

This isn't specific to rust-analyzer.assist.preferSelf and an issue that has existed since at least 2021. For example if !preferSelf and type Alias = Ty;, this assist also doesn't consider Alias::A and Ty::A to be equal either leading to the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's completely unrelated to this PR which is concerned with the code r-a generates (and on a different assist even).

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Member
@fmease fmease Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean of course you know the impl contrary to me and I'm not saying that this PR regressed anything (and I should definitely open a separate issue for this),

I'm trying to refer to the fact that there seems to be some filtering going on to skip already covered variants (which is affected by preferSelf as added in this PR). E.g., with preferSelf, match … { Self::A => {} $0 } completes to match … { Self::A => {}, Self::B => {} } (correct) under add_missing_match_arms (the main assist modified in this PR and the only one I'm referring to, I hope?) but with !preferSelf it completes to match … { Self::A => {} Ty::A => {} Ty::B => {} } (incorrect).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we seem to have a proper issue for this already: #4650.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fill-match-arms should prefer to use Self when inside of an impl of an enum
5 participants
0