From 01e2a53cb84f959f400af79172843e4bc906ff9a Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 3 May 2024 16:30:06 +0200 Subject: gccrs: Change lookup_hir_implitem return type Wrap the return type within an optional. Now return the parent id within a pair instead of taking an out reference. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Change call site to accept new return type. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_implitem): Likewise. (Mappings::lookup_hir_implitem): Change return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/backend/rust-compile-item.cc | 7 ++----- gcc/rust/backend/rust-compile-resolve-path.cc | 12 ++++-------- gcc/rust/backend/rust-mangle-v0.cc | 10 ++++------ 3 files changed, 10 insertions(+), 19 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index 9d65b61..e7b3a17 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -152,15 +152,12 @@ CompileItem::visit (HIR::Function &function) { // if this is part of a trait impl block which is not generic we need to // ensure associated types are setup - HirId parent_impl_block = UNKNOWN_HIRID; HirId id = function.get_mappings ().get_hirid (); - HIR::ImplItem *impl_item - = ctx->get_mappings ().lookup_hir_implitem (id, &parent_impl_block); - if (impl_item != nullptr) + if (auto impl_item = ctx->get_mappings ().lookup_hir_implitem (id)) { Resolver::AssociatedImplTrait *impl = nullptr; bool found = ctx->get_tyctx ()->lookup_associated_trait_impl ( - parent_impl_block, &impl); + impl_item->second, &impl); if (found) impl->setup_raw_associated_types (); } diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index c27074f..7c9b303 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -238,18 +238,14 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, } } - HirId parent_impl_id = UNKNOWN_HIRID; - HIR::ImplItem *resolved_item - = ctx->get_mappings ().lookup_hir_implitem (ref, &parent_impl_id); - bool is_impl_item = resolved_item != nullptr; - if (is_impl_item) + if (auto resolved_item = ctx->get_mappings ().lookup_hir_implitem (ref)) { if (!lookup->has_substitutions_defined ()) - return CompileInherentImplItem::Compile (resolved_item, ctx, + return CompileInherentImplItem::Compile (resolved_item->first, ctx, nullptr, true, expr_locus); else - return CompileInherentImplItem::Compile (resolved_item, ctx, lookup, - true, expr_locus); + return CompileInherentImplItem::Compile (resolved_item->first, ctx, + lookup, true, expr_locus); } else { diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc index 0b6d945..261e844 100644 --- a/gcc/rust/backend/rust-mangle-v0.cc +++ b/gcc/rust/backend/rust-mangle-v0.cc @@ -384,17 +384,15 @@ v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, auto hir_id = hid.value (); - HirId parent_impl_id = UNKNOWN_HIRID; - HIR::ImplItem *impl_item - = mappings.lookup_hir_implitem (hir_id, &parent_impl_id); HIR::Expr *expr = mappings.lookup_hir_expr (hir_id); - if (impl_item != nullptr) + if (auto impl_item = mappings.lookup_hir_implitem (hir_id)) { - switch (impl_item->get_impl_item_type ()) + switch (impl_item->first->get_impl_item_type ()) { case HIR::ImplItem::FUNCTION: { - HIR::Function *fn = static_cast (impl_item); + HIR::Function *fn + = static_cast (impl_item->first); v0path = v0_function_path (v0path, ctx, ty, fn->get_generic_params (), v0_identifier (seg.get ())); -- cgit v1.1