aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2025-01-22 20:12:46 -0500
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-24 13:07:03 +0100
commitbbf31f8f5a6da20090ae2a5126854e0cf96b9253 (patch)
tree89e05ffad2b9f47b7f64bfc1762c4d25b8baa66b /gcc/rust/resolve/rust-late-name-resolver-2.0.cc
parentd9a21c1875110711159cc435124493849343532a (diff)
downloadgcc-bbf31f8f5a6da20090ae2a5126854e0cf96b9253.zip
gcc-bbf31f8f5a6da20090ae2a5126854e0cf96b9253.tar.gz
gcc-bbf31f8f5a6da20090ae2a5126854e0cf96b9253.tar.bz2
gccrs: nr2.0: Resolve instances of TypePath more accurately
gcc/rust/ChangeLog: * util/rust-unwrap-segment.cc: New file. * util/rust-unwrap-segment.h: New file. * Make-lang.in: Add rust-unwrap-segment.o to the object list. * resolve/rust-forever-stack.hxx: Include rust-unwrap-segment.h. (ForeverStack::find_starting_point): Use unwrap_type_segment. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Resolve type paths using NameResolutionContext::resolve_path. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Use unwrap_segment_node_id. 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-late-name-resolver-2.0.cc')
-rw-r--r--gcc/rust/resolve/rust-late-name-resolver-2.0.cc31
1 files changed, 11 insertions, 20 deletions
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index 0b591730..c134ca0 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -294,29 +294,20 @@ Late::visit (AST::TypePath &type)
// maybe we can overload `resolve_path<Namespace::Types>` to only do
// typepath-like path resolution? that sounds good
- if (type.get_segments ().size () != 1)
- {
- rust_sorry_at (
- type.get_locus (),
- "name resolution 2.0 cannot resolve multi-segment type paths");
- return;
- }
+ // take care of only simple cases
+ // TODO: remove this?
+ rust_assert (!type.has_opening_scope_resolution_op ());
- auto str = type.get_segments ().back ()->get_ident_segment ().as_string ();
- auto values = ctx.types.peek ().get_values ();
+ // this *should* mostly work
+ // TODO: make sure typepath-like path resolution (?) is working
+ auto resolved = ctx.resolve_path (type.get_segments (), Namespace::Types);
- if (auto resolved = ctx.types.get (str))
- {
- ctx.map_usage (Usage (type.get_node_id ()),
- Definition (resolved->get_node_id ()));
- ctx.map_usage (Usage (type.get_segments ().back ()->get_node_id ()),
- Definition (resolved->get_node_id ()));
- }
+ if (resolved.has_value ())
+ ctx.map_usage (Usage (type.get_node_id ()),
+ Definition (resolved->get_node_id ()));
else
- {
- rust_error_at (type.get_locus (), "could not resolve type path %qs",
- str.c_str ());
- }
+ rust_error_at (type.get_locus (), "could not resolve type path %qs",
+ type.as_string ().c_str ());
DefaultResolver::visit (type);
}