https://gcc.gnu.org/g:77ab427e314a21383f71b30116acaf68f1234b89
commit r17-1881-g77ab427e314a21383f71b30116acaf68f1234b89 Author: Arthur Cohen <[email protected]> Date: Wed Jun 3 11:25:11 2026 +0200 gccrs: nr: Add lookup(ns1, ns2, ns3) Which enables looking up resolved nodes in three different namespaces. This is used in select cases but still important. gcc/rust/ChangeLog: * resolve/rust-finalized-name-resolution-context.cc (FinalizedNameResolutionContext::lookup): New function. * resolve/rust-finalized-name-resolution-context.h: Declare it. * resolve/rust-name-resolution-context.cc (NameResolutionContext::lookup): New function. * resolve/rust-name-resolution-context.h: Declare it. Diff: --- gcc/rust/resolve/rust-finalized-name-resolution-context.cc | 7 +++++++ gcc/rust/resolve/rust-finalized-name-resolution-context.h | 2 ++ gcc/rust/resolve/rust-name-resolution-context.cc | 12 ++++++++++++ gcc/rust/resolve/rust-name-resolution-context.h | 2 ++ 4 files changed, 23 insertions(+) diff --git a/gcc/rust/resolve/rust-finalized-name-resolution-context.cc b/gcc/rust/resolve/rust-finalized-name-resolution-context.cc index 71d1269f3131..8e6600a49a01 100644 --- a/gcc/rust/resolve/rust-finalized-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-finalized-name-resolution-context.cc @@ -83,6 +83,13 @@ FinalizedNameResolutionContext::lookup (NodeId usage, Namespace ns1, return ctx.lookup (usage, ns1, ns2); } +tl::optional<NameResolutionContext::NSLookup> +FinalizedNameResolutionContext::lookup (NodeId usage, Namespace ns1, + Namespace ns2, Namespace ns3) const +{ + return ctx.lookup (usage, ns1, ns2, ns3); +} + Resolver::CanonicalPath FinalizedNameResolutionContext::to_canonical_path (NodeId id, Namespace ns) const diff --git a/gcc/rust/resolve/rust-finalized-name-resolution-context.h b/gcc/rust/resolve/rust-finalized-name-resolution-context.h index 5f3354936268..3bfba3bc0196 100644 --- a/gcc/rust/resolve/rust-finalized-name-resolution-context.h +++ b/gcc/rust/resolve/rust-finalized-name-resolution-context.h @@ -71,6 +71,8 @@ public: tl::optional<NodeId> lookup (NodeId usage, Namespace ns) const; tl::optional<NameResolutionContext::NSLookup> lookup (NodeId usage, Namespace ns1, Namespace ns2) const; + tl::optional<NameResolutionContext::NSLookup> + lookup (NodeId usage, Namespace ns1, Namespace ns2, Namespace ns3) const; /** * Same as NameResolutionContext::to_canonical_path diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index 7bb74b7e5208..e05c1c665d4f 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -315,6 +315,18 @@ NameResolutionContext::lookup (NodeId usage, Namespace ns1, Namespace ns2) const }); } +tl::optional<NameResolutionContext::NSLookup> +NameResolutionContext::lookup (NodeId usage, Namespace ns1, Namespace ns2, + Namespace ns3) const +{ + if (auto result = lookup (usage, ns1, ns2)) + return result; + + return lookup (usage, ns3).map ([&ns3] (NodeId id) { + return NSLookup (id, ns3); + }); +} + void NameResolutionContext::scoped (Rib::Kind rib_kind, NodeId id, std::function<void (void)> lambda, diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index 779f6a725da8..6cbcfbb7655e 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -553,6 +553,8 @@ public: */ tl::optional<NSLookup> lookup (NodeId usage, Namespace ns1, Namespace ns2) const; + tl::optional<NSLookup> lookup (NodeId usage, Namespace ns1, Namespace ns2, + Namespace ns3) const; Resolver::CanonicalPath to_canonical_path (NodeId id, Namespace ns) const {
