Skip to content

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

Merged
bors merged 2 commits into
rust-lang:masterfrom
dianne:deref-pat-column-check
Jul 9, 2025
Merged

rustc_pattern_analysis: always check that deref patterns don't match on the same place as normal constructors#143472
bors merged 2 commits into
rust-lang:masterfrom
dianne:deref-pat-column-check

Conversation

@dianne

@dianne dianne commented Jul 5, 2025

Copy link
Copy Markdown
Member

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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants