Exhaustively handle expressions in patterns
This commit is contained in:
@@ -1519,6 +1519,26 @@ impl fmt::Debug for DotDotPos {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct PatExpr<'hir> {
|
||||
pub hir_id: HirId,
|
||||
pub span: Span,
|
||||
pub kind: PatExprKind<'hir>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub enum PatExprKind<'hir> {
|
||||
Lit {
|
||||
lit: &'hir Lit,
|
||||
// FIXME: move this into `Lit` and handle negated literal expressions
|
||||
// once instead of matching on unop neg expressions everywhere.
|
||||
negated: bool,
|
||||
},
|
||||
ConstBlock(ConstBlock),
|
||||
/// A path pattern for a unit struct/variant or a (maybe-associated) constant.
|
||||
Path(QPath<'hir>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub enum PatKind<'hir> {
|
||||
/// Represents a wildcard pattern (i.e., `_`).
|
||||
@@ -1564,13 +1584,13 @@ pub enum PatKind<'hir> {
|
||||
Ref(&'hir Pat<'hir>, Mutability),
|
||||
|
||||
/// A literal.
|
||||
Lit(&'hir Expr<'hir>),
|
||||
Lit(&'hir PatExpr<'hir>),
|
||||
|
||||
/// A guard pattern (e.g., `x if guard(x)`).
|
||||
Guard(&'hir Pat<'hir>, &'hir Expr<'hir>),
|
||||
|
||||
/// A range pattern (e.g., `1..=2` or `1..2`).
|
||||
Range(Option<&'hir Expr<'hir>>, Option<&'hir Expr<'hir>>, RangeEnd),
|
||||
Range(Option<&'hir PatExpr<'hir>>, Option<&'hir PatExpr<'hir>>, RangeEnd),
|
||||
|
||||
/// A slice pattern, `[before_0, ..., before_n, (slice, after_0, ..., after_n)?]`.
|
||||
///
|
||||
@@ -4144,6 +4164,10 @@ pub enum Node<'hir> {
|
||||
OpaqueTy(&'hir OpaqueTy<'hir>),
|
||||
Pat(&'hir Pat<'hir>),
|
||||
PatField(&'hir PatField<'hir>),
|
||||
/// Needed as its own node with its own HirId for tracking
|
||||
/// the unadjusted type of literals within patterns
|
||||
/// (e.g. byte str literals not being of slice type).
|
||||
PatExpr(&'hir PatExpr<'hir>),
|
||||
Arm(&'hir Arm<'hir>),
|
||||
Block(&'hir Block<'hir>),
|
||||
LetStmt(&'hir LetStmt<'hir>),
|
||||
@@ -4200,6 +4224,7 @@ impl<'hir> Node<'hir> {
|
||||
| Node::Block(..)
|
||||
| Node::Ctor(..)
|
||||
| Node::Pat(..)
|
||||
| Node::PatExpr(..)
|
||||
| Node::Arm(..)
|
||||
| Node::LetStmt(..)
|
||||
| Node::Crate(..)
|
||||
|
||||
Reference in New Issue
Block a user