Skip to content

Commit

Permalink
Improve handline of SelfParam with missing type
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.h
	(DefaultASTVisitor::visit): Add overload for tl::optional<T &>.
	* ast/rust-item.h
	(SelfParam::get_type): Return tl::optional<Type &>.

	* ast/rust-ast-collector.cc
	(TokenCollector::visit): Handle changed return type of
	SelfParam::get_type.
	* expand/rust-cfg-strip.cc
	(CfgStrip::visit): Likewise.
	* hir/rust-ast-lower-base.cc
	(ASTLoweringBase::lower_self): Likewise.
	* resolve/rust-ast-resolve-item.cc
	(ResolveTraitItems::visit): Likewise.
	(ResolveItem::visit): Likewise.
	* resolve/rust-ast-resolve-stmt.h
	(ResolveStmt::visit): Likewise.
	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit): Likewise, and properly handle empty
	optional.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
  • Loading branch information
powerboat9 committed Sep 30, 2024
1 parent 409beeb commit 21994e6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ TokenCollector::visit (SelfParam &param)
if (param.has_type ())
{
push (Rust::Token::make (COLON, UNDEF_LOCATION));
visit (param.get_type ());
visit (param.get_type ().value ());
}
}

Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/ast/rust-ast-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ class DefaultASTVisitor : public ASTVisitor
node->accept_vis (*this);
}

template <typename T> void visit (tl::optional<T &> opt)
{
if (opt.has_value ())
visit (opt.value ());
}

virtual void visit (AST::GenericArgsBinding &binding);
virtual void visit (AST::PathExprSegment &segment);
virtual void visit (AST::GenericArgs &args);
Expand Down
5 changes: 2 additions & 3 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,9 @@ class SelfParam : public Param
NodeId get_node_id () const { return node_id; }

// TODO: is this better? Or is a "vis_block" better?
Type &get_type ()
tl::optional<Type &> get_type ()
{
rust_assert (has_type ());
return *type;
return has_type () ? tl::optional<Type &> (*type) : tl::optional<Type &> ();
}

std::unique_ptr<Type> &get_type_ptr ()
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/expand/rust-cfg-strip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ CfgStrip::visit (AST::SelfParam &param)

if (param.has_type ())
{
auto &type = param.get_type ();
auto &type = param.get_type ().value ();
if (type.is_marked_for_strip ())
rust_error_at (type.get_locus (), "cannot strip type in this position");
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/hir/rust-ast-lower-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ ASTLoweringBase::lower_self (AST::Param &param)

if (self.has_type ())
{
HIR::Type *type = ASTLoweringType::translate (self.get_type ());
HIR::Type *type = ASTLoweringType::translate (self.get_type ().value ());
return HIR::SelfParam (mapping, std::unique_ptr<HIR::Type> (type),
self.get_is_mut (), self.get_locus ());
}
Expand Down
6 changes: 3 additions & 3 deletions gcc/rust/resolve/rust-ast-resolve-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ResolveTraitItems::visit (AST::Function &function)
{
// This shouldn't happen the parser should already error for this
rust_assert (!param.get_has_ref ());
ResolveType::go (param.get_type ());
ResolveType::go (param.get_type ().value ());
}
else
{
Expand Down Expand Up @@ -503,7 +503,7 @@ ResolveItem::visit (AST::Function &function)
{
// This shouldn't happen the parser should already error for this
rust_assert (!self_param.get_has_ref ());
ResolveType::go (self_param.get_type ());
ResolveType::go (self_param.get_type ().value ());
}
else
{
Expand Down Expand Up @@ -536,7 +536,7 @@ ResolveItem::visit (AST::Function &function)
{
auto &param = static_cast<AST::SelfParam &> (*p);
if (param.has_type ())
ResolveType::go (param.get_type ());
ResolveType::go (param.get_type ().value ());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/resolve/rust-ast-resolve-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class ResolveStmt : public ResolverBase
else if (p->is_self ())
{
auto &param = static_cast<AST::SelfParam &> (*p);
ResolveType::go (param.get_type ());
ResolveType::go (param.get_type ().value ());
}
else
{
Expand Down

0 comments on commit 21994e6

Please sign in to comment.