From 8c8d0bb34f5495e0f260b5aaf3685ecb98406f32 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 9 Feb 2020 18:57:01 +0000 Subject: Add or- and parenthesized-patterns --- crates/ra_hir_ty/src/infer/expr.rs | 4 +--- crates/ra_hir_ty/src/infer/pat.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 3c9c02d03..186857b8b 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -168,9 +168,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let mut result_ty = self.table.new_maybe_never_type_var(); for arm in arms { - for &pat in &arm.pats { - let _pat_ty = self.infer_pat(pat, &input_ty, BindingMode::default()); - } + let _pat_ty = self.infer_pat(arm.pat, &input_ty, BindingMode::default()); if let Some(guard_expr) = arm.guard { self.infer_expr( guard_expr, diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index e7283f24c..a5dfdf6c4 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -82,6 +82,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let is_non_ref_pat = match &body[pat] { Pat::Tuple(..) + | Pat::Or(..) | Pat::TupleStruct { .. } | Pat::Record { .. } | Pat::Range { .. } @@ -126,6 +127,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Ty::apply(TypeCtor::Tuple { cardinality: args.len() as u16 }, Substs(inner_tys)) } + Pat::Or(ref pats) => { + if let Some((first_pat, rest)) = pats.split_first() { + let ty = self.infer_pat(*first_pat, expected, default_bm); + for pat in rest { + self.infer_pat(*pat, expected, default_bm); + } + ty + } else { + Ty::Unknown + } + } Pat::Ref { pat, mutability } => { let expectation = match expected.as_reference() { Some((inner_ty, exp_mut)) => { -- cgit v1.2.3