Skip to content

Commit 56b055a

Browse files
committed
or-patterns: HAIR: Arm.patterns: Vec<Pattern<'_>> -> .pattern: Pattern<'_>.
1 parent 549756b commit 56b055a

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/librustc_mir/build/matches/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
142142
// Step 2. Create the otherwise and prebinding blocks.
143143

144144
// create binding start block for link them by false edges
145-
let candidate_count = arms.iter().map(|c| c.patterns.len()).sum::<usize>();
145+
let candidate_count = arms.iter().map(|c| c.top_pats_hack().len()).sum::<usize>();
146146
let pre_binding_blocks: Vec<_> = (0..candidate_count)
147147
.map(|_| self.cfg.start_new_block())
148148
.collect();
@@ -159,7 +159,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
159159
.map(|arm| {
160160
let arm_has_guard = arm.guard.is_some();
161161
match_has_guard |= arm_has_guard;
162-
let arm_candidates: Vec<_> = arm.patterns
162+
let arm_candidates: Vec<_> = arm.top_pats_hack()
163163
.iter()
164164
.zip(candidate_pre_binding_blocks.by_ref())
165165
.map(
@@ -238,7 +238,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
238238
let scope = this.declare_bindings(
239239
None,
240240
arm.span,
241-
&arm.patterns[0],
241+
&arm.top_pats_hack()[0],
242242
ArmHasGuard(arm.guard.is_some()),
243243
Some((Some(&scrutinee_place), scrutinee_span)),
244244
);

src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,9 @@ impl ToBorrowKind for hir::Mutability {
860860
}
861861
}
862862

863-
fn convert_arm<'a, 'tcx>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm<'tcx> {
863+
fn convert_arm<'tcx>(cx: &mut Cx<'_, 'tcx>, arm: &'tcx hir::Arm) -> Arm<'tcx> {
864864
Arm {
865-
patterns: arm.top_pats_hack().iter().map(|p| cx.pattern_from_hir(p)).collect(),
865+
pattern: cx.pattern_from_hir(&arm.pat),
866866
guard: match arm.guard {
867867
Some(hir::Guard::If(ref e)) => Some(Guard::If(e.to_ref())),
868868
_ => None,

src/librustc_mir/hair/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,25 @@ pub struct FruInfo<'tcx> {
293293

294294
#[derive(Clone, Debug)]
295295
pub struct Arm<'tcx> {
296-
pub patterns: Vec<Pattern<'tcx>>,
296+
pub pattern: Pattern<'tcx>,
297297
pub guard: Option<Guard<'tcx>>,
298298
pub body: ExprRef<'tcx>,
299299
pub lint_level: LintLevel,
300300
pub scope: region::Scope,
301301
pub span: Span,
302302
}
303303

304+
impl Arm<'tcx> {
305+
// HACK(or_patterns; Centril | dlrobertson): Remove this and
306+
// correctly handle each case in which this method is used.
307+
pub fn top_pats_hack(&self) -> &[Pattern<'tcx>] {
308+
match &*self.pattern.kind {
309+
PatternKind::Or { pats } => pats,
310+
_ => std::slice::from_ref(&self.pattern),
311+
}
312+
}
313+
}
314+
304315
#[derive(Clone, Debug)]
305316
pub enum Guard<'tcx> {
306317
If(ExprRef<'tcx>),

0 commit comments

Comments
 (0)