Skip to content

Commit c7a9640

Browse files
committed
Improve handling of non-final path segments
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::resolve_segments): Remove usage of optional reference, allow non-final path segments to resolve to types even outside the type namespace, and allow resolution to progress past non-final path segments which resolve to modules. gcc/testsuite/ChangeLog: * rust/compile/use_3.rs: New test. Signed-off-by: Owen Avery <[email protected]>
1 parent 5b7a0d7 commit c7a9640

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

gcc/rust/resolve/rust-forever-stack.hxx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ ForeverStack<N>::resolve_segments (
531531
|| seg.is_lower_self_seg ()))
532532
return tl::nullopt;
533533

534-
tl::optional<typename ForeverStack<N>::Node &> child = tl::nullopt;
534+
Node *child = nullptr;
535535

536536
/*
537537
* On every iteration this loop either
@@ -573,20 +573,27 @@ ForeverStack<N>::resolve_segments (
573573
},
574574
false))
575575
{
576-
child = kv.second;
576+
child = &kv.second;
577577
break;
578578
}
579579
}
580580

581-
if (child.has_value ())
581+
if (child)
582582
{
583583
break;
584584
}
585585

586-
if (N == Namespace::Types)
586+
auto rib_lookup = current_node->rib.get (seg.as_string ());
587+
if (rib_lookup && !rib_lookup->is_ambiguous ())
587588
{
588-
auto rib_lookup = current_node->rib.get (seg.as_string ());
589-
if (rib_lookup && !rib_lookup->is_ambiguous ())
589+
if (Analysis::Mappings::get ()
590+
.lookup_glob_container (rib_lookup->get_node_id ())
591+
.has_value ())
592+
{
593+
child = &dfs_node (root, rib_lookup->get_node_id ()).value ();
594+
break;
595+
}
596+
else
590597
{
591598
insert_segment_resolution (outer_seg,
592599
rib_lookup->get_node_id ());
@@ -611,9 +618,9 @@ ForeverStack<N>::resolve_segments (
611618
current_node = &current_node->parent.value ();
612619
}
613620

614-
// if child didn't contain a value
615-
// the while loop above should have return'd or kept looping
616-
current_node = &child.value ();
621+
// if child didn't point to a value
622+
// the while loop above would have returned or kept looping
623+
current_node = child;
617624
insert_segment_resolution (outer_seg, current_node->id);
618625
}
619626

gcc/testsuite/rust/compile/use_3.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mod intrinsic {
2+
pub fn foo() {}
3+
}
4+
5+
pub mod a {
6+
pub fn b() {
7+
use crate::intrinsic;
8+
intrinsic::foo();
9+
}
10+
}

0 commit comments

Comments
 (0)