From: AhmedSaid3617 <[email protected]>
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<N>::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 <[email protected]>
---
gcc/rust/ast/rust-item.h | 2 +-
gcc/rust/resolve/rust-forever-stack.hxx | 27 ++++++++++---------
.../rust-toplevel-name-resolver-2.0.cc | 4 ++-
3 files changed, 19 insertions(+), 14 deletions(-)
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<N>::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<AST::SimplePath> &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
--
2.50.1