Skip to content

Commit 4f772da

Browse files
powerboat9P-E-P
authored andcommitted
Small improvements to DefaultASTVisitor and nr2.0
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Only visit the path of an instance of Visibility if the instance has a path. * ast/rust-ast.h (SimplePath::SimplePath): Make sure constructors are explicit. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Pass entire paths to NameResolutionContext::resolve_path. (Early::visit): Likewise and avoid copying a path. * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Assert that at least one path segment has been passed in. Signed-off-by: Owen Avery <[email protected]>
1 parent 7a562bc commit 4f772da

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

gcc/rust/ast/rust-ast-visitor.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ DefaultASTVisitor::visit (AST::TypeBoundWhereClauseItem &item)
755755
void
756756
DefaultASTVisitor::visit (AST::Visibility &vis)
757757
{
758-
visit (vis.get_path ());
758+
if (vis.has_path ())
759+
visit (vis.get_path ());
759760
}
760761

761762
void

gcc/rust/ast/rust-ast.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,15 @@ class SimplePath
403403

404404
public:
405405
// Constructor
406-
SimplePath (std::vector<SimplePathSegment> path_segments,
407-
bool has_opening_scope_resolution = false,
408-
location_t locus = UNDEF_LOCATION)
406+
explicit SimplePath (std::vector<SimplePathSegment> path_segments,
407+
bool has_opening_scope_resolution = false,
408+
location_t locus = UNDEF_LOCATION)
409409
: opening_scope_resolution (has_opening_scope_resolution),
410410
segments (std::move (path_segments)), locus (locus),
411411
node_id (Analysis::Mappings::get ().get_next_node_id ())
412412
{}
413413

414-
SimplePath (Identifier ident)
414+
explicit SimplePath (Identifier ident)
415415
: opening_scope_resolution (false),
416416
segments ({SimplePathSegment (ident.as_string (), ident.get_locus ())}),
417417
locus (ident.get_locus ()),

gcc/rust/resolve/rust-early-name-resolver-2.0.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ Early::visit (AST::Module &module)
249249
void
250250
Early::visit (AST::MacroInvocation &invoc)
251251
{
252-
auto path = invoc.get_invoc_data ().get_path ();
252+
auto &path = invoc.get_invoc_data ().get_path ();
253253

254254
if (invoc.get_kind () == AST::MacroInvocation::InvocKind::Builtin)
255255
for (auto &pending_invoc : invoc.get_pending_eager_invocations ())
@@ -272,7 +272,7 @@ Early::visit (AST::MacroInvocation &invoc)
272272
// we won't have changed `definition` from `nullopt` if there are more
273273
// than one segments in our path
274274
if (!definition.has_value ())
275-
definition = ctx.resolve_path (path.get_segments (), Namespace::Macros);
275+
definition = ctx.resolve_path (path, Namespace::Macros);
276276

277277
// if the definition still does not have a value, then it's an error
278278
if (!definition.has_value ())
@@ -314,8 +314,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
314314
auto traits = attr.get_traits_to_derive ();
315315
for (auto &trait : traits)
316316
{
317-
auto definition = ctx.resolve_path (trait.get ().get_segments (),
318-
Namespace::Macros);
317+
auto definition
318+
= ctx.resolve_path (trait.get (), Namespace::Macros);
319319
if (!definition.has_value ())
320320
{
321321
// FIXME: Change to proper error message
@@ -337,8 +337,8 @@ Early::visit_attributes (std::vector<AST::Attribute> &attrs)
337337
->lookup_builtin (name)
338338
.is_error ()) // Do not resolve builtins
339339
{
340-
auto definition = ctx.resolve_path (attr.get_path ().get_segments (),
341-
Namespace::Macros);
340+
auto definition
341+
= ctx.resolve_path (attr.get_path (), Namespace::Macros);
342342
if (!definition.has_value ())
343343
{
344344
// FIXME: Change to proper error message

gcc/rust/resolve/rust-forever-stack.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ ForeverStack<N>::resolve_path (
629629
std::function<void (const S &, NodeId)> insert_segment_resolution,
630630
std::vector<Error> &collect_errors)
631631
{
632-
// TODO: What to do if segments.empty() ?
632+
rust_assert (!segments.empty ());
633633

634634
// handle paths with opening scopes
635635
std::function<void (void)> cleanup_current = [] () {};

0 commit comments

Comments
 (0)