Wrap BuiltinType in code model

This commit is contained in:
Jonas Schievink 2021-02-11 19:52:33 +01:00
parent b0f20a795d
commit 216dc856c5
9 changed files with 56 additions and 28 deletions

View file

@ -27,6 +27,7 @@ use std::{iter, mem, ops::Deref, sync::Arc};
use base_db::{salsa, CrateId};
use hir_def::{
builtin_type::BuiltinType,
expr::ExprId,
type_ref::{Mutability, Rawness},
AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId,
@ -738,6 +739,15 @@ impl Ty {
Substs(sig.params_and_return),
)
}
pub fn builtin(builtin: BuiltinType) -> Self {
Ty::simple(match builtin {
BuiltinType::Char => TypeCtor::Char,
BuiltinType::Bool => TypeCtor::Bool,
BuiltinType::Str => TypeCtor::Str,
BuiltinType::Int(t) => TypeCtor::Int(IntTy::from(t).into()),
BuiltinType::Float(t) => TypeCtor::Float(FloatTy::from(t).into()),
})
}
pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
match self {