Move Ty::builtin to TyBuilder

This commit is contained in:
Florian Diebold 2021-04-03 21:32:22 +02:00
parent 620769f322
commit 2ead65190e
3 changed files with 20 additions and 20 deletions

View File

@ -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")
}

View File

@ -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<hir_def::AdtId> {
@ -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)),

View File

@ -1216,7 +1216,7 @@ pub enum ValueTyDefId {
/// namespace.
pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> {
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),
}