Skip to content

rustc_pattern_analysis: always check that deref patterns don't match on the same place as normal constructors #143472

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Jul 5, 2025

In #140106, deref pattern validation was tied to the deref_patterns feature to temporarily avoid affecting perf. However:

  • As of remove special-casing of boxes from match exhaustiveness/usefulness analysis #143414, box patterns are represented as deref patterns in rustc_pattern_analysis. Since they can be used by enabling box_patterns instead of deref_patterns, it was possible for them to skip validation, resulting in an ICE. This fixes that and adds a regression test.
  • External tooling (e.g. rust-analyzer) will also need to validate matches containing deref patterns, which was not possible. This fixes that by making compute_match_usefulness validate deref patterns by default.

In order to avoid doing an extra pass for anything with patterns, the second commit makes RustcPatCtxt keep track of whether it encounters a deref pattern, so that it only does the check if so. This is purely for performance. If the perf impact of the first commit is negligible and the complexity cost introduced by the second commit is significant, it may be worth dropping the latter.

r? @Nadrieril

@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2025

Nadrieril is currently at their maximum review capacity.
They may take a while to respond.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2025

Some changes occurred in exhaustiveness checking

cc @Nadrieril

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in match checking

cc @Nadrieril

@rust-log-analyzer

This comment has been minimized.

@Nadrieril
Copy link
Member

Nadrieril commented Jul 5, 2025

Do you want to try keeping just the first commit so we can do a perf run? Mostly out of curiosity, second commit looks good to me.

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants