|
| 1 | +use std::cell::Cell; |
1 | 2 | use std::fmt; |
2 | 3 | use std::iter::once; |
3 | 4 |
|
@@ -99,6 +100,16 @@ pub struct RustcPatCtxt<'p, 'tcx: 'p> { |
99 | 100 | /// Whether the data at the scrutinee is known to be valid. This is false if the scrutinee comes |
100 | 101 | /// from a union field, a pointer deref, or a reference deref (pending opsem decisions). |
101 | 102 | pub known_valid_scrutinee: bool, |
| 103 | + pub internal_state: RustcPatCtxtState, |
| 104 | +} |
| 105 | + |
| 106 | +/// Private fields of [`RustcPatCtxt`], separated out to permit record initialization syntax. |
| 107 | +#[derive(Clone, Default)] |
| 108 | +pub struct RustcPatCtxtState { |
| 109 | + /// Has a deref pattern been lowered? This is initialized to `false` and is updated by |
| 110 | + /// [`RustcPatCtxt::lower_pat`] in order to avoid performing deref-pattern-specific validation |
| 111 | + /// for everything containing patterns. |
| 112 | + has_lowered_deref_pat: Cell<bool>, |
102 | 113 | } |
103 | 114 |
|
104 | 115 | impl<'p, 'tcx: 'p> fmt::Debug for RustcPatCtxt<'p, 'tcx> { |
@@ -474,6 +485,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
474 | 485 | fields = vec![self.lower_pat(subpattern).at_index(0)]; |
475 | 486 | arity = 1; |
476 | 487 | ctor = DerefPattern(cx.reveal_opaque_ty(subpattern.ty)); |
| 488 | + self.internal_state.has_lowered_deref_pat.set(true); |
477 | 489 | } |
478 | 490 | PatKind::Leaf { subpatterns } | PatKind::Variant { subpatterns, .. } => { |
479 | 491 | match ty.kind() { |
@@ -1028,6 +1040,10 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { |
1028 | 1040 | } |
1029 | 1041 | } |
1030 | 1042 |
|
| 1043 | + fn match_may_contain_deref_pats(&self) -> bool { |
| 1044 | + self.internal_state.has_lowered_deref_pat.get() |
| 1045 | + } |
| 1046 | + |
1031 | 1047 | fn report_mixed_deref_pat_ctors( |
1032 | 1048 | &self, |
1033 | 1049 | deref_pat: &crate::pat::DeconstructedPat<Self>, |
|
0 commit comments