From: Arthur Cohen Date: Fri, 12 Sep 2025 14:11:15 +0000 (+0200) Subject: gccrs: nr: Do prelude resolution for Identifiers X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=30e3760e63f10bc511e0976247d44487e514d3ce;p=thirdparty%2Fgcc.git gccrs: nr: Do prelude resolution for Identifiers gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: New function. * resolve/rust-forever-stack.hxx: Implement it. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Call it if the prelude exists and we have an unresolved Identifier Call it if the prelude exists and we have an unresolved Identifier. --- diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 2a88df7b9e0..cca98b55c2a 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -668,6 +668,8 @@ public: tl::optional get (const Identifier &name); tl::optional get_lang_prelude (const Identifier &name); tl::optional get_lang_prelude (const std::string &name); + tl::optional get_from_prelude (NodeId prelude, + const Identifier &name); /** * Resolve a path to its definition in the current `ForeverStack` diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index bd35d6c4e4a..1093646eb4f 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -343,6 +343,17 @@ ForeverStack::get_lang_prelude (const std::string &name) return lang_prelude.rib.get (name); } +template +tl::optional +ForeverStack::get_from_prelude (NodeId prelude, const Identifier &name) +{ + auto starting_point = dfs_node (root, prelude); + if (!starting_point) + return tl::nullopt; + + return get (*starting_point, name); +} + template <> tl::optional inline ForeverStack::get ( const Identifier &name) 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 0da8c38b63e..9a7c2f8a0b6 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -346,7 +346,17 @@ Late::visit (AST::IdentifierExpr &expr) { resolved = type; } - else + else if (!resolved && ctx.prelude) + { + resolved + = ctx.values.get_from_prelude (*ctx.prelude, expr.get_ident ()); + + if (!resolved) + resolved + = ctx.types.get_from_prelude (*ctx.prelude, expr.get_ident ()); + } + + if (!resolved) { rust_error_at (expr.get_locus (), ErrorCode::E0425, "cannot find value %qs in this scope",