aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-04-06 09:50:55 +0100
committerLukas Wirth <[email protected]>2021-04-06 09:50:55 +0100
commit08dc69599efb4961319c0118b789d3abb264b7fa (patch)
treef4951c835dd6f4840ae02ba5c06d5da44aedae94 /crates/hir_ty/src/infer
parentb98c681cb7ede9fd6a8683b1edd83a5b18502178 (diff)
Use a constructor function for Static lifetimes
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r--crates/hir_ty/src/infer/expr.rs21
-rw-r--r--crates/hir_ty/src/infer/pat.rs15
2 files changed, 14 insertions, 22 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 77fb36332..796487d02 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -19,11 +19,11 @@ use crate::{
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 LifetimeData, ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, 26 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeWalk,
27}; 27};
28 28
29use super::{ 29use super::{
@@ -527,9 +527,7 @@ 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 => { 530 Rawness::Ref => TyKind::Ref(mutability, static_lifetime(), inner_ty),
531 TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), inner_ty)
532 }
533 } 531 }
534 .intern(&Interner) 532 .intern(&Interner)
535 } 533 }
@@ -732,17 +730,14 @@ impl<'a> InferenceContext<'a> {
732 } 730 }
733 Expr::Literal(lit) => match lit { 731 Expr::Literal(lit) => match lit {
734 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), 732 Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner),
735 Literal::String(..) => TyKind::Ref( 733 Literal::String(..) => {
736 Mutability::Not, 734 TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner))
737 LifetimeData::Static.intern(&Interner), 735 .intern(&Interner)
738 TyKind::Str.intern(&Interner), 736 }
739 )
740 .intern(&Interner),
741 Literal::ByteString(..) => { 737 Literal::ByteString(..) => {
742 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); 738 let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner);
743 let array_type = TyKind::Array(byte_type).intern(&Interner); 739 let array_type = TyKind::Array(byte_type).intern(&Interner);
744 TyKind::Ref(Mutability::Not, LifetimeData::Static.intern(&Interner), array_type) 740 TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner)
745 .intern(&Interner)
746 } 741 }
747 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), 742 Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner),
748 Literal::Int(_v, ty) => match ty { 743 Literal::Int(_v, ty) => match ty {
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index b5e97cc8c..2848a393c 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -13,7 +13,7 @@ use hir_expand::name::Name;
13 13
14use super::{BindingMode, Expectation, InferenceContext}; 14use super::{BindingMode, Expectation, InferenceContext};
15use crate::{ 15use crate::{
16 lower::lower_to_chalk_mutability, utils::variant_data, Interner, LifetimeData, Substitution, 16 lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution,
17 Ty, TyBuilder, TyKind, 17 Ty, TyBuilder, TyKind,
18}; 18};
19 19
@@ -171,8 +171,7 @@ impl<'a> InferenceContext<'a> {
171 _ => self.result.standard_types.unknown.clone(), 171 _ => self.result.standard_types.unknown.clone(),
172 }; 172 };
173 let subty = self.infer_pat(*pat, &expectation, default_bm); 173 let subty = self.infer_pat(*pat, &expectation, default_bm);
174 TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), subty) 174 TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner)
175 .intern(&Interner)
176 } 175 }
177 Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( 176 Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat(
178 p.as_ref(), 177 p.as_ref(),
@@ -204,12 +203,10 @@ impl<'a> InferenceContext<'a> {
204 let inner_ty = self.insert_type_vars_shallow(inner_ty); 203 let inner_ty = self.insert_type_vars_shallow(inner_ty);
205 204
206 let bound_ty = match mode { 205 let bound_ty = match mode {
207 BindingMode::Ref(mutability) => TyKind::Ref( 206 BindingMode::Ref(mutability) => {
208 mutability, 207 TyKind::Ref(mutability, static_lifetime(), inner_ty.clone())
209 LifetimeData::Static.intern(&Interner), 208 .intern(&Interner)
210 inner_ty.clone(), 209 }
211 )
212 .intern(&Interner),
213 BindingMode::Move => inner_ty.clone(), 210 BindingMode::Move => inner_ty.clone(),
214 }; 211 };
215 let bound_ty = self.resolve_ty_as_possible(bound_ty); 212 let bound_ty = self.resolve_ty_as_possible(bound_ty);