aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/lib.rs10
-rw-r--r--crates/hir_ty/src/lower.rs14
2 files changed, 11 insertions, 13 deletions
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};
27 27
28use base_db::{salsa, CrateId}; 28use base_db::{salsa, CrateId};
29use hir_def::{ 29use hir_def::{
30 builtin_type::BuiltinType,
30 expr::ExprId, 31 expr::ExprId,
31 type_ref::{Mutability, Rawness}, 32 type_ref::{Mutability, Rawness},
32 AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId, 33 AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId,
@@ -738,6 +739,15 @@ impl Ty {
738 Substs(sig.params_and_return), 739 Substs(sig.params_and_return),
739 ) 740 )
740 } 741 }
742 pub fn builtin(builtin: BuiltinType) -> Self {
743 Ty::simple(match builtin {
744 BuiltinType::Char => TypeCtor::Char,
745 BuiltinType::Bool => TypeCtor::Bool,
746 BuiltinType::Str => TypeCtor::Str,
747 BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()),
748 BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()),
749 })
750 }
741 751
742 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { 752 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
743 match self { 753 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;
27 27
28use crate::{ 28use crate::{
29 db::HirDatabase, 29 db::HirDatabase,
30 primitive::{FloatTy, IntTy},
31 utils::{ 30 utils::{
32 all_super_trait_refs, associated_type_by_name_including_super_traits, generics, 31 all_super_trait_refs, associated_type_by_name_including_super_traits, generics,
33 make_mut_slice, variant_data, 32 make_mut_slice, variant_data,
@@ -1051,17 +1050,6 @@ fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders<Ty> {
1051 Binders::new(0, Ty::from_hir(&ctx, &data.type_ref)) 1050 Binders::new(0, Ty::from_hir(&ctx, &data.type_ref))
1052} 1051}
1053 1052
1054/// Build the declared type of a static.
1055fn type_for_builtin(def: BuiltinType) -> Ty {
1056 Ty::simple(match def {
1057 BuiltinType::Char => TypeCtor::Char,
1058 BuiltinType::Bool => TypeCtor::Bool,
1059 BuiltinType::Str => TypeCtor::Str,
1060 BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()),
1061 BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()),
1062 })
1063}
1064
1065fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig { 1053fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig {
1066 let struct_data = db.struct_data(def); 1054 let struct_data = db.struct_data(def);
1067 let fields = struct_data.variant_data.fields(); 1055 let fields = struct_data.variant_data.fields();
@@ -1186,7 +1174,7 @@ impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for V
1186/// namespace. 1174/// namespace.
1187pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> { 1175pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> {
1188 match def { 1176 match def {
1189 TyDefId::BuiltinType(it) => Binders::new(0, type_for_builtin(it)), 1177 TyDefId::BuiltinType(it) => Binders::new(0, Ty::builtin(it)),
1190 TyDefId::AdtId(it) => type_for_adt(db, it), 1178 TyDefId::AdtId(it) => type_for_adt(db, it),
1191 TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), 1179 TyDefId::TypeAliasId(it) => type_for_type_alias(db, it),
1192 } 1180 }