diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index a1306463e250..56949e4657cd 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -2014,7 +2014,7 @@ TokenCollector::visit (SelfParam ¶m) if (param.has_type ()) { push (Rust::Token::make (COLON, UNDEF_LOCATION)); - visit (param.get_type ()); + visit (param.get_type ().value ()); } } diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index 7d418989c049..fd2129d653d3 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -409,6 +409,12 @@ class DefaultASTVisitor : public ASTVisitor node->accept_vis (*this); } + template void visit (tl::optional 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); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index f6b29130cb8a..937559f5339b 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -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 get_type () { - rust_assert (has_type ()); - return *type; + return has_type () ? tl::optional (*type) : tl::optional (); } std::unique_ptr &get_type_ptr () diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 33fb64f0ff2d..640a1f0dcad6 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -2697,7 +2697,7 @@ CfgStrip::visit (AST::SelfParam ¶m) 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"); } diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 272de0f87172..8fd6f15f53a0 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -674,7 +674,7 @@ ASTLoweringBase::lower_self (AST::Param ¶m) 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 (type), self.get_is_mut (), self.get_locus ()); } diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index bf47c73495c8..5bb0798e9920 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -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 { @@ -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 { @@ -536,7 +536,7 @@ ResolveItem::visit (AST::Function &function) { auto ¶m = static_cast (*p); if (param.has_type ()) - ResolveType::go (param.get_type ()); + ResolveType::go (param.get_type ().value ()); } else { diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 7118b70d7058..c2012fab1f09 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -364,7 +364,7 @@ class ResolveStmt : public ResolverBase else if (p->is_self ()) { auto ¶m = static_cast (*p); - ResolveType::go (param.get_type ()); + ResolveType::go (param.get_type ().value ()); } else {