From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 2252A385803A for ; Tue, 30 Jan 2024 12:11:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2252A385803A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2252A385803A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616762; cv=none; b=OmkD4HzC26UoQARS9tp1PZgpQeO8bPxJeL1pHe2Lo3n9upXnufe0kewd32lLw+kRNOJK35yXjghED3YySRsqEJIwG9W7GgCo3NnL73oaBzln6pdTKPuqi5N8hpW4pFQFxusMO6Baab0apmuOgY+UGsbpHlO2xQAkZguFSDeG6go= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616762; c=relaxed/simple; bh=WQeaKoMZ0XC9Duhk/KKrzQ1d+2MTz0jXu3xHclgxsYQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UsAJU3T4EULAun0uxGY5xYEgqZXXnzSlo+bfxo7IVXzxj2aT8k0wzX/6+axROwLgG2cdl9ScIkOoG7wZwEwz1AP0CLbH0rqhw0nB4cGj2gV/ICFljtDpPNhXtJLIGDX2q1eccJxbHWt/iL9PPZfRTFVRm3M1xToeDxKUsfJhvws= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40ed3101ce3so52316565e9.2 for ; Tue, 30 Jan 2024 04:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616711; x=1707221511; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=ab4EMeg2V1GNvrF4isGq5h3MQhKi7yi0KGUuDXlyvfQ=; b=HkBJ9FARAvoPT2E0fnaS3/0mlZA+C8tKhJbkytoX8Z8ApsuZOfv55T25mxNRQZzrVA NTkw9/xD//TvGfRcPEmfG4xvFWM1FGMjBGMghpr/4PbILfJfQCTgXDVEEkigUVpnpuj4 9kGpeyyjFCzEQqmb4z4UaJXdEDCOujuqe7MC9waUbWvTUa5bQRSez9q3fUmO3gbpugyo 7S58LTlsbFK7Zq9eYug130zmmkYSxf8x3BSZcLggUqoHWpKbNlbqhrb83ICHXteKjGKs //YcwF8Z6QTGlrdbp8IcmBvItzpPSrYa9zTUknyH2SDaEulvzY/LAN/FC6QIEYfRdU1r IwDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616711; x=1707221511; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ab4EMeg2V1GNvrF4isGq5h3MQhKi7yi0KGUuDXlyvfQ=; b=Cl9JjDJIICWqspR7+0MKo8mbZyMkKxeKDjfW/x0dnVuI1a5Dp8Wx6+JjBF8HfV8huR uV7CEtVelo1kWdgOCtkG47jI+ViRQBWhEdw7fdXwfl6fZd1roAqSliqmLd0eAdLknsaG ZtrrFrgB26yY2acQYu07Lo3aBCWljytyJcUP6uqZX1gPgO33+X45gSv4PeRkuRTlm6dL fWLbMhG+c1VGGXzFS6m2cLwET2H04d2CfehF1zAXVabjUaqlyLedEfZYypeqjU/zTz2G KzHdQU2UC2FnHEolSHd/aKWhNC5yMHVHaDTzs/V4GMD1ct0oz7wEssByEE4gQ/5Ca9Pf 8vhw== X-Gm-Message-State: AOJu0YwXumdxR7CECkuktcvTrlRyNtqanTc3ZFmcXC0zZ/dTYzTM1lMA gce4Oc9Ltf3zwI1j1uaTld/huAayAMCG2oCwHIcJiGyjuU4+urOqe7ojvERIt1W/dg8fVPWeEB2 yDw== X-Google-Smtp-Source: AGHT+IE1aExu1Tf9kA5nZBXZ0vtnKrY69++DqmnTtU8Ap0PkToC2pkX3bdSkIZjPF1qb+cwnS/6aiw== X-Received: by 2002:a5d:6746:0:b0:337:c4d8:a570 with SMTP id l6-20020a5d6746000000b00337c4d8a570mr5400537wrw.11.1706616710931; Tue, 30 Jan 2024 04:11:50 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:50 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 084/101] gccrs: ast: Full lifetime elision handling Date: Tue, 30 Jan 2024 13:07:40 +0100 Message-ID: <20240130121026.807464-87-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Jakub Dupak 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 --- 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 0e2cfce1e19..dfa2762c5c3 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 4291e4198a5..3fc86206de7 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); -- 2.42.1