Skip to content

Commit

Permalink
Disambiguate generic args during name resolution 2.0
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc
	(Late::visit): Visit GenericArgs and GenericArg, the former
	because the latter involves a non-virtual member function call.
	* resolve/rust-late-name-resolver-2.0.h
	(Late::visit): Likewise.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed Oct 17, 2024
1 parent 6708d35 commit a9931e9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,37 @@ Late::visit (AST::StructExprStructFields &s)
DefaultResolver::visit (s);
}

// needed because Late::visit (AST::GenericArg &) is non-virtual
void
Late::visit (AST::GenericArgs &args)
{
for (auto &lifetime : args.get_lifetime_args ())
visit (lifetime);

for (auto &generic : args.get_generic_args ())
visit (generic);

for (auto &binding : args.get_binding_args ())
visit (binding);
}

void
Late::visit (AST::GenericArg &arg)
{
if (arg.get_kind () == AST::GenericArg::Kind::Either)
{
// prefer type parameter to const parameter on ambiguity
auto type = ctx.types.get (arg.get_path ());
auto value = ctx.values.get (arg.get_path ());

if (!type.has_value () && value.has_value ())
arg = arg.disambiguate_to_const ();
else
arg = arg.disambiguate_to_type ();
}

DefaultResolver::visit (arg);
}

} // namespace Resolver2_0
} // namespace Rust
2 changes: 2 additions & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Late : public DefaultResolver
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
void visit (AST::StructStruct &) override;
void visit (AST::GenericArgs &) override;
void visit (AST::GenericArg &);

private:
/* Setup Rust's builtin types (u8, i32, !...) in the resolver */
Expand Down

0 comments on commit a9931e9

Please sign in to comment.