Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid visiting nonexistant function parameter types during nr2.0 #3168

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading