From 4992d2bf79e9da6db759eb8e1715f90f31ec7eb9 Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 29 Nov 2019 03:10:16 +0800 Subject: Infer range types --- crates/ra_hir_ty/src/infer/expr.rs | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'crates/ra_hir_ty/src/infer') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 2f9ca4bbb..a00aa426a 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -415,6 +415,47 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } _ => Ty::Unknown, }, + Expr::RangeFull => match self.resolve_range_full() { + Some(adt) => Ty::simple(TypeCtor::Adt(adt)), + None => Ty::Unknown, + }, + Expr::Range { lhs, rhs } => { + let lhs_ty = self.infer_expr(*lhs, &Expectation::none()); + let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(lhs_ty)); + match self.resolve_range() { + Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), rhs_ty), + None => Ty::Unknown, + } + } + Expr::RangeInclusive { lhs, rhs } => { + let lhs_ty = self.infer_expr(*lhs, &Expectation::none()); + let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(lhs_ty)); + match self.resolve_range_inclusive() { + Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), rhs_ty), + None => Ty::Unknown, + } + } + Expr::RangeFrom { lhs } => { + let ty = self.infer_expr(*lhs, &Expectation::none()); + match self.resolve_range_from() { + Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), + None => Ty::Unknown, + } + } + Expr::RangeTo { rhs } => { + let ty = self.infer_expr(*rhs, &Expectation::none()); + match self.resolve_range_to() { + Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), + None => Ty::Unknown, + } + } + Expr::RangeToInclusive { rhs } => { + let ty = self.infer_expr(*rhs, &Expectation::none()); + match self.resolve_range_to_inclusive() { + Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), + None => Ty::Unknown, + } + } Expr::Index { base, index } => { let _base_ty = self.infer_expr(*base, &Expectation::none()); let _index_ty = self.infer_expr(*index, &Expectation::none()); -- cgit v1.2.3