diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index eb19e4b51a8..682d49a21fd 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -59,7 +59,7 @@ 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 afe5424d62e..be6fe5016c8 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -877,6 +877,23 @@ pub fn fn_ptr(sig: CallableSig) -> Ty { }) .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 @@ pub fn build(self) -> Ty { } 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 5e2024f0a9f..762b226e62b 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -1216,7 +1216,7 @@ pub enum ValueTyDefId { /// 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), }