From 079736a9459d6044415b6f4d31fd29222d0ccbc2 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 24 Dec 2024 11:45:25 +0000 Subject: [PATCH] hack: Work around MarkLive for lang items --- gcc/rust/checks/lints/rust-lint-marklive.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index 91550c7a568f..1b3b3d661e50 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -22,6 +22,8 @@ #include "rust-lint-marklive.h" #include "options.h" #include "rust-hir-full.h" +#include "rust-hir-map.h" +#include "rust-hir-path.h" #include "rust-name-resolver.h" #include "rust-immutable-name-resolution-context.h" #include "rust-system.h" @@ -97,17 +99,25 @@ MarkLive::go (HIR::Crate &) void MarkLive::visit (HIR::PathInExpression &expr) { + auto is_lang_item = expr.get_path_kind () == HIR::PathPattern::Kind::LangItem; + // We should iterate every path segment in order to mark the struct which // is used in expression like Foo::bar(), we should mark the Foo alive. - expr.iterate_path_segments ([&] (HIR::PathExprSegment &seg) -> bool { - return visit_path_segment (seg); - }); + if (!is_lang_item) + expr.iterate_path_segments ([&] (HIR::PathExprSegment &seg) -> bool { + return visit_path_segment (seg); + }); // after iterate the path segments, we should mark functions and associated // functions alive. NodeId ast_node_id = expr.get_mappings ().get_nodeid (); NodeId ref_node_id = UNKNOWN_NODEID; - find_ref_node_id (ast_node_id, ref_node_id); + + if (is_lang_item) + ref_node_id = *Analysis::Mappings::get ().lookup_lang_item_node ( + expr.get_lang_item_kind ()); + else + find_ref_node_id (ast_node_id, ref_node_id); // node back to HIR tl::optional hid = mappings.lookup_node_to_hir (ref_node_id);