aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/lib.rs34
-rw-r--r--crates/hir_ty/src/lower.rs2
2 files changed, 18 insertions, 18 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index afe5424d6..be6fe5016 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -877,6 +877,23 @@ impl TyBuilder<()> {
877 }) 877 })
878 .intern(&Interner) 878 .intern(&Interner)
879 } 879 }
880
881 pub fn builtin(builtin: BuiltinType) -> Ty {
882 match builtin {
883 BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(&Interner),
884 BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(&Interner),
885 BuiltinType::Str => TyKind::Str.intern(&Interner),
886 BuiltinType::Int(t) => {
887 TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(&Interner)
888 }
889 BuiltinType::Uint(t) => {
890 TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(&Interner)
891 }
892 BuiltinType::Float(t) => {
893 TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(&Interner)
894 }
895 }
896 }
880} 897}
881 898
882impl TyBuilder<hir_def::AdtId> { 899impl TyBuilder<hir_def::AdtId> {
@@ -911,23 +928,6 @@ impl TyBuilder<hir_def::AdtId> {
911} 928}
912 929
913impl Ty { 930impl Ty {
914 pub fn builtin(builtin: BuiltinType) -> Self {
915 match builtin {
916 BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(&Interner),
917 BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(&Interner),
918 BuiltinType::Str => TyKind::Str.intern(&Interner),
919 BuiltinType::Int(t) => {
920 TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(&Interner)
921 }
922 BuiltinType::Uint(t) => {
923 TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(&Interner)
924 }
925 BuiltinType::Float(t) => {
926 TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(&Interner)
927 }
928 }
929 }
930
931 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { 931 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
932 match self.kind(&Interner) { 932 match self.kind(&Interner) {
933 TyKind::Ref(mutability, ty) => Some((ty, *mutability)), 933 TyKind::Ref(mutability, ty) => Some((ty, *mutability)),
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 5e2024f0a..762b226e6 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1216,7 +1216,7 @@ impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for V
1216/// namespace. 1216/// namespace.
1217pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> { 1217pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> {
1218 match def { 1218 match def {
1219 TyDefId::BuiltinType(it) => Binders::new(0, Ty::builtin(it)), 1219 TyDefId::BuiltinType(it) => Binders::new(0, TyBuilder::builtin(it)),
1220 TyDefId::AdtId(it) => type_for_adt(db, it), 1220 TyDefId::AdtId(it) => type_for_adt(db, it),
1221 TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), 1221 TyDefId::TypeAliasId(it) => type_for_type_alias(db, it),
1222 } 1222 }