aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/infer/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/infer/expr.rs')
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs76
1 files changed, 37 insertions, 39 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index a00aa426a..4014f4732 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -12,6 +12,7 @@ use hir_def::{
12 AdtId, ContainerId, Lookup, StructFieldId, 12 AdtId, ContainerId, Lookup, StructFieldId,
13}; 13};
14use hir_expand::name::{self, Name}; 14use hir_expand::name::{self, Name};
15use ra_syntax::ast::RangeOp;
15 16
16use crate::{ 17use crate::{
17 autoderef, db::HirDatabase, method_resolution, op, traits::InEnvironment, utils::variant_data, 18 autoderef, db::HirDatabase, method_resolution, op, traits::InEnvironment, utils::variant_data,
@@ -415,45 +416,42 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
415 } 416 }
416 _ => Ty::Unknown, 417 _ => Ty::Unknown,
417 }, 418 },
418 Expr::RangeFull => match self.resolve_range_full() { 419 Expr::Range { lhs, rhs, range_type } => {
419 Some(adt) => Ty::simple(TypeCtor::Adt(adt)), 420 let lhs_ty = lhs.map(|e| self.infer_expr(e, &Expectation::none()));
420 None => Ty::Unknown, 421 let rhs_expect = lhs_ty
421 }, 422 .as_ref()
422 Expr::Range { lhs, rhs } => { 423 .map_or_else(Expectation::none, |ty| Expectation::has_type(ty.clone()));
423 let lhs_ty = self.infer_expr(*lhs, &Expectation::none()); 424 let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect));
424 let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(lhs_ty)); 425 match (range_type, lhs_ty, rhs_ty) {
425 match self.resolve_range() { 426 (RangeOp::Exclusive, None, None) => match self.resolve_range_full() {
426 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), rhs_ty), 427 Some(adt) => Ty::simple(TypeCtor::Adt(adt)),
427 None => Ty::Unknown, 428 None => Ty::Unknown,
428 } 429 },
429 } 430 (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() {
430 Expr::RangeInclusive { lhs, rhs } => { 431 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty),
431 let lhs_ty = self.infer_expr(*lhs, &Expectation::none()); 432 None => Ty::Unknown,
432 let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(lhs_ty)); 433 },
433 match self.resolve_range_inclusive() { 434 (RangeOp::Inclusive, None, Some(ty)) => {
434 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), rhs_ty), 435 match self.resolve_range_to_inclusive() {
435 None => Ty::Unknown, 436 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty),
436 } 437 None => Ty::Unknown,
437 } 438 }
438 Expr::RangeFrom { lhs } => { 439 }
439 let ty = self.infer_expr(*lhs, &Expectation::none()); 440 (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() {
440 match self.resolve_range_from() { 441 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty),
441 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), 442 None => Ty::Unknown,
442 None => Ty::Unknown, 443 },
443 } 444 (RangeOp::Inclusive, Some(_), Some(ty)) => {
444 } 445 match self.resolve_range_inclusive() {
445 Expr::RangeTo { rhs } => { 446 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty),
446 let ty = self.infer_expr(*rhs, &Expectation::none()); 447 None => Ty::Unknown,
447 match self.resolve_range_to() { 448 }
448 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty), 449 }
449 None => Ty::Unknown, 450 (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() {
450 } 451 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty),
451 } 452 None => Ty::Unknown,
452 Expr::RangeToInclusive { rhs } => { 453 },
453 let ty = self.infer_expr(*rhs, &Expectation::none()); 454 (RangeOp::Inclusive, _, None) => Ty::Unknown,
454 match self.resolve_range_to_inclusive() {
455 Some(adt) => Ty::apply_one(TypeCtor::Adt(adt), ty),
456 None => Ty::Unknown,
457 } 455 }
458 } 456 }
459 Expr::Index { base, index } => { 457 Expr::Index { base, index } => {