From 216dc856c5b48de7d9cdbe6259b2d0cd3c4e5042 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 11 Feb 2021 19:52:33 +0100 Subject: Wrap `BuiltinType` in code model --- crates/hir_ty/src/lib.rs | 10 ++++++++++ crates/hir_ty/src/lower.rs | 14 +------------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 6bec389f8..50d248674 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -27,6 +27,7 @@ use std::{iter, mem, ops::Deref, sync::Arc}; use base_db::{salsa, CrateId}; use hir_def::{ + builtin_type::BuiltinType, expr::ExprId, type_ref::{Mutability, Rawness}, AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId, @@ -738,6 +739,15 @@ impl Ty { Substs(sig.params_and_return), ) } + pub fn builtin(builtin: BuiltinType) -> Self { + Ty::simple(match builtin { + BuiltinType::Char => TypeCtor::Char, + BuiltinType::Bool => TypeCtor::Bool, + BuiltinType::Str => TypeCtor::Str, + BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()), + BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()), + }) + } pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { match self { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index dfb573ff3..f9dc832bd 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -27,7 +27,6 @@ use test_utils::mark; use crate::{ db::HirDatabase, - primitive::{FloatTy, IntTy}, utils::{ all_super_trait_refs, associated_type_by_name_including_super_traits, generics, make_mut_slice, variant_data, @@ -1051,17 +1050,6 @@ fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders { Binders::new(0, Ty::from_hir(&ctx, &data.type_ref)) } -/// Build the declared type of a static. -fn type_for_builtin(def: BuiltinType) -> Ty { - Ty::simple(match def { - BuiltinType::Char => TypeCtor::Char, - BuiltinType::Bool => TypeCtor::Bool, - BuiltinType::Str => TypeCtor::Str, - BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()), - BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()), - }) -} - fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig { let struct_data = db.struct_data(def); let fields = struct_data.variant_data.fields(); @@ -1186,7 +1174,7 @@ impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for V /// namespace. pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders { match def { - TyDefId::BuiltinType(it) => Binders::new(0, type_for_builtin(it)), + TyDefId::BuiltinType(it) => Binders::new(0, Ty::builtin(it)), TyDefId::AdtId(it) => type_for_adt(db, it), TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), } -- cgit v1.2.3