-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Pattern Migration 2024: suggest nicer patterns #136496
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Some changes occurred in match checking cc @Nadrieril |
r? @Nadrieril Hmm, would it be possible to first implement a very basic fix which is: if we find |
That should be possible, but it would require some logic. Edit: Thought about this some more. I think it doesn't even need to be based on 203d310. I duplicated the default binding mode tracking logic in that since I didn't want to maintain a hashmap of default binding mode changes in HIR typeck on the happy path. But that's irrelevant here; this doesn't need those spans. I'll open a separate PR. Edit 2: It ended up being more convenient to base that off of #136475 anyway. Here's the new PR: #136577. |
☔ The latest upstream changes (presumably #136549) made this pull request unmergeable. Please resolve the merge conflicts. |
…fication, r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on rust-lang#136475. Only the last commit is new. This is a simpler, more restrictive alternative to rust-lang#136496, meant to partially address rust-lang#136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: rust-lang#131414 `@rustbot` label A-diagnostics A-patterns A-edition-2024 r? `@Nadrieril`
…fication, r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on rust-lang#136475. Only the last commit is new. This is a simpler, more restrictive alternative to rust-lang#136496, meant to partially address rust-lang#136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: rust-lang#131414 ``@rustbot`` label A-diagnostics A-patterns A-edition-2024 r? ``@Nadrieril``
Rollup merge of rust-lang#136577 - dianne:simple-pat-migration-simplification, r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on rust-lang#136475. Only the last commit is new. This is a simpler, more restrictive alternative to rust-lang#136496, meant to partially address rust-lang#136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: rust-lang#131414 ``@rustbot`` label A-diagnostics A-patterns A-edition-2024 r? ``@Nadrieril``
…vements The following commits are the possible future improvements.
This will let us propagate changes to the default binding mode when suggesting adding `&` patterns.
This lets us revise the suggestion on-the-fly as we discover which reference patterns and binding modifiers are necessary vs. which may be omitted.
A slight refactor: we'll always want to pass the mutability in to `push_deref` to determine the default binding mode when a pattern is removed, so this eliminates the redundancy of having both that and the user's dbm as separate arguments.
5c83ca2
to
ec5c713
Compare
I've rebased on top of #136817 (which puts pattern migration in its own file) and pulled the commit structure apart a bit. Rebasing onto the other diagnostic improvements has made this a bit bigger in total than it was before, but hopefully each of the refactors should at least be a bit more digestible than they were initially. |
This is based on #136817. The new commits start with removing a comment on the tests. The goal of the refactors in the following commits is to eventually [produce suggestions which remove reference patterns], fixing #136047 in a more thorough way.
Here's a simplified version of how it works, for reference (it's not actually split into discrete phases, but these are the conceptual steps):
&ref x
tox
when it's convenient. This isn't quite complete; full simplification would require potentially rewriting&ref x @ ...
tox @ &...
, which would add a bit of complexity, though I can implement that too if desired.Unfortunately, it ended up being more code than I'd hoped, so I understand if it's unappealing from a maintenance perspective. If nothing else, finalizing match ergonomics 2024 should open up significant simplifications, and I'm happy to help maintain it until then. There's a chance some common bookkeeping could be shared between other diagnostics/suggestions too; I have a couple in mind, but I haven't checked whether it'd be less complexity overall.
Relevant tracking issue: #131414
This doesn't aim to provide viable suggestions under the feature gates
ref_pat_eat_one_layer_2024
orref_pat_eat_one_layer_2024_structural
; some of the suggestions in the test output for those features are wrong and/or not as pretty as they could be. I've included FIXME comments providing more detail. Producing suggestions targeting the match ergonomics implemented by those features would actually be significantly simpler than what this PR does, but since it would require different1 logic, I'm inclined to save that for later. cc @Nadrieril, do any other feature gates come to mind that might require tweaks to this?@rustbot label A-diagnostics A-patterns A-edition-2024
Footnotes
It would only require a small tweak to correct the suggestions in the
ref_pat_eat_one_layer_2024
andref_pat_eat_one_layer_2024_structural
tests. However, a different approach to the one in this PR would let us use simpler logic to give more local suggestions. I figure if we're adding logic specific to new match ergonomics, we may as well not (slightly) complicate this version of it further when we could be doing something better. ↩