aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
diff options
context:
space:
mode:
authorLiam Naddell <liamnprg@gmail.com>2025-02-11 16:42:41 -0500
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2025-03-18 13:39:52 +0000
commit199b540046fa211d836b3f2246fd9973b4b14067 (patch)
tree16c47be30f24df8ff896abc478cc53f0ee86e2b8 /gcc/rust/resolve/rust-late-name-resolver-2.0.cc
parent6a4363f83a8454e7f33baa4bf11101cc5ada36ad (diff)
downloadgcc-199b540046fa211d836b3f2246fd9973b4b14067.zip
gcc-199b540046fa211d836b3f2246fd9973b4b14067.tar.gz
gcc-199b540046fa211d836b3f2246fd9973b4b14067.tar.bz2
Fix modules with same name as builtins causing ICE (#3315)
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack): Add a dedicated prelude node for the Language prelude * resolve/rust-forever-stack.hxx (ForeverStack): Add support code for the prelude node * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move language prelude builtins to the prelude context * resolve/rust-name-resolution-context.cc (NameResolutionContext::scoped): Add code for handling the prelude corner case * resolve/rust-rib.h (Rib::Kind): Add a special Prelude rib type gcc/testsuite/ChangeLog: * rust/compile/issue-3315-1.rs: Add test for module with same name as builtin * rust/compile/issue-3315-2.rs: Test with utilization of i32 type * rust/compile/nr2/exclude: issue-3315-2.rs Does not work with NR2.0 Signed-off-by: Liam Naddell <liamnprg@gmail.com>
Diffstat (limited to 'gcc/rust/resolve/rust-late-name-resolver-2.0.cc')
-rw-r--r--gcc/rust/resolve/rust-late-name-resolver-2.0.cc33
1 files changed, 18 insertions, 15 deletions
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 d7bd046..ef09fb0 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -91,16 +91,18 @@ Late::setup_builtin_types ()
// insert it in the type context...
};
- for (const auto &builtin : builtins)
- {
- // we should be able to use `insert_at_root` or `insert` here, since we're
- // at the root :) hopefully!
- auto ok = ctx.types.insert (builtin.name, builtin.node_id);
- rust_assert (ok);
-
- ctx.mappings.insert_node_to_hir (builtin.node_id, builtin.hir_id);
- ty_ctx.insert_builtin (builtin.hir_id, builtin.node_id, builtin.type);
- }
+ // There's a special Rib for putting prelude items, since prelude items need
+ // to satisfy certain special rules.
+ ctx.scoped (Rib::Kind::Prelude, 0, [this, &ty_ctx] (void) -> void {
+ for (const auto &builtin : builtins)
+ {
+ auto ok = ctx.types.insert (builtin.name, builtin.node_id);
+ rust_assert (ok);
+
+ ctx.mappings.insert_node_to_hir (builtin.node_id, builtin.hir_id);
+ ty_ctx.insert_builtin (builtin.hir_id, builtin.node_id, builtin.type);
+ }
+ });
// ...here!
auto *unit_type = TyTy::TupleType::get_unit_type ();
@@ -213,7 +215,6 @@ Late::visit (AST::IdentifierExpr &expr)
// TODO: same thing as visit(PathInExpression) here?
tl::optional<Rib::Definition> resolved = tl::nullopt;
-
if (auto value = ctx.values.get (expr.get_ident ()))
{
resolved = value;
@@ -231,10 +232,12 @@ Late::visit (AST::IdentifierExpr &expr)
}
else
{
- rust_error_at (expr.get_locus (),
- "could not resolve identifier expression: %qs",
- expr.get_ident ().as_string ().c_str ());
- return;
+ if (auto typ = ctx.types.get_prelude (expr.get_ident ()))
+ resolved = typ;
+ else
+ rust_error_at (expr.get_locus (),
+ "could not resolve identifier expression: %qs",
+ expr.get_ident ().as_string ().c_str ());
}
ctx.map_usage (Usage (expr.get_node_id ()),