or-patterns: HAIR: Arm.patterns: Vec<Pattern<'_>>
-> .pattern: Pattern<'_>
.
This commit is contained in:
parent
549756bef8
commit
56b055a6ab
@ -142,7 +142,7 @@ pub fn match_expr(
|
|||||||
// Step 2. Create the otherwise and prebinding blocks.
|
// Step 2. Create the otherwise and prebinding blocks.
|
||||||
|
|
||||||
// create binding start block for link them by false edges
|
// create binding start block for link them by false edges
|
||||||
let candidate_count = arms.iter().map(|c| c.patterns.len()).sum::<usize>();
|
let candidate_count = arms.iter().map(|c| c.top_pats_hack().len()).sum::<usize>();
|
||||||
let pre_binding_blocks: Vec<_> = (0..candidate_count)
|
let pre_binding_blocks: Vec<_> = (0..candidate_count)
|
||||||
.map(|_| self.cfg.start_new_block())
|
.map(|_| self.cfg.start_new_block())
|
||||||
.collect();
|
.collect();
|
||||||
@ -159,7 +159,7 @@ pub fn match_expr(
|
|||||||
.map(|arm| {
|
.map(|arm| {
|
||||||
let arm_has_guard = arm.guard.is_some();
|
let arm_has_guard = arm.guard.is_some();
|
||||||
match_has_guard |= arm_has_guard;
|
match_has_guard |= arm_has_guard;
|
||||||
let arm_candidates: Vec<_> = arm.patterns
|
let arm_candidates: Vec<_> = arm.top_pats_hack()
|
||||||
.iter()
|
.iter()
|
||||||
.zip(candidate_pre_binding_blocks.by_ref())
|
.zip(candidate_pre_binding_blocks.by_ref())
|
||||||
.map(
|
.map(
|
||||||
@ -238,7 +238,7 @@ pub fn match_expr(
|
|||||||
let scope = this.declare_bindings(
|
let scope = this.declare_bindings(
|
||||||
None,
|
None,
|
||||||
arm.span,
|
arm.span,
|
||||||
&arm.patterns[0],
|
&arm.top_pats_hack()[0],
|
||||||
ArmHasGuard(arm.guard.is_some()),
|
ArmHasGuard(arm.guard.is_some()),
|
||||||
Some((Some(&scrutinee_place), scrutinee_span)),
|
Some((Some(&scrutinee_place), scrutinee_span)),
|
||||||
);
|
);
|
||||||
|
@ -860,9 +860,9 @@ fn to_borrow_kind(&self) -> BorrowKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_arm<'a, 'tcx>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm<'tcx> {
|
fn convert_arm<'tcx>(cx: &mut Cx<'_, 'tcx>, arm: &'tcx hir::Arm) -> Arm<'tcx> {
|
||||||
Arm {
|
Arm {
|
||||||
patterns: arm.top_pats_hack().iter().map(|p| cx.pattern_from_hir(p)).collect(),
|
pattern: cx.pattern_from_hir(&arm.pat),
|
||||||
guard: match arm.guard {
|
guard: match arm.guard {
|
||||||
Some(hir::Guard::If(ref e)) => Some(Guard::If(e.to_ref())),
|
Some(hir::Guard::If(ref e)) => Some(Guard::If(e.to_ref())),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -293,7 +293,7 @@ pub struct FruInfo<'tcx> {
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Arm<'tcx> {
|
pub struct Arm<'tcx> {
|
||||||
pub patterns: Vec<Pattern<'tcx>>,
|
pub pattern: Pattern<'tcx>,
|
||||||
pub guard: Option<Guard<'tcx>>,
|
pub guard: Option<Guard<'tcx>>,
|
||||||
pub body: ExprRef<'tcx>,
|
pub body: ExprRef<'tcx>,
|
||||||
pub lint_level: LintLevel,
|
pub lint_level: LintLevel,
|
||||||
@ -301,6 +301,17 @@ pub struct Arm<'tcx> {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Arm<'tcx> {
|
||||||
|
// HACK(or_patterns; Centril | dlrobertson): Remove this and
|
||||||
|
// correctly handle each case in which this method is used.
|
||||||
|
pub fn top_pats_hack(&self) -> &[Pattern<'tcx>] {
|
||||||
|
match &*self.pattern.kind {
|
||||||
|
PatternKind::Or { pats } => pats,
|
||||||
|
_ => std::slice::from_ref(&self.pattern),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Guard<'tcx> {
|
pub enum Guard<'tcx> {
|
||||||
If(ExprRef<'tcx>),
|
If(ExprRef<'tcx>),
|
||||||
|
Loading…
Reference in New Issue
Block a user