aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse.h
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-11-15 13:02:28 +0100
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-11-21 09:19:08 +0000
commitd2f2f68a8d9d3ce71e97fb586318445d7e7cd984 (patch)
tree4e5c221a7f334bf8ce49554925cf3303fe28b967 /gcc/rust/parse/rust-parse.h
parent6f8b0ffd7667c81af7798c5c02eb24f7b2a79bd5 (diff)
downloadgcc-d2f2f68a8d9d3ce71e97fb586318445d7e7cd984.zip
gcc-d2f2f68a8d9d3ce71e97fb586318445d7e7cd984.tar.gz
gcc-d2f2f68a8d9d3ce71e97fb586318445d7e7cd984.tar.bz2
Report self parameter parsing error kind
Self parameter parsing errors may come from different situations, which should not be handled in the same way. It is now possible to differentiate a missing self parameter from a self pointer or a parsing error. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Early return on unrecoverable errors. (Parser::parse_trait_item): Likewise. (Parser::parse_self_param): Update return type. * parse/rust-parse.h (enum ParseSelfError): Add enumeration to describe different self parameter parsing errors. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/parse/rust-parse.h')
-rw-r--r--gcc/rust/parse/rust-parse.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 08e6ce0..e873d52 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -22,6 +22,8 @@ along with GCC; see the file COPYING3. If not see
#include "rust-ast-full.h"
#include "rust-diagnostics.h"
+#include "expected.h"
+
namespace Rust {
/* HACK: used to resolve the expression-or-statement problem at the end of a
* block by allowing either to be returned (technically). Tagged union would
@@ -93,6 +95,12 @@ struct ParseRestrictions
bool allow_close_after_expr_stmt = false;
};
+enum ParseSelfError
+{
+ SELF_PTR,
+ PARSING,
+ NOT_SELF,
+};
// Parser implementation for gccrs.
// TODO: if updated to C++20, ManagedTokenSource would be useful as a concept
template <typename ManagedTokenSource> class Parser
@@ -335,7 +343,9 @@ private:
parse_trait_type (AST::AttrVec outer_attrs, AST::Visibility);
std::unique_ptr<AST::TraitItemConst>
parse_trait_const (AST::AttrVec outer_attrs);
- std::unique_ptr<AST::Param> parse_self_param ();
+
+ tl::expected<std::unique_ptr<AST::Param>, ParseSelfError> parse_self_param ();
+
std::unique_ptr<AST::Impl> parse_impl (AST::Visibility vis,
AST::AttrVec outer_attrs);
std::unique_ptr<AST::InherentImplItem>