aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2025-01-04 14:59:54 -0500
committerCohenArthur <arthur.cohen@embecosm.com>2025-02-03 11:44:49 +0000
commit668c3bf7b7b45f8cea7a09515b6420cece877881 (patch)
tree2d7394f4c305d28719615b6d84293337b388fbb9 /gcc/rust/resolve/rust-early-name-resolver-2.0.cc
parenta4a3183322dc195b3f235618d28ddca3e320a5fa (diff)
downloadgcc-668c3bf7b7b45f8cea7a09515b6420cece877881.zip
gcc-668c3bf7b7b45f8cea7a09515b6420cece877881.tar.gz
gcc-668c3bf7b7b45f8cea7a09515b6420cece877881.tar.bz2
Fix bug in type resolution of paths
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Use NameResolutionContext::resolve_path instead of ForeverStack::resolve_path. (Early::visit): Likewise. (Early::visit_attributes): Likewise. * resolve/rust-early-name-resolver-2.0.h (Early::resolve_path_in_all_ns): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise, insert segment resolutions not handled by NameResolutionContext::resolve_path, and avoid throwing an error when path resolution could be finished by the typechecker. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Add. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Use segment node ids instead of the path node id to look up segment resolutions when using the 2.0 resolver, as is done with the 1.0 resolver. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * resolve/rust-forever-stack.h (ForeverStack::resolve_path): Add callback parameter for inserting segment resolutions. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. * resolve/rust-forever-stack.hxx (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise and avoid resolving inside TraitOrImpl ribs. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/resolve/rust-early-name-resolver-2.0.cc')
-rw-r--r--gcc/rust/resolve/rust-early-name-resolver-2.0.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
index ae02a17..cdd8d16 100644
--- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc
@@ -74,7 +74,8 @@ Early::go (AST::Crate &crate)
bool
Early::resolve_glob_import (NodeId use_dec_id, TopLevel::ImportKind &&glob)
{
- auto resolved = ctx.types.resolve_path (glob.to_resolve.get_segments ());
+ auto resolved
+ = ctx.resolve_path (glob.to_resolve.get_segments (), Namespace::Types);
if (!resolved.has_value ())
return false;
@@ -259,7 +260,7 @@ Early::visit (AST::MacroInvocation &invoc)
// we won't have changed `definition` from `nullopt` if there are more
// than one segments in our path
if (!definition.has_value ())
- definition = ctx.macros.resolve_path (path.get_segments ());
+ definition = ctx.resolve_path (path.get_segments (), Namespace::Macros);
// if the definition still does not have a value, then it's an error
if (!definition.has_value ())
@@ -300,8 +301,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
auto traits = attr.get_traits_to_derive ();
for (auto &trait : traits)
{
- auto definition
- = ctx.macros.resolve_path (trait.get ().get_segments ());
+ auto definition = ctx.resolve_path (trait.get ().get_segments (),
+ Namespace::Macros);
if (!definition.has_value ())
{
// FIXME: Change to proper error message
@@ -324,8 +325,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
->lookup_builtin (name)
.is_error ()) // Do not resolve builtins
{
- auto definition
- = ctx.macros.resolve_path (attr.get_path ().get_segments ());
+ auto definition = ctx.resolve_path (attr.get_path ().get_segments (),
+ Namespace::Macros);
if (!definition.has_value ())
{
// FIXME: Change to proper error message