Semantic getter

This commit is contained in:
Andrzej Głuszak 2021-09-29 14:04:32 +02:00
parent 6c7526d308
commit 98676efdc5
9 changed files with 401 additions and 63 deletions

View file

@ -1574,6 +1574,11 @@ pub struct BuiltinType {
}
impl BuiltinType {
// FIXME: I'm not sure if it's the best place to put it
pub fn str() -> BuiltinType {
BuiltinType { inner: hir_def::builtin_type::BuiltinType::Str }
}
pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type {
let resolver = module.id.resolver(db.upcast());
Type::new_with_resolver(db, &resolver, TyBuilder::builtin(self.inner))
@ -2263,6 +2268,11 @@ impl Type {
Type::new(db, krate, def, ty)
}
// FIXME: No idea where to put it
pub fn make_slice_of(self) -> Type {
Type { krate: self.krate, env: self.env, ty: TyBuilder::slice(self.ty) }
}
pub fn is_unit(&self) -> bool {
matches!(self.ty.kind(&Interner), TyKind::Tuple(0, ..))
}