diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-07 16:00:09 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-15 18:50:44 +0200 |
| commit | b2f903c066185d32bdfc02ff6a35f4e50c54728d (patch) | |
| tree | 75e31206184e0aeb3a6ff862d4a564e0d729574f | |
| parent | 146cb8eda667e5d76bebdef3acc61adaeaa025b0 (diff) | |
| download | rust-b2f903c066185d32bdfc02ff6a35f4e50c54728d.tar.gz rust-b2f903c066185d32bdfc02ff6a35f4e50c54728d.zip | |
or-patterns: `hir::Arm::pats` -> `::pat` + `Arm::top_pats_hack`.
| -rw-r--r-- | src/librustc/hir/mod.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 2c8590aa4e3..1b32979eda5 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1259,21 +1259,32 @@ pub struct Local { } /// Represents a single arm of a `match` expression, e.g. -/// `<pats> (if <guard>) => <body>`. +/// `<pat> (if <guard>) => <body>`. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Arm { #[stable_hasher(ignore)] pub hir_id: HirId, pub span: Span, pub attrs: HirVec<Attribute>, - /// Multiple patterns can be combined with `|` - pub pats: HirVec<P<Pat>>, + /// If this pattern and the optional guard matches, then `body` is evaluated. + pub pat: P<Pat>, /// Optional guard clause. pub guard: Option<Guard>, /// The expression the arm evaluates to if this arm matches. pub body: P<Expr>, } +impl Arm { + // HACK(or_patterns; Centril | dlrobertson): Remove this and + // correctly handle each case in which this method is used. + pub fn top_pats_hack(&self) -> &[P<Pat>] { + match &self.pat.node { + PatKind::Or(pats) => pats, + _ => std::slice::from_ref(&self.pat), + } + } +} + #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Guard { If(P<Expr>), |
