Skip to content

Commit

Permalink
Use name resolver 2.0 in MarkLive
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* checks/lints/rust-lint-marklive.cc
	(MarkLive::visit_path_segment): Use name resolver 2.0 when
	enabled.
	(MarkLive::visit): Likewise.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed Oct 17, 2024
1 parent 2b74b5c commit 20ef282
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions gcc/rust/checks/lints/rust-lint-marklive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,17 @@ MarkLive::visit_path_segment (HIR::PathExprSegment seg)
//
// We should mark them alive all and ignoring other kind of segments.
// If the segment we dont care then just return false is fine
if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

if (auto id = nr_ctx.lookup (ast_node_id))
ref_node_id = *id;
else
return false;
}
else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
{
if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
return false;
Expand Down Expand Up @@ -232,9 +242,22 @@ MarkLive::visit (HIR::TupleIndexExpr &expr)
void
MarkLive::visit (HIR::TypeAlias &alias)
{
NodeId ast_node_id;
resolver->lookup_resolved_type (
alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id);
NodeId ast_node_id = UNKNOWN_NODEID;
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

if (auto id = nr_ctx.lookup (
alias.get_type_aliased ()->get_mappings ().get_nodeid ()))
ast_node_id = *id;
}
else
{
resolver->lookup_resolved_type (
alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id);
}

if (auto hid = mappings.lookup_node_to_hir (ast_node_id))
mark_hir_id (*hid);
else
Expand Down

0 comments on commit 20ef282

Please sign in to comment.