From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id B02873858038; Tue, 30 Jan 2024 12:01:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B02873858038 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706616087; bh=fZlyhEgEBlr3GMFuL35UEA5Oz4zzUkl8nNHMACsKT5I=; h=From:To:Subject:Date:From; b=s3EIpcsE3evvWCLwxUBMaEm8rRrfjS7jaGFZU6Gd4N9dGG3e7Syv2vwMrwVt4bp/M ZbopaLgT0XucwLklJWUj4HHiXBfCDNq9qjQwXMJazjhyMYyY9aOfPlFOjPV2uxCgeF N6uT3KTWcWOTg0Yo45rJAqyhbYcZFEW1z/MKajhI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8608] gccrs: ast: Full lifetime elision handling X-Act-Checkin: gcc X-Git-Author: Jakub Dupak X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 50f305926810ca9ac9efacd6daeebad01f0cd68b X-Git-Newrev: 6def638e66df549ad3885c2888a7fce9b0552670 Message-Id: <20240130120127.B02873858038@sourceware.org> Date: Tue, 30 Jan 2024 12:01:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6def638e66df549ad3885c2888a7fce9b0552670 commit r14-8608-g6def638e66df549ad3885c2888a7fce9b0552670 Author: Jakub Dupak Date: Sun Dec 3 12:28:07 2023 +0100 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 Diff: --- gcc/rust/parse/rust-parse-impl.h | 25 +++++++++++++------------ gcc/rust/parse/rust-parse.h | 2 +- 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 0e2cfce1e19c..dfa2762c5c3e 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3099,7 +3099,7 @@ Parser::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 std::unique_ptr Parser::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::parse_type_param_bound () { case LIFETIME: return std::unique_ptr ( - new AST::Lifetime (parse_lifetime ())); + new AST::Lifetime (parse_lifetime (false))); case LEFT_PAREN: case QUESTION_MARK: case FOR: @@ -4075,7 +4075,7 @@ Parser::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::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::parse_lifetime_bounds (EndTokenPred is_end_token) * existing. */ template AST::Lifetime -Parser::parse_lifetime () +Parser::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::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::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::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::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 ( @@ -9838,7 +9839,7 @@ Parser::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 4291e4198a5f..3fc86206de7c 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -303,7 +303,7 @@ private: std::vector parse_lifetime_bounds (); template std::vector 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 parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);