diff options
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 27 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 26 |
2 files changed, 17 insertions, 36 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index db8aeead2..5eb07126e 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -539,17 +539,10 @@ impl<'a> InferenceContext<'a> { | |||
539 | Expr::Box { expr } => { | 539 | Expr::Box { expr } => { |
540 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 540 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
541 | if let Some(box_) = self.resolve_boxed_box() { | 541 | if let Some(box_) = self.resolve_boxed_box() { |
542 | let mut sb = | 542 | TyBuilder::adt(self.db, box_) |
543 | Substitution::build_for_generics(&generics(self.db.upcast(), box_.into())); | 543 | .push(inner_ty) |
544 | sb = sb.push(inner_ty); | 544 | .fill_with_defaults(self.db, || self.table.new_type_var()) |
545 | match self.db.generic_defaults(box_.into()).get(1) { | 545 | .build() |
546 | Some(alloc_ty) if !alloc_ty.value.is_unknown() && sb.remaining() > 0 => { | ||
547 | sb = sb.push(alloc_ty.value.clone()); | ||
548 | } | ||
549 | _ => (), | ||
550 | } | ||
551 | sb = sb.fill(repeat_with(|| self.table.new_type_var())); | ||
552 | Ty::adt_ty(box_, sb.build()) | ||
553 | } else { | 546 | } else { |
554 | self.err_ty() | 547 | self.err_ty() |
555 | } | 548 | } |
@@ -639,31 +632,31 @@ impl<'a> InferenceContext<'a> { | |||
639 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); | 632 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); |
640 | match (range_type, lhs_ty, rhs_ty) { | 633 | match (range_type, lhs_ty, rhs_ty) { |
641 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { | 634 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { |
642 | Some(adt) => Ty::adt_ty(adt, Substitution::empty(&Interner)), | 635 | Some(adt) => TyBuilder::adt(self.db, adt).build(), |
643 | None => self.err_ty(), | 636 | None => self.err_ty(), |
644 | }, | 637 | }, |
645 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { | 638 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { |
646 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), | 639 | Some(adt) => TyBuilder::adt(self.db, adt).push(ty).build(), |
647 | None => self.err_ty(), | 640 | None => self.err_ty(), |
648 | }, | 641 | }, |
649 | (RangeOp::Inclusive, None, Some(ty)) => { | 642 | (RangeOp::Inclusive, None, Some(ty)) => { |
650 | match self.resolve_range_to_inclusive() { | 643 | match self.resolve_range_to_inclusive() { |
651 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), | 644 | Some(adt) => TyBuilder::adt(self.db, adt).push(ty).build(), |
652 | None => self.err_ty(), | 645 | None => self.err_ty(), |
653 | } | 646 | } |
654 | } | 647 | } |
655 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { | 648 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { |
656 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), | 649 | Some(adt) => TyBuilder::adt(self.db, adt).push(ty).build(), |
657 | None => self.err_ty(), | 650 | None => self.err_ty(), |
658 | }, | 651 | }, |
659 | (RangeOp::Inclusive, Some(_), Some(ty)) => { | 652 | (RangeOp::Inclusive, Some(_), Some(ty)) => { |
660 | match self.resolve_range_inclusive() { | 653 | match self.resolve_range_inclusive() { |
661 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), | 654 | Some(adt) => TyBuilder::adt(self.db, adt).push(ty).build(), |
662 | None => self.err_ty(), | 655 | None => self.err_ty(), |
663 | } | 656 | } |
664 | } | 657 | } |
665 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { | 658 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { |
666 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), | 659 | Some(adt) => TyBuilder::adt(self.db, adt).push(ty).build(), |
667 | None => self.err_ty(), | 660 | None => self.err_ty(), |
668 | }, | 661 | }, |
669 | (RangeOp::Inclusive, _, None) => self.err_ty(), | 662 | (RangeOp::Inclusive, _, None) => self.err_ty(), |
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 10df8d8cb..5b70d5e5a 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -13,9 +13,8 @@ use hir_expand::name::Name; | |||
13 | 13 | ||
14 | use super::{BindingMode, Expectation, InferenceContext}; | 14 | use super::{BindingMode, Expectation, InferenceContext}; |
15 | use crate::{ | 15 | use crate::{ |
16 | lower::lower_to_chalk_mutability, | 16 | lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substitution, Ty, TyBuilder, |
17 | utils::{generics, variant_data}, | 17 | TyKind, |
18 | Interner, Substitution, Ty, TyKind, | ||
19 | }; | 18 | }; |
20 | 19 | ||
21 | impl<'a> InferenceContext<'a> { | 20 | impl<'a> InferenceContext<'a> { |
@@ -246,23 +245,12 @@ impl<'a> InferenceContext<'a> { | |||
246 | }; | 245 | }; |
247 | 246 | ||
248 | let inner_ty = self.infer_pat(*inner, &inner_ty, default_bm); | 247 | let inner_ty = self.infer_pat(*inner, &inner_ty, default_bm); |
249 | let mut sb = Substitution::build_for_generics(&generics( | 248 | let mut b = TyBuilder::adt(self.db, box_adt).push(inner_ty); |
250 | self.db.upcast(), | 249 | |
251 | box_adt.into(), | 250 | if let Some(alloc_ty) = alloc_ty { |
252 | )); | 251 | b = b.push(alloc_ty); |
253 | sb = sb.push(inner_ty); | ||
254 | if sb.remaining() == 1 { | ||
255 | sb = sb.push(match alloc_ty { | ||
256 | Some(alloc_ty) if !alloc_ty.is_unknown() => alloc_ty, | ||
257 | _ => match self.db.generic_defaults(box_adt.into()).get(1) { | ||
258 | Some(alloc_ty) if !alloc_ty.value.is_unknown() => { | ||
259 | alloc_ty.value.clone() | ||
260 | } | ||
261 | _ => self.table.new_type_var(), | ||
262 | }, | ||
263 | }); | ||
264 | } | 252 | } |
265 | Ty::adt_ty(box_adt, sb.build()) | 253 | b.fill_with_defaults(self.db, || self.table.new_type_var()).build() |
266 | } | 254 | } |
267 | None => self.err_ty(), | 255 | None => self.err_ty(), |
268 | }, | 256 | }, |