From: AhmedSaid3617 Date: Sat, 11 Apr 2026 09:35:56 +0000 (+0200) Subject: gccrs: Fixed glob-import all ICE X-Git-Tag: basepoints/gcc-17~149 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=151e5468f2aa94f29eb88698fda7e3085b87493d;p=thirdparty%2Fgcc.git gccrs: Fixed glob-import all ICE Modified toplevel name resolver to recognize use ::*; and use *; as valid import statements, to prevent ICE. gcc/rust/ChangeLog: * ast/rust-item.h:(PathType::get_glob_type): Added const qualifier to allow function call from const objects. * resolve/rust-forever-stack.hxx: (ForeverStack::resolve_path): Check for empty segments vector and return starting point. * resolve/rust-toplevel-name-resolver-2.0.cc (flatten_glob): Preserve the opening scope resolution property of the use statement. Signed-off-by: AhmedSaid3617 --- diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 91c52d2cc70..0724638f210 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1078,7 +1078,7 @@ public: void accept_vis (ASTVisitor &vis) override; - PathType get_glob_type () { return glob_type; } + PathType get_glob_type () const { return glob_type; } Kind get_kind () const override { return Glob; } diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index e8f4e8449b3..c7f90ae3a21 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -729,21 +729,24 @@ ForeverStack::resolve_path ( } else { - rust_assert (!path.get_segments ().empty ()); + switch (mode) + { + case ResolutionMode::Normal: + break; // default + case ResolutionMode::FromRoot: + starting_point = root; + break; + case ResolutionMode::FromExtern: + starting_point = extern_prelude; + break; + default: + rust_unreachable (); + } } - switch (mode) + if (path.get_segments ().empty ()) { - case ResolutionMode::Normal: - break; // default - case ResolutionMode::FromRoot: - starting_point = root; - break; - case ResolutionMode::FromExtern: - starting_point = extern_prelude; - break; - default: - rust_unreachable (); + return Rib::Definition::NonShadowable (starting_point.get ().id); } auto &segments = path.get_segments (); diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 630b5ab8b95..84961ae2e59 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -504,7 +504,9 @@ flatten_glob (const AST::UseTreeGlob &glob, std::vector &paths, if (glob.has_path ()) paths.emplace_back (glob.get_path ()); else - paths.emplace_back (AST::SimplePath ({}, false, glob.get_locus ())); + paths.emplace_back (AST::SimplePath ( + {}, glob.get_glob_type () == AST::UseTreeGlob::PathType::GLOBAL, + glob.get_locus ())); } static bool