mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Remove PatKind::Constant
This commit is contained in:
parent
283243ac5a
commit
9952e4d4c8
@ -784,7 +784,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
|
|||||||
} else if range.is_singleton() {
|
} else if range.is_singleton() {
|
||||||
let lo = cx.hoist_pat_range_bdy(range.lo, ty);
|
let lo = cx.hoist_pat_range_bdy(range.lo, ty);
|
||||||
let value = lo.as_finite().unwrap();
|
let value = lo.as_finite().unwrap();
|
||||||
PatKind::Constant { value }
|
PatKind::Print(value.to_string())
|
||||||
} else {
|
} else {
|
||||||
// We convert to an inclusive range for diagnostics.
|
// We convert to an inclusive range for diagnostics.
|
||||||
let mut end = rustc_hir::RangeEnd::Included;
|
let mut end = rustc_hir::RangeEnd::Included;
|
||||||
@ -827,7 +827,8 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
|
|||||||
let cx = self;
|
let cx = self;
|
||||||
let hoist = |p| Box::new(cx.hoist_witness_pat(p));
|
let hoist = |p| Box::new(cx.hoist_witness_pat(p));
|
||||||
let kind = match pat.ctor() {
|
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()),
|
IntRange(range) => return self.hoist_pat_range(range, *pat.ty()),
|
||||||
Struct if pat.ty().is_box() => {
|
Struct if pat.ty().is_box() => {
|
||||||
// Outside of the `alloc` crate, the only way to create a struct pattern
|
// 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 }
|
PatKind::Slice { prefix, has_dot_dot, suffix }
|
||||||
}
|
}
|
||||||
&Str(value) => PatKind::Constant { value },
|
|
||||||
Never if self.tcx.features().never_patterns => PatKind::Never,
|
Never if self.tcx.features().never_patterns => PatKind::Never,
|
||||||
Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => {
|
Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => {
|
||||||
PatKind::Print("_".to_string())
|
PatKind::Print("_".to_string())
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use rustc_middle::bug;
|
||||||
use rustc_middle::thir::PatRange;
|
use rustc_middle::thir::PatRange;
|
||||||
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
|
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
|
||||||
use rustc_middle::{bug, mir};
|
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||||
|
|
||||||
@ -33,10 +33,6 @@ pub(crate) struct Pat<'tcx> {
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) enum PatKind<'tcx> {
|
pub(crate) enum PatKind<'tcx> {
|
||||||
Constant {
|
|
||||||
value: mir::Const<'tcx>,
|
|
||||||
},
|
|
||||||
|
|
||||||
Range(Box<PatRange<'tcx>>),
|
Range(Box<PatRange<'tcx>>),
|
||||||
|
|
||||||
Slice {
|
Slice {
|
||||||
@ -56,7 +52,6 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
PatKind::Never => write!(f, "!"),
|
PatKind::Never => write!(f, "!"),
|
||||||
PatKind::Constant { value } => write!(f, "{value}"),
|
|
||||||
PatKind::Range(ref range) => write!(f, "{range}"),
|
PatKind::Range(ref range) => write!(f, "{range}"),
|
||||||
PatKind::Slice { ref prefix, has_dot_dot, ref suffix } => {
|
PatKind::Slice { ref prefix, has_dot_dot, ref suffix } => {
|
||||||
write_slice_like(f, prefix, has_dot_dot, suffix)
|
write_slice_like(f, prefix, has_dot_dot, suffix)
|
||||||
|
Loading…
Reference in New Issue
Block a user