else
{
// it might be resolved to a trait item
- HIR::TraitItem *trait_item
+ tl::optional<HIR::TraitItem *> trait_item
= ctx->get_mappings ().lookup_hir_trait_item (ref);
+
HIR::Trait *trait = ctx->get_mappings ().lookup_trait_item_mapping (
- trait_item->get_mappings ().get_hirid ());
+ trait_item.value ()->get_mappings ().get_hirid ());
Resolver::TraitReference *trait_ref
= &Resolver::TraitReference::error_node ();
// this means we are defaulting back to the trait_item if
// possible
Resolver::TraitItemReference *trait_item_ref = nullptr;
- bool ok = trait_ref->lookup_hir_trait_item (*trait_item,
+ bool ok = trait_ref->lookup_hir_trait_item (*trait_item.value (),
&trait_item_ref);
rust_assert (ok); // found
rust_assert (trait_item_ref->is_optional ()); // has definition
}
static V0Path
-v0_function_path (V0Path path, Rust::Compile::Context *ctx,
- const TyTy::BaseType *ty, HIR::Function *fn,
- std::string ident)
+v0_function_path (
+ V0Path path, Rust::Compile::Context *ctx, const TyTy::BaseType *ty,
+ const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params,
+ std::string ident)
{
V0Path v0path;
v0path.prefix = "N";
v0path.ns = "v";
v0path.path = path.as_string ();
v0path.ident = ident;
- if (!fn->get_generic_params ().empty ())
+ if (!generic_params.empty ())
{
v0path.generic_prefix = "I";
v0path.generic_postfix = v0_generic_args (ctx, ty) + "E";
HirId parent_impl_id = UNKNOWN_HIRID;
HIR::ImplItem *impl_item
= mappings.lookup_hir_implitem (hir_id, &parent_impl_id);
- HIR::TraitItem *trait_item = mappings.lookup_hir_trait_item (hir_id);
HIR::Expr *expr = mappings.lookup_hir_expr (hir_id);
if (impl_item != nullptr)
{
case HIR::ImplItem::FUNCTION: {
HIR::Function *fn = static_cast<HIR::Function *> (impl_item);
- v0path = v0_function_path (v0path, ctx, ty, fn,
- v0_identifier (seg.get ()));
+ v0path
+ = v0_function_path (v0path, ctx, ty, fn->get_generic_params (),
+ v0_identifier (seg.get ()));
}
break;
case HIR::ImplItem::CONSTANT:
break;
}
}
- else if (trait_item != nullptr)
+ else if (auto trait_item = mappings.lookup_hir_trait_item (hir_id))
{
- switch (trait_item->get_item_kind ())
+ switch (trait_item.value ()->get_item_kind ())
{
case HIR::TraitItem::FUNC: {
- HIR::Function *fn = static_cast<HIR::Function *> (impl_item);
- v0path = v0_function_path (v0path, ctx, ty, fn,
+ auto fn = static_cast<HIR::TraitItemFunc *> (*trait_item);
+ rust_unreachable ();
+ v0path = v0_function_path (v0path, ctx, ty,
+ fn->get_decl ().get_generic_params (),
v0_identifier (seg.get ()));
}
break;
{
case HIR::Item::ItemKind::Function: {
HIR::Function *fn = static_cast<HIR::Function *> (*item);
- v0path = v0_function_path (v0path, ctx, ty, fn,
- v0_identifier (seg.get ()));
+ v0path
+ = v0_function_path (v0path, ctx, ty, fn->get_generic_params (),
+ v0_identifier (seg.get ()));
}
break;
case HIR::Item::ItemKind::Module:
Mappings::insert_hir_trait_item (HIR::TraitItem *item)
{
auto id = item->get_mappings ().get_hirid ();
- rust_assert (lookup_hir_trait_item (id) == nullptr);
+ rust_assert (!lookup_hir_trait_item (id).has_value ());
hirTraitItemMappings[id] = item;
insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
}
-HIR::TraitItem *
+tl::optional<HIR::TraitItem *>
Mappings::lookup_hir_trait_item (HirId id)
{
auto it = hirTraitItemMappings.find (id);
if (it == hirTraitItemMappings.end ())
- return nullptr;
+ return tl::nullopt;
return it->second;
}