diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index 91650c7531a..97d4a94756d 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -865,7 +865,11 @@ fn hoist_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> print::Pat<'tcx> { .unwrap(); PatKind::Print(s) } - Ref => PatKind::Deref { subpattern: hoist(&pat.fields[0]) }, + Ref => { + let mut s = String::new(); + print::write_ref_like(&mut s, pat.ty().inner(), &hoist(&pat.fields[0])).unwrap(); + PatKind::Print(s) + } Slice(slice) => { let (prefix_len, has_dot_dot) = match slice.kind { SliceKind::FixedLen(len) => (len, false), diff --git a/compiler/rustc_pattern_analysis/src/rustc/print.rs b/compiler/rustc_pattern_analysis/src/rustc/print.rs index d03c68442cd..f147d62ed9b 100644 --- a/compiler/rustc_pattern_analysis/src/rustc/print.rs +++ b/compiler/rustc_pattern_analysis/src/rustc/print.rs @@ -26,16 +26,13 @@ pub(crate) struct FieldPat<'tcx> { #[derive(Clone, Debug)] pub(crate) struct Pat<'tcx> { + #[allow(dead_code)] pub(crate) ty: Ty<'tcx>, pub(crate) kind: PatKind<'tcx>, } #[derive(Clone, Debug)] pub(crate) enum PatKind<'tcx> { - Deref { - subpattern: Box>, - }, - Constant { value: mir::Const<'tcx>, }, @@ -59,7 +56,6 @@ impl<'tcx> fmt::Display for Pat<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.kind { PatKind::Never => write!(f, "!"), - PatKind::Deref { ref subpattern } => write_ref_like(f, self.ty, subpattern), PatKind::Constant { value } => write!(f, "{value}"), PatKind::Range(ref range) => write!(f, "{range}"), PatKind::Slice { ref prefix, has_dot_dot, ref suffix } => { @@ -172,7 +168,7 @@ pub(crate) fn write_struct_like<'tcx>( Ok(()) } -fn write_ref_like<'tcx>( +pub(crate) fn write_ref_like<'tcx>( f: &mut impl fmt::Write, ty: Ty<'tcx>, subpattern: &Pat<'tcx>,