aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse
diff options
context:
space:
mode:
authorJakub Dupak <dev@jakubdupak.com>2023-12-03 12:28:07 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-30 12:36:51 +0100
commit6def638e66df549ad3885c2888a7fce9b0552670 (patch)
treeac978d1d76743b024e5b86f9332df1cd4d54de32 /gcc/rust/parse
parent50f305926810ca9ac9efacd6daeebad01f0cd68b (diff)
downloadgcc-6def638e66df549ad3885c2888a7fce9b0552670.zip
gcc-6def638e66df549ad3885c2888a7fce9b0552670.tar.gz
gcc-6def638e66df549ad3885c2888a7fce9b0552670.tar.bz2
gccrs: ast: Full lifetime elision handling
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_param): Lifetime elision control. (Parser::parse_lifetime_where_clause_item): Lifetime elision control. (Parser::parse_type_param_bound): Lifetime elision control. (Parser::parse_lifetime_bounds): Lifetime elision control. (Parser::parse_lifetime): Lifetime elision control. (Parser::parse_path_generic_args): Lifetime elision control. (Parser::parse_self_param): Lifetime elision control. (Parser::parse_break_expr): Lifetime elision control. (Parser::parse_continue_expr): Lifetime elision control. (Parser::parse_reference_type_inner): Lifetime elision control. * parse/rust-parse.h: Lifetime elision control. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h25
-rw-r--r--gcc/rust/parse/rust-parse.h2
2 files changed, 14 insertions, 13 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 0e2cfce..dfa2762 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -3099,7 +3099,7 @@ Parser<ManagedTokenSource>::parse_generic_param (EndTokenPred is_end_token)
switch (token->get_id ())
{
case LIFETIME: {
- auto lifetime = parse_lifetime ();
+ auto lifetime = parse_lifetime (false);
if (lifetime.is_error ())
{
rust_error_at (
@@ -3808,7 +3808,7 @@ template <typename ManagedTokenSource>
std::unique_ptr<AST::LifetimeWhereClauseItem>
Parser<ManagedTokenSource>::parse_lifetime_where_clause_item ()
{
- AST::Lifetime lifetime = parse_lifetime ();
+ AST::Lifetime lifetime = parse_lifetime (false);
if (lifetime.is_error ())
{
// TODO: error here?
@@ -4001,7 +4001,7 @@ Parser<ManagedTokenSource>::parse_type_param_bound ()
{
case LIFETIME:
return std::unique_ptr<AST::Lifetime> (
- new AST::Lifetime (parse_lifetime ()));
+ new AST::Lifetime (parse_lifetime (false)));
case LEFT_PAREN:
case QUESTION_MARK:
case FOR:
@@ -4075,7 +4075,7 @@ Parser<ManagedTokenSource>::parse_lifetime_bounds ()
while (true)
{
- AST::Lifetime lifetime = parse_lifetime ();
+ AST::Lifetime lifetime = parse_lifetime (false);
// quick exit for parsing failure
if (lifetime.is_error ())
@@ -4105,7 +4105,7 @@ Parser<ManagedTokenSource>::parse_lifetime_bounds (EndTokenPred is_end_token)
while (!is_end_token (lexer.peek_token ()->get_id ()))
{
- AST::Lifetime lifetime = parse_lifetime ();
+ AST::Lifetime lifetime = parse_lifetime (false);
if (lifetime.is_error ())
{
@@ -4136,12 +4136,13 @@ Parser<ManagedTokenSource>::parse_lifetime_bounds (EndTokenPred is_end_token)
* existing. */
template <typename ManagedTokenSource>
AST::Lifetime
-Parser<ManagedTokenSource>::parse_lifetime ()
+Parser<ManagedTokenSource>::parse_lifetime (bool allow_elided)
{
const_TokenPtr lifetime_tok = lexer.peek_token ();
if (lifetime_tok->get_id () != LIFETIME)
{
- return AST::Lifetime::elided ();
+ return (allow_elided) ? AST::Lifetime::elided ()
+ : AST::Lifetime::error ();
}
lexer.skip_token ();
@@ -6606,7 +6607,7 @@ Parser<ManagedTokenSource>::parse_path_generic_args ()
location_t locus = t->get_locus ();
while (!is_right_angle_tok (t->get_id ()))
{
- AST::Lifetime lifetime = parse_lifetime ();
+ AST::Lifetime lifetime = parse_lifetime (false);
if (lifetime.is_error ())
{
// not necessarily an error
@@ -7227,7 +7228,7 @@ Parser<ManagedTokenSource>::parse_self_param ()
// now test whether it has a lifetime
if (lexer.peek_token ()->get_id () == LIFETIME)
{
- lifetime = parse_lifetime ();
+ lifetime = parse_lifetime (true);
// something went wrong somehow
if (lifetime.is_error ())
@@ -7763,7 +7764,7 @@ Parser<ManagedTokenSource>::parse_break_expr (AST::AttrVec outer_attrs,
AST::Lifetime label = AST::Lifetime::error ();
if (lexer.peek_token ()->get_id () == LIFETIME)
{
- label = parse_lifetime ();
+ label = parse_lifetime (false);
}
// parse break return expression if it exists
@@ -7794,7 +7795,7 @@ Parser<ManagedTokenSource>::parse_continue_expr (AST::AttrVec outer_attrs,
AST::Lifetime label = AST::Lifetime::error ();
if (lexer.peek_token ()->get_id () == LIFETIME)
{
- label = parse_lifetime ();
+ label = parse_lifetime (false);
}
return std::unique_ptr<AST::ContinueExpr> (
@@ -9838,7 +9839,7 @@ Parser<ManagedTokenSource>::parse_reference_type_inner (location_t locus)
AST::Lifetime lifetime = AST::Lifetime::elided ();
if (lexer.peek_token ()->get_id () == LIFETIME)
{
- lifetime = parse_lifetime ();
+ lifetime = parse_lifetime (true);
if (lifetime.is_error ())
{
Error error (lexer.peek_token ()->get_locus (),
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 4291e41..3fc8620 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -303,7 +303,7 @@ private:
std::vector<AST::Lifetime> parse_lifetime_bounds ();
template <typename EndTokenPred>
std::vector<AST::Lifetime> parse_lifetime_bounds (EndTokenPred is_end_token);
- AST::Lifetime parse_lifetime ();
+ AST::Lifetime parse_lifetime (bool allow_elided);
AST::Lifetime lifetime_from_token (const_TokenPtr tok);
std::unique_ptr<AST::ExternalTypeItem>
parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);