Skip to content

Commit b2f903c

Browse files
committed
or-patterns: hir::Arm::pats -> ::pat + Arm::top_pats_hack.
1 parent 146cb8e commit b2f903c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/librustc/hir/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,21 +1259,32 @@ pub struct Local {
12591259
}
12601260

12611261
/// Represents a single arm of a `match` expression, e.g.
1262-
/// `<pats> (if <guard>) => <body>`.
1262+
/// `<pat> (if <guard>) => <body>`.
12631263
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
12641264
pub struct Arm {
12651265
#[stable_hasher(ignore)]
12661266
pub hir_id: HirId,
12671267
pub span: Span,
12681268
pub attrs: HirVec<Attribute>,
1269-
/// Multiple patterns can be combined with `|`
1270-
pub pats: HirVec<P<Pat>>,
1269+
/// If this pattern and the optional guard matches, then `body` is evaluated.
1270+
pub pat: P<Pat>,
12711271
/// Optional guard clause.
12721272
pub guard: Option<Guard>,
12731273
/// The expression the arm evaluates to if this arm matches.
12741274
pub body: P<Expr>,
12751275
}
12761276

1277+
impl Arm {
1278+
// HACK(or_patterns; Centril | dlrobertson): Remove this and
1279+
// correctly handle each case in which this method is used.
1280+
pub fn top_pats_hack(&self) -> &[P<Pat>] {
1281+
match &self.pat.node {
1282+
PatKind::Or(pats) => pats,
1283+
_ => std::slice::from_ref(&self.pat),
1284+
}
1285+
}
1286+
}
1287+
12771288
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
12781289
pub enum Guard {
12791290
If(P<Expr>),

0 commit comments

Comments
 (0)