Parse a pattern with no arm
This commit is contained in:
parent
caa488b96e
commit
80bdcbf50a
36 changed files with 420 additions and 279 deletions
|
@ -658,6 +658,24 @@ impl Pat {
|
|||
pub fn is_rest(&self) -> bool {
|
||||
matches!(self.kind, PatKind::Rest)
|
||||
}
|
||||
|
||||
/// Could this be a never pattern? I.e. is it a never pattern modulo macro invocations that
|
||||
/// might return never patterns?
|
||||
pub fn could_be_never_pattern(&self) -> bool {
|
||||
let mut could_be_never_pattern = false;
|
||||
self.walk(&mut |pat| match &pat.kind {
|
||||
PatKind::Never | PatKind::MacCall(_) => {
|
||||
could_be_never_pattern = true;
|
||||
false
|
||||
}
|
||||
PatKind::Or(s) => {
|
||||
could_be_never_pattern = s.iter().all(|p| p.could_be_never_pattern());
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
});
|
||||
could_be_never_pattern
|
||||
}
|
||||
}
|
||||
|
||||
/// A single field in a struct pattern.
|
||||
|
@ -1080,8 +1098,8 @@ pub struct Arm {
|
|||
pub pat: P<Pat>,
|
||||
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`
|
||||
pub guard: Option<P<Expr>>,
|
||||
/// Match arm body.
|
||||
pub body: P<Expr>,
|
||||
/// Match arm body. Omitted if the pattern is a never pattern.
|
||||
pub body: Option<P<Expr>>,
|
||||
pub span: Span,
|
||||
pub id: NodeId,
|
||||
pub is_placeholder: bool,
|
||||
|
|
|
@ -453,7 +453,7 @@ pub fn noop_flat_map_arm<T: MutVisitor>(mut arm: Arm, vis: &mut T) -> SmallVec<[
|
|||
vis.visit_id(id);
|
||||
vis.visit_pat(pat);
|
||||
visit_opt(guard, |guard| vis.visit_expr(guard));
|
||||
vis.visit_expr(body);
|
||||
visit_opt(body, |body| vis.visit_expr(body));
|
||||
vis.visit_span(span);
|
||||
smallvec![arm]
|
||||
}
|
||||
|
|
|
@ -951,7 +951,7 @@ pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) {
|
|||
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
|
||||
visitor.visit_pat(&arm.pat);
|
||||
walk_list!(visitor, visit_expr, &arm.guard);
|
||||
visitor.visit_expr(&arm.body);
|
||||
walk_list!(visitor, visit_expr, &arm.body);
|
||||
walk_list!(visitor, visit_attribute, &arm.attrs);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue