diff options
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-forever-stack.hxx | 20 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 31 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-name-resolution-context.h | 6 |
3 files changed, 26 insertions, 31 deletions
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index f5f0b15..b51da51 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -21,6 +21,7 @@ #include "rust-diagnostics.h" #include "rust-forever-stack.h" #include "rust-rib.h" +#include "rust-unwrap-segment.h" #include "optional.h" namespace Rust { @@ -389,7 +390,8 @@ ForeverStack<N>::find_starting_point ( for (; !is_last (iterator, segments); iterator++) { - auto &seg = *iterator; + auto &outer_seg = *iterator; + auto &seg = unwrap_type_segment (outer_seg); auto is_self_or_crate = seg.is_crate_path_seg () || seg.is_lower_self_seg (); @@ -407,14 +409,14 @@ ForeverStack<N>::find_starting_point ( NodeId current_crate = *mappings.crate_num_to_nodeid (mappings.get_current_crate ()); - insert_segment_resolution (seg, current_crate); + insert_segment_resolution (outer_seg, current_crate); iterator++; break; } if (seg.is_lower_self_seg ()) { // insert segment resolution and exit - insert_segment_resolution (seg, starting_point.get ().id); + insert_segment_resolution (outer_seg, starting_point.get ().id); iterator++; break; } @@ -430,7 +432,7 @@ ForeverStack<N>::find_starting_point ( starting_point = find_closest_module (starting_point.get ().parent.value ()); - insert_segment_resolution (seg, starting_point.get ().id); + insert_segment_resolution (outer_seg, starting_point.get ().id); continue; } @@ -454,7 +456,8 @@ ForeverStack<N>::resolve_segments ( auto *current_node = &starting_point; for (; !is_last (iterator, segments); iterator++) { - auto &seg = *iterator; + auto &outer_seg = *iterator; + auto &seg = unwrap_type_segment (outer_seg); auto str = seg.as_string (); rust_debug ("[ARTHUR]: resolving segment part: %s", str.c_str ()); @@ -490,7 +493,7 @@ ForeverStack<N>::resolve_segments ( } current_node = &child.value (); - insert_segment_resolution (seg, current_node->id); + insert_segment_resolution (outer_seg, current_node->id); } return *current_node; @@ -508,7 +511,7 @@ ForeverStack<N>::resolve_path ( // if there's only one segment, we just use `get` if (segments.size () == 1) { - auto res = get (segments.back ().as_string ()); + auto res = get (unwrap_type_segment (segments.back ()).as_string ()); if (res && !res->is_ambiguous ()) insert_segment_resolution (segments.back (), res->get_node_id ()); return res; @@ -528,7 +531,8 @@ ForeverStack<N>::resolve_path ( // leave resolution within impl blocks to type checker if (final_node.rib.kind == Rib::Kind::TraitOrImpl) return tl::nullopt; - auto res = final_node.rib.get (segments.back ().as_string ()); + auto res = final_node.rib.get ( + unwrap_type_segment (segments.back ()).as_string ()); if (res && !res->is_ambiguous ()) insert_segment_resolution (segments.back (), res->get_node_id ()); return res; 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); } diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index b4d6859..a381411 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -222,9 +222,9 @@ public: { std::function<void (const S &, NodeId)> insert_segment_resolution = [this] (const S &seg, NodeId id) { - if (resolved_nodes.find (Usage (seg.get_node_id ())) - == resolved_nodes.end ()) - map_usage (Usage (seg.get_node_id ()), Definition (id)); + auto seg_id = unwrap_segment_node_id (seg); + if (resolved_nodes.find (Usage (seg_id)) == resolved_nodes.end ()) + map_usage (Usage (seg_id), Definition (id)); }; switch (ns) { |