From 08dc69599efb4961319c0118b789d3abb264b7fa Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 6 Apr 2021 10:50:55 +0200 Subject: Use a constructor function for Static lifetimes --- crates/hir_ty/src/infer/expr.rs | 21 ++++++++------------- crates/hir_ty/src/infer/pat.rs | 15 ++++++--------- 2 files changed, 14 insertions(+), 22 deletions(-) (limited to 'crates/hir_ty/src/infer') 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::{ lower::lower_to_chalk_mutability, method_resolution, op, primitive::{self, UintTy}, - to_chalk_trait_id, + static_lifetime, to_chalk_trait_id, traits::{chalk::from_chalk, FnTrait}, utils::{generics, variant_data, Generics}, AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, - LifetimeData, ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, + ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, }; use super::{ @@ -527,9 +527,7 @@ impl<'a> InferenceContext<'a> { let inner_ty = self.infer_expr_inner(*expr, &expectation); match rawness { Rawness::RawPtr => TyKind::Raw(mutability, inner_ty), - Rawness::Ref => { - TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), inner_ty) - } + Rawness::Ref => TyKind::Ref(mutability, static_lifetime(), inner_ty), } .intern(&Interner) } @@ -732,17 +730,14 @@ impl<'a> InferenceContext<'a> { } Expr::Literal(lit) => match lit { Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), - Literal::String(..) => TyKind::Ref( - Mutability::Not, - LifetimeData::Static.intern(&Interner), - TyKind::Str.intern(&Interner), - ) - .intern(&Interner), + Literal::String(..) => { + TyKind::Ref(Mutability::Not, static_lifetime(), TyKind::Str.intern(&Interner)) + .intern(&Interner) + } Literal::ByteString(..) => { let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); let array_type = TyKind::Array(byte_type).intern(&Interner); - TyKind::Ref(Mutability::Not, LifetimeData::Static.intern(&Interner), array_type) - .intern(&Interner) + TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) } Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), 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; use super::{BindingMode, Expectation, InferenceContext}; use crate::{ - lower::lower_to_chalk_mutability, utils::variant_data, Interner, LifetimeData, Substitution, + lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution, Ty, TyBuilder, TyKind, }; @@ -171,8 +171,7 @@ impl<'a> InferenceContext<'a> { _ => self.result.standard_types.unknown.clone(), }; let subty = self.infer_pat(*pat, &expectation, default_bm); - TyKind::Ref(mutability, LifetimeData::Static.intern(&Interner), subty) - .intern(&Interner) + TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner) } Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( p.as_ref(), @@ -204,12 +203,10 @@ impl<'a> InferenceContext<'a> { let inner_ty = self.insert_type_vars_shallow(inner_ty); let bound_ty = match mode { - BindingMode::Ref(mutability) => TyKind::Ref( - mutability, - LifetimeData::Static.intern(&Interner), - inner_ty.clone(), - ) - .intern(&Interner), + BindingMode::Ref(mutability) => { + TyKind::Ref(mutability, static_lifetime(), inner_ty.clone()) + .intern(&Interner) + } BindingMode::Move => inner_ty.clone(), }; let bound_ty = self.resolve_ty_as_possible(bound_ty); -- cgit v1.2.3