core: refactor to use PrimitiveDefinition::contains_id

This commit is contained in:
lyken 2024-06-06 12:54:22 +08:00
parent 38981445ae
commit b6ded9a869
2 changed files with 3 additions and 3 deletions

View File

@ -435,7 +435,7 @@ fn get_llvm_type<'ctx, G: CodeGenerator + ?Sized>(
let result = match &*ty_enum { let result = match &*ty_enum {
TObj { obj_id, fields, .. } => { TObj { obj_id, fields, .. } => {
// check to avoid treating non-class primitives as classes // check to avoid treating non-class primitives as classes
if obj_id.0 <= PrimitiveDefinition::max_id().0 { if PrimitiveDefinition::contains_id(*obj_id) {
return match &*unifier.get_ty_immutable(ty) { return match &*unifier.get_ty_immutable(ty) {
TObj { obj_id, params, .. } if *obj_id == PrimitiveDefinition::Option.id() => { TObj { obj_id, params, .. } if *obj_id == PrimitiveDefinition::Option.id() => {
get_llvm_type( get_llvm_type(

View File

@ -35,8 +35,8 @@ impl PrimitiveDefinition {
return DefinitionId(self as usize); return DefinitionId(self as usize);
} }
pub fn max_id() -> DefinitionId { pub fn contains_id(id: DefinitionId) -> bool {
Self::iter().map(|prim| prim.id()).max().unwrap() Self::iter().any(|prim| prim.id() == id)
} }
} }