aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer/expr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r--crates/hir_ty/src/infer/expr.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 2fcc7c549..5b3cdab4e 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -15,15 +15,16 @@ use stdx::always;
15use syntax::ast::RangeOp; 15use syntax::ast::RangeOp;
16 16
17use crate::{ 17use crate::{
18 autoderef, 18 autoderef, dummy_usize_const,
19 lower::lower_to_chalk_mutability, 19 lower::lower_to_chalk_mutability,
20 method_resolution, op, 20 method_resolution, op,
21 primitive::{self, UintTy}, 21 primitive::{self, UintTy},
22 to_chalk_trait_id, 22 static_lifetime, to_chalk_trait_id,
23 traits::{chalk::from_chalk, FnTrait}, 23 traits::{chalk::from_chalk, FnTrait},
24 utils::{generics, variant_data, Generics}, 24 utils::{generics, variant_data, Generics},
25 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, 25 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
26 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, 26 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,
27 TypeWalk,
27}; 28};
28 29
29use super::{ 30use super::{
@@ -533,7 +534,7 @@ impl<'a> InferenceContext<'a> {
533 let inner_ty = self.infer_expr_inner(*expr, &expectation); 534 let inner_ty = self.infer_expr_inner(*expr, &expectation);
534 match rawness { 535 match rawness {
535 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty), 536 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty),
536 Rawness::Ref => TyKind::Ref(mutability, inner_ty), 537 Rawness::Ref => TyKind::Ref(mutability, static_lifetime(), inner_ty),
537 } 538 }
538 .intern(&Interner) 539 .intern(&Interner)
539 } 540 }
@@ -708,7 +709,7 @@ impl<'a> InferenceContext<'a> {
708 } 709 }
709 Expr::Array(array) => { 710 Expr::Array(array) => {
710 let elem_ty = match expected.ty.kind(&Interner) { 711 let elem_ty = match expected.ty.kind(&Interner) {
711 TyKind::Array(st) | TyKind::Slice(st) => st.clone(), 712 TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(),
712 _ => self.table.new_type_var(), 713 _ => self.table.new_type_var(),
713 }; 714 };
714 715
@@ -732,17 +733,19 @@ impl<'a> InferenceContext<'a> {
732 } 733 }
733 } 734 }
734 735
735 TyKind::Array(elem_ty).intern(&Interner) 736 TyKind::Array(elem_ty, dummy_usize_const()).intern(&Interner)
736 } 737 }
737 Expr::Literal(lit) => match lit { 738 Expr::Literal(lit) => match lit {
738 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), 739 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
739 Literal::String(..) => { 740 Literal::String(..) => {
740 TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner) 741 TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner))
742 .intern(&Interner)
741 } 743 }
742 Literal::ByteString(..) => { 744 Literal::ByteString(..) => {
743 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); 745 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
744 let array_type = TyKind::Array(byte_type).intern(&Interner); 746 let array_type =
745 TyKind::Ref(Mutability::Not, array_type).intern(&Interner) 747 TyKind::Array(byte_type, dummy_usize_const()).intern(&Interner);
748 TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner)
746 } 749 }
747 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), 750 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
748 Literal::Int(_v, ty) => match ty { 751 Literal::Int(_v, ty) => match ty {
@@ -878,7 +881,9 @@ impl<'a> InferenceContext<'a> {
878 // Apply autoref so the below unification works correctly 881 // Apply autoref so the below unification works correctly
879 // FIXME: return correct autorefs from lookup_method 882 // FIXME: return correct autorefs from lookup_method
880 let actual_receiver_ty = match expected_receiver_ty.as_reference() { 883 let actual_receiver_ty = match expected_receiver_ty.as_reference() {
881 Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner), 884 Some((_, lifetime, mutability)) => {
885 TyKind::Ref(mutability, lifetime, derefed_receiver_ty).intern(&Interner)
886 }
882 _ => derefed_receiver_ty, 887 _ => derefed_receiver_ty,
883 }; 888 };
884 self.unify(&expected_receiver_ty, &actual_receiver_ty); 889 self.unify(&expected_receiver_ty, &actual_receiver_ty);