From b392a732d31f9be028e4b2dcf4752c5e4c7a9880 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 1 Apr 2020 20:27:47 +0200 Subject: Add inference for literal and range patterns --- crates/ra_hir_ty/src/infer/pat.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index baed6225b..86acd27f8 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -11,7 +11,7 @@ use hir_def::{ use hir_expand::name::Name; use test_utils::tested_by; -use super::{BindingMode, InferenceContext}; +use super::{BindingMode, Expectation, InferenceContext}; use crate::{utils::variant_data, Substs, Ty, TypeCtor}; impl<'a> InferenceContext<'a> { @@ -198,7 +198,14 @@ impl<'a> InferenceContext<'a> { Ty::apply_one(container_ty, elem_ty) } - _ => Ty::Unknown, + Pat::Wild => expected.clone(), + Pat::Range { start, end } => { + let start_ty = self.infer_expr(*start, &Expectation::has_type(expected.clone())); + let end_ty = self.infer_expr(*end, &Expectation::has_type(start_ty)); + end_ty + } + Pat::Lit(expr) => self.infer_expr(*expr, &Expectation::has_type(expected.clone())), + Pat::Missing => Ty::Unknown, }; // use a new type variable if we got Ty::Unknown here let ty = self.insert_type_vars_shallow(ty); -- cgit v1.2.3