diff options
author | Florian Diebold <[email protected]> | 2021-04-03 20:32:22 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-04 12:16:38 +0100 |
commit | 2ead65190ecaf1096a998d88d4aab8505ce88afa (patch) | |
tree | dd6aa27a384dfc08d4cf65da4207bc518d162ebc /crates | |
parent | 620769f32276bb7e8c580eae2c91ee535a06d9f8 (diff) |
Move Ty::builtin to TyBuilder
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 34 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 2 |
3 files changed, 20 insertions, 20 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index eb19e4b51..682d49a21 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -59,7 +59,7 @@ use hir_ty::{ | |||
59 | traits::{FnTrait, Solution, SolutionVariables}, | 59 | traits::{FnTrait, Solution, SolutionVariables}, |
60 | AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, | 60 | AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, |
61 | DebruijnIndex, InEnvironment, Interner, ProjectionTy, QuantifiedWhereClause, Scalar, | 61 | DebruijnIndex, InEnvironment, Interner, ProjectionTy, QuantifiedWhereClause, Scalar, |
62 | Substitution, TraitEnvironment, Ty, TyDefId, TyKind, TyVariableKind, WhereClause, | 62 | Substitution, TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause, |
63 | }; | 63 | }; |
64 | use itertools::Itertools; | 64 | use itertools::Itertools; |
65 | use rustc_hash::FxHashSet; | 65 | use rustc_hash::FxHashSet; |
@@ -1129,7 +1129,7 @@ pub struct BuiltinType { | |||
1129 | impl BuiltinType { | 1129 | impl BuiltinType { |
1130 | pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type { | 1130 | pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type { |
1131 | let resolver = module.id.resolver(db.upcast()); | 1131 | let resolver = module.id.resolver(db.upcast()); |
1132 | Type::new_with_resolver(db, &resolver, Ty::builtin(self.inner)) | 1132 | Type::new_with_resolver(db, &resolver, TyBuilder::builtin(self.inner)) |
1133 | .expect("crate not present in resolver") | 1133 | .expect("crate not present in resolver") |
1134 | } | 1134 | } |
1135 | 1135 | ||
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 | ||
882 | impl TyBuilder<hir_def::AdtId> { | 899 | impl TyBuilder<hir_def::AdtId> { |
@@ -911,23 +928,6 @@ impl TyBuilder<hir_def::AdtId> { | |||
911 | } | 928 | } |
912 | 929 | ||
913 | impl Ty { | 930 | impl 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. |
1217 | pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> { | 1217 | pub(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 | } |