From 2ead65190ecaf1096a998d88d4aab8505ce88afa Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 3 Apr 2021 21:32:22 +0200 Subject: Move Ty::builtin to TyBuilder --- crates/hir/src/lib.rs | 4 ++-- crates/hir_ty/src/lib.rs | 34 +++++++++++++++++----------------- crates/hir_ty/src/lower.rs | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'crates') 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::{ traits::{FnTrait, Solution, SolutionVariables}, AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, DebruijnIndex, InEnvironment, Interner, ProjectionTy, QuantifiedWhereClause, Scalar, - Substitution, TraitEnvironment, Ty, TyDefId, TyKind, TyVariableKind, WhereClause, + Substitution, TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause, }; use itertools::Itertools; use rustc_hash::FxHashSet; @@ -1129,7 +1129,7 @@ pub struct BuiltinType { impl BuiltinType { pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type { let resolver = module.id.resolver(db.upcast()); - Type::new_with_resolver(db, &resolver, Ty::builtin(self.inner)) + Type::new_with_resolver(db, &resolver, TyBuilder::builtin(self.inner)) .expect("crate not present in resolver") } 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<()> { }) .intern(&Interner) } + + pub fn builtin(builtin: BuiltinType) -> Ty { + match builtin { + BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(&Interner), + BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(&Interner), + BuiltinType::Str => TyKind::Str.intern(&Interner), + BuiltinType::Int(t) => { + TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(&Interner) + } + BuiltinType::Uint(t) => { + TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(&Interner) + } + BuiltinType::Float(t) => { + TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(&Interner) + } + } + } } impl TyBuilder { @@ -911,23 +928,6 @@ impl TyBuilder { } impl Ty { - pub fn builtin(builtin: BuiltinType) -> Self { - match builtin { - BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(&Interner), - BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(&Interner), - BuiltinType::Str => TyKind::Str.intern(&Interner), - BuiltinType::Int(t) => { - TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(&Interner) - } - BuiltinType::Uint(t) => { - TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(&Interner) - } - BuiltinType::Float(t) => { - TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(&Interner) - } - } - } - pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { match self.kind(&Interner) { 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 /// namespace. pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders { match def { - TyDefId::BuiltinType(it) => Binders::new(0, Ty::builtin(it)), + TyDefId::BuiltinType(it) => Binders::new(0, TyBuilder::builtin(it)), TyDefId::AdtId(it) => type_for_adt(db, it), TyDefId::TypeAliasId(it) => type_for_type_alias(db, it), } -- cgit v1.2.3