const Analysis::NodeMapping &mappings,
location_t expr_locus, bool is_qualified_path)
{
- HirId parent_block;
- HIR::ExternalItem *resolved_extern_item
- = ctx->get_mappings ().lookup_hir_extern_item (ref, &parent_block);
- bool is_hir_extern_item = resolved_extern_item != nullptr;
bool is_fn = lookup->get_kind () == TyTy::TypeKind::FNDEF;
if (auto resolved_item = ctx->get_mappings ().lookup_hir_item (ref))
{
return CompileItem::compile (*resolved_item, ctx, lookup, true,
expr_locus);
}
- else if (is_hir_extern_item)
+ else if (auto hir_extern_item
+ = ctx->get_mappings ().lookup_hir_extern_item (ref))
{
+ HIR::ExternalItem *resolved_extern_item = hir_extern_item->first;
if (!lookup->has_substitutions_defined ())
return CompileExternItem::compile (resolved_extern_item, ctx, nullptr,
true, expr_locus);
// There are const extern functions (intrinsics)
// TODO: Should we check the ABI is only "rust intrinsics"? Is that handled
// elsewhere?
- HirId parent_block;
- auto maybe_extern_item
- = mappings.lookup_hir_extern_item (fn_id, &parent_block);
+ auto maybe_extern_item = mappings.lookup_hir_extern_item (fn_id);
if (maybe_extern_item
- && maybe_extern_item->get_extern_kind ()
+ && maybe_extern_item->first->get_extern_kind ()
!= ExternalItem::ExternKind::Function)
return;
if (maybe_extern_item)
{
{
- auto fn = static_cast<ExternalFunctionItem *> (maybe_extern_item);
+ auto fn
+ = static_cast<ExternalFunctionItem *> (maybe_extern_item->first);
if (!is_const_extern_fn (*fn))
is_error = true;
}
if (unsafe_context.is_in_context ())
return;
- HirId extern_block;
- auto maybe_extern_static
- = mappings.lookup_hir_extern_item (node_id, &extern_block);
-
if (auto maybe_static_mut = mappings.lookup_hir_item (node_id))
check_static_mut (*maybe_static_mut, locus);
- if (maybe_extern_static)
- check_extern_static (static_cast<ExternalItem *> (maybe_extern_static),
+ if (auto maybe_extern_static = mappings.lookup_hir_extern_item (node_id))
+ check_extern_static (static_cast<ExternalItem *> (
+ maybe_extern_static->first),
locus);
}
if (unsafe_context.is_in_context ())
return;
- HirId parent_extern_block;
auto maybe_fn = mappings.lookup_hir_item (node_id);
- auto maybe_extern
- = mappings.lookup_hir_extern_item (node_id, &parent_extern_block);
if (maybe_fn
&& maybe_fn.value ()->get_item_kind () == Item::ItemKind::Function)
check_unsafe_call (static_cast<Function *> (*maybe_fn), locus, "function");
- if (maybe_extern)
- check_extern_call (static_cast<ExternalItem *> (maybe_extern),
- *mappings.lookup_hir_extern_block (parent_extern_block),
+ if (auto maybe_extern = mappings.lookup_hir_extern_item (node_id))
+ check_extern_call (static_cast<ExternalItem *> (maybe_extern->first),
+ *mappings.lookup_hir_extern_block (maybe_extern->second),
locus);
}
}
// is it an extern item?
- HirId parent_extern_block_id = UNKNOWN_HIRID;
- HIR::ExternalItem *extern_item
- = mappings.lookup_hir_extern_item (reference, &parent_extern_block_id);
- if (extern_item != nullptr)
+ if (auto extern_item = mappings.lookup_hir_extern_item (reference))
{
- auto block = mappings.lookup_hir_extern_block (parent_extern_block_id);
+ auto block = mappings.lookup_hir_extern_block (extern_item->second);
rust_assert (block.has_value ());
- *result
- = TypeCheckTopLevelExternItem::Resolve (extern_item, *block.value ());
+ *result = TypeCheckTopLevelExternItem::Resolve (extern_item->first,
+ *block.value ());
context->query_completed (reference);
return true;
}
Mappings::insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block)
{
auto id = item->get_mappings ().get_hirid ();
- rust_assert (lookup_hir_extern_item (id, nullptr) == nullptr);
+ rust_assert (!lookup_hir_extern_item (id));
hirExternItemMappings[id] = {item, parent_block};
insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
}
-HIR::ExternalItem *
-Mappings::lookup_hir_extern_item (HirId id, HirId *parent_block)
+tl::optional<std::pair<HIR::ExternalItem *, HirId>>
+Mappings::lookup_hir_extern_item (HirId id)
{
auto it = hirExternItemMappings.find (id);
if (it == hirExternItemMappings.end ())
- return nullptr;
-
- *parent_block = it->second.second;
+ return tl::nullopt;
- return it->second.first;
+ return it->second;
}
void
tl::optional<HIR::ExternBlock *> lookup_hir_extern_block (HirId id);
void insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block);
- HIR::ExternalItem *lookup_hir_extern_item (HirId id, HirId *parent_block);
+
+ // std::pair<hir_extern_item, parent hirid>
+ tl::optional<std::pair<HIR::ExternalItem *, HirId>>
+ lookup_hir_extern_item (HirId id);
void insert_hir_impl_block (HIR::ImplBlock *item);
tl::optional<HIR::ImplBlock *> lookup_hir_impl_block (HirId id);