Skip to content

Improve handling of non-final path segments #4063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions gcc/rust/resolve/rust-forever-stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ ForeverStack<N>::resolve_segments (
|| seg.is_lower_self_seg ()))
return tl::nullopt;

tl::optional<typename ForeverStack<N>::Node &> child = tl::nullopt;
tl::optional<std::reference_wrapper<Node>> child = tl::nullopt;

/*
* On every iteration this loop either
Expand Down Expand Up @@ -583,10 +583,17 @@ ForeverStack<N>::resolve_segments (
break;
}

if (N == Namespace::Types)
auto rib_lookup = current_node->rib.get (seg.as_string ());
if (rib_lookup && !rib_lookup->is_ambiguous ())
{
auto rib_lookup = current_node->rib.get (seg.as_string ());
if (rib_lookup && !rib_lookup->is_ambiguous ())
if (Analysis::Mappings::get ()
.lookup_glob_container (rib_lookup->get_node_id ())
.has_value ())
{
child = dfs_node (root, rib_lookup->get_node_id ()).value ();
break;
}
else
{
insert_segment_resolution (outer_seg,
rib_lookup->get_node_id ());
Expand All @@ -611,9 +618,9 @@ ForeverStack<N>::resolve_segments (
current_node = &current_node->parent.value ();
}

// if child didn't contain a value
// the while loop above should have return'd or kept looping
current_node = &child.value ();
// if child didn't point to a value
// the while loop above would have returned or kept looping
current_node = &child->get ();
insert_segment_resolution (outer_seg, current_node->id);
}

Expand Down
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/use_3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod intrinsic {
pub fn foo() {}
}

pub mod a {
pub fn b() {
use crate::intrinsic;
intrinsic::foo();
}
}
Loading