Commit Message
Arthur Cohen
Aug. 1, 2024, 2:57 p.m. UTC
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> Globbing visitor did not visit subitems. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add a check for missing item. * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go): Add a new function in the visitor to dispatch the visitor to items in the given module. (TopLevel::handle_use_glob): Change call to visitor to use the pointer. * resolve/rust-toplevel-name-resolver-2.0.h: Add prototype for new member function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> --- gcc/rust/resolve/rust-late-name-resolver-2.0.cc | 2 ++ gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 9 ++++++++- gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-)
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 68eb88a1e4c..d8bd9ac524f 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -197,6 +197,8 @@ Late::visit (AST::PathInExpression &expr) // do we emit it in `get<Namespace::Labels>`? auto value = ctx.values.resolve_path (expr.get_segments ()); + if (!value.has_value ()) + rust_unreachable (); // Should have been resolved earlier ctx.map_usage (Usage (expr.get_node_id ()), Definition (*value)); } 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 3122d41412f..501204174f2 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -25,6 +25,13 @@ namespace Rust { namespace Resolver2_0 { +void +GlobbingVisitor::go (AST::Module *module) +{ + for (auto &i : module->get_items ()) + visit (i); +} + void GlobbingVisitor::visit (AST::Module &module) { @@ -399,7 +406,7 @@ TopLevel::handle_use_glob (AST::SimplePath glob) return false; GlobbingVisitor gvisitor (ctx); - gvisitor.visit (*result.value ()); + gvisitor.go (result.value ()); return true; } diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h index 31535a9b22e..f5e224fa049 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h @@ -33,6 +33,7 @@ class GlobbingVisitor : public AST::DefaultASTVisitor public: GlobbingVisitor (NameResolutionContext &ctx) : ctx (ctx) {} + void go (AST::Module *module); void visit (AST::Module &module) override; void visit (AST::MacroRulesDefinition ¯o) override; void visit (AST::Function &function) override;