Skip to content

Commit 3a5e13a

Browse files
committed
Auto merge of #143472 - dianne:deref-pat-column-check, r=Nadrieril
`rustc_pattern_analysis`: always check that deref patterns don't match on the same place as normal constructors In rust-lang/rust#140106, deref pattern validation was tied to the `deref_patterns` feature to temporarily avoid affecting perf. However: - As of rust-lang/rust#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`
2 parents d0188bd + 127a4ef commit 3a5e13a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ impl PatCx for MatchCheckCtx<'_> {
489489
fn complexity_exceeded(&self) -> Result<(), Self::Error> {
490490
Err(())
491491
}
492+
493+
fn report_mixed_deref_pat_ctors(
494+
&self,
495+
_deref_pat: &DeconstructedPat<'_>,
496+
_normal_pat: &DeconstructedPat<'_>,
497+
) {
498+
// FIXME(deref_patterns): This could report an error comparable to the one in rustc.
499+
}
492500
}
493501

494502
impl fmt::Debug for MatchCheckCtx<'_> {

0 commit comments

Comments
 (0)