From 199b540046fa211d836b3f2246fd9973b4b14067 Mon Sep 17 00:00:00 2001 From: Liam Naddell Date: Tue, 11 Feb 2025 16:42:41 -0500 Subject: 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 --- gcc/rust/resolve/rust-name-resolution-context.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gcc/rust/resolve/rust-name-resolution-context.cc') diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index 38994fe..35befc1 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -113,6 +113,7 @@ NameResolutionContext::scoped (Rib::Kind rib_kind, NodeId id, std::function lambda, tl::optional path) { + // NOTE: You must be at the root node when pushing the prelude rib. values.push (rib_kind, id, path); types.push (rib_kind, id, path); macros.push (rib_kind, id, path); @@ -132,6 +133,9 @@ NameResolutionContext::scoped (Rib::Kind rib_kind, Namespace ns, std::function lambda, tl::optional path) { + // This could work... I'm not sure why you would want to do this though. + rust_assert (rib_kind != Rib::Kind::Prelude); + switch (ns) { case Namespace::Values: -- cgit v1.1