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.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index ff564106b..77fb36332 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -23,7 +23,7 @@ use crate::{
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 LifetimeData, ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind,
27}; 27};
28 28
29use super::{ 29use super::{
@@ -527,7 +527,9 @@ impl<'a> InferenceContext<'a> {
527 let inner_ty = self.infer_expr_inner(*expr, &expectation); 527 let inner_ty = self.infer_expr_inner(*expr, &expectation);
528 match rawness { 528 match rawness {
529 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty), 529 Rawness::RawPtr => TyKind::Raw(mutability, inner_ty),
530 Rawness::Ref => TyKind::Ref(mutability, inner_ty), 530 Rawness::Ref => {
531 TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), inner_ty)
532 }
531 } 533 }
532 .intern(&Interner) 534 .intern(&Interner)
533 } 535 }
@@ -730,13 +732,17 @@ impl<'a> InferenceContext<'a> {
730 } 732 }
731 Expr::Literal(lit) => match lit { 733 Expr::Literal(lit) => match lit {
732 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), 734 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
733 Literal::String(..) => { 735 Literal::String(..) => TyKind::Ref(
734 TyKind::Ref(Mutability::Not, TyKind::Str.intern(&Interner)).intern(&Interner) 736 Mutability::Not,
735 } 737 LifetimeData::Static.intern(&Interner),
738 TyKind::Str.intern(&Interner),
739 )
740 .intern(&Interner),
736 Literal::ByteString(..) => { 741 Literal::ByteString(..) => {
737 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); 742 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
738 let array_type = TyKind::Array(byte_type).intern(&Interner); 743 let array_type = TyKind::Array(byte_type).intern(&Interner);
739 TyKind::Ref(Mutability::Not, array_type).intern(&Interner) 744 TyKind::Ref(Mutability::Not, LifetimeData::Static.intern(&Interner), array_type)
745 .intern(&Interner)
740 } 746 }
741 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), 747 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
742 Literal::Int(_v, ty) => match ty { 748 Literal::Int(_v, ty) => match ty {
@@ -872,7 +878,9 @@ impl<'a> InferenceContext<'a> {
872 // Apply autoref so the below unification works correctly 878 // Apply autoref so the below unification works correctly
873 // FIXME: return correct autorefs from lookup_method 879 // FIXME: return correct autorefs from lookup_method
874 let actual_receiver_ty = match expected_receiver_ty.as_reference() { 880 let actual_receiver_ty = match expected_receiver_ty.as_reference() {
875 Some((_, mutability)) => TyKind::Ref(mutability, derefed_receiver_ty).intern(&Interner), 881 Some((_, lifetime, mutability)) => {
882 TyKind::Ref(mutability, lifetime, derefed_receiver_ty).intern(&Interner)
883 }
876 _ => derefed_receiver_ty, 884 _ => derefed_receiver_ty,
877 }; 885 };
878 self.unify(&expected_receiver_ty, &actual_receiver_ty); 886 self.unify(&expected_receiver_ty, &actual_receiver_ty);