Skip to content

Commit

Permalink
Fix name resolution 2.0 definition lookups in unsafe checker
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* checks/errors/rust-unsafe-checker.cc: Add includes.
	(UnsafeChecker::visit): Use 2.0 version of resolver when name
	resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and CohenArthur committed Oct 28, 2024
1 parent c220250 commit 4564a4f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
42 changes: 38 additions & 4 deletions gcc/rust/checks/errors/rust-unsafe-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "rust-hir-item.h"
#include "rust-attribute-values.h"
#include "rust-system.h"
#include "rust-immutable-name-resolution-context.h"

// for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace HIR {
Expand Down Expand Up @@ -216,8 +220,23 @@ UnsafeChecker::visit (PathInExpression &path)
NodeId ast_node_id = path.get_mappings ().get_nodeid ();
NodeId ref_node_id;

if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
return;
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

auto resolved = nr_ctx.lookup (ast_node_id);

if (!resolved.has_value ())
return;

ref_node_id = resolved.value ();
}
else
{
if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
return;
}

if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
{
Expand Down Expand Up @@ -418,8 +437,23 @@ UnsafeChecker::visit (CallExpr &expr)
// There are no unsafe types, and functions are defined in the name resolver.
// If we can't find the name, then we're dealing with a type and should return
// early.
if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
return;
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

auto resolved = nr_ctx.lookup (ast_node_id);

if (!resolved.has_value ())
return;

ref_node_id = resolved.value ();
}
else
{
if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
return;
}

if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
{
Expand Down
6 changes: 0 additions & 6 deletions gcc/testsuite/rust/compile/nr2/exclude
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ traits9.rs
type-bindings1.rs
unconstrained_type_param.rs
undeclared_label.rs
unsafe1.rs
unsafe11.rs
unsafe2.rs
unsafe3.rs
unsafe6.rs
unsafe7.rs
use_1.rs
use_2.rs
v0-mangle1.rs
Expand Down

0 comments on commit 4564a4f

Please sign in to comment.