Remove PatKind::Constant

This commit is contained in:
Zalathar 2024-08-03 20:55:50 +10:00
parent 283243ac5a
commit 9952e4d4c8
2 changed files with 4 additions and 9 deletions

View File

@ -784,7 +784,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
} else if range.is_singleton() {
let lo = cx.hoist_pat_range_bdy(range.lo, ty);
let value = lo.as_finite().unwrap();
PatKind::Constant { value }
PatKind::Print(value.to_string())
} else {
// We convert to an inclusive range for diagnostics.
let mut end = rustc_hir::RangeEnd::Included;
@ -827,7 +827,8 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
let cx = self;
let hoist = |p| Box::new(cx.hoist_witness_pat(p));
let kind = match pat.ctor() {
Bool(b) => PatKind::Constant { value: mir::Const::from_bool(cx.tcx, *b) },
Bool(b) => PatKind::Print(b.to_string()),
Str(s) => PatKind::Print(s.to_string()),
IntRange(range) => return self.hoist_pat_range(range, *pat.ty()),
Struct if pat.ty().is_box() => {
// Outside of the `alloc` crate, the only way to create a struct pattern
@ -901,7 +902,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
PatKind::Slice { prefix, has_dot_dot, suffix }
}
&Str(value) => PatKind::Constant { value },
Never if self.tcx.features().never_patterns => PatKind::Never,
Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => {
PatKind::Print("_".to_string())

View File

@ -11,9 +11,9 @@
use std::fmt;
use rustc_middle::bug;
use rustc_middle::thir::PatRange;
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
use rustc_middle::{bug, mir};
use rustc_span::sym;
use rustc_target::abi::{FieldIdx, VariantIdx};
@ -33,10 +33,6 @@ pub(crate) struct Pat<'tcx> {
#[derive(Clone, Debug)]
pub(crate) enum PatKind<'tcx> {
Constant {
value: mir::Const<'tcx>,
},
Range(Box<PatRange<'tcx>>),
Slice {
@ -56,7 +52,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::Constant { value } => write!(f, "{value}"),
PatKind::Range(ref range) => write!(f, "{range}"),
PatKind::Slice { ref prefix, has_dot_dot, ref suffix } => {
write_slice_like(f, prefix, has_dot_dot, suffix)