Skip to content

Commit

Permalink
HIR Typecheck - Tweak Pointee trait impl
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Jan 4, 2024
1 parent d4e2b70 commit 79d2588
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/hir_typeck/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ bool TraitResolution::find_trait_impls_magic(const Span& sp,
return callback( ImplRef(type.clone(), HIR::PathParams(), ::HIR::TraitPath::assoc_list_t()), ::HIR::Compare::Fuzzy );
}
// Generics (or opaque ATYs)
if( type.data().is_Generic() || (type.data().is_Path() && type.data().as_Path().binding.is_Opaque()) ) {
else if( type.data().is_Generic() || (type.data().is_Path() && type.data().as_Path().binding.is_Opaque()) ) {
// If the type is `Sized` return `()` as the type
if( type_is_sized(sp, type) ) {
meta_ty = HIR::TypeRef::new_unit();
Expand All @@ -1349,18 +1349,18 @@ bool TraitResolution::find_trait_impls_magic(const Span& sp,
}
}
// Trait object: `Metadata=DynMetadata<T>`
if( type.data().is_TraitObject() ) {
else if( type.data().is_TraitObject() ) {
meta_ty = ::HIR::TypeRef::new_path(
::HIR::GenericPath(this->m_crate.get_lang_item_path(sp, "dyn_metadata"), HIR::PathParams(type.clone())),
&m_crate.get_struct_by_path(sp, this->m_crate.get_lang_item_path(sp, "dyn_metadata"))
);
}
// Slice and str
if( type.data().is_Slice() || TU_TEST1(type.data(), Primitive, == HIR::CoreType::Str) ) {
else if( type.data().is_Slice() || TU_TEST1(type.data(), Primitive, == HIR::CoreType::Str) ) {
meta_ty = HIR::CoreType::Usize;
}
// Structs: Can delegate their metadata
if( type.data().is_Path() && type.data().as_Path().binding.is_Struct() )
else if( type.data().is_Path() && type.data().as_Path().binding.is_Struct() )
{
const auto& str = *type.data().as_Path().binding.as_Struct();
switch(str.m_struct_markings.dst_type)
Expand All @@ -1377,6 +1377,9 @@ bool TraitResolution::find_trait_impls_magic(const Span& sp,
TODO(sp, "m_lang_Pointee - " << type);
}
}
else {
meta_ty = ::HIR::TypeRef::new_unit();
}
::HIR::TraitPath::assoc_list_t assoc_list;
if(meta_ty != HIR::TypeRef()) {
assoc_list.insert(std::make_pair( RcString::new_interned("Metadata"), HIR::TraitPath::AtyEqual { trait, mv$(meta_ty) } ));
Expand Down

0 comments on commit 79d2588

Please sign in to comment.