rustc_middle/ty/
pattern.rs1use std::fmt;
2
3use rustc_data_structures::intern::Interned;
4use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
5
6use crate::ty;
7
8#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
9#[rustc_pass_by_value]
10pub struct Pattern<'tcx>(pub Interned<'tcx, PatternKind<'tcx>>);
11
12impl<'tcx> std::ops::Deref for Pattern<'tcx> {
13 type Target = PatternKind<'tcx>;
14
15 fn deref(&self) -> &Self::Target {
16 &*self.0
17 }
18}
19
20impl<'tcx> fmt::Debug for Pattern<'tcx> {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 write!(f, "{:?}", **self)
23 }
24}
25
26impl<'tcx> fmt::Debug for PatternKind<'tcx> {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match *self {
29 PatternKind::Range { start, end, include_end } => {
30 if let Some(start) = start {
31 write!(f, "{start}")?;
32 }
33 write!(f, "..")?;
34 if include_end {
35 write!(f, "=")?;
36 }
37 if let Some(end) = end {
38 write!(f, "{end}")?;
39 }
40 Ok(())
41 }
42 }
43 }
44}
45
46#[derive(Clone, PartialEq, Eq, Hash)]
47#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
48pub enum PatternKind<'tcx> {
49 Range { start: Option<ty::Const<'tcx>>, end: Option<ty::Const<'tcx>>, include_end: bool },
50}