From patchwork Tue Jan 30 12:07:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 194110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1187140dyb; Tue, 30 Jan 2024 04:35:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWda368vYDtGh2827SrsrwSd4Dqhlrhe6PzxoBPFZr4lK8H2OjLdF2xBGNKXgLN4liVRRV X-Received: by 2002:a0c:fcc5:0:b0:68c:3cbc:f4f9 with SMTP id i5-20020a0cfcc5000000b0068c3cbcf4f9mr5675685qvq.78.1706618115279; Tue, 30 Jan 2024 04:35:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706618115; cv=pass; d=google.com; s=arc-20160816; b=SWe85Fpf8q+tJSXpoTF2EALztbzst+ljCoY9dS9m3cvxa7m2A6jjYJ0o2eVZq41rxZ +D5ZPttfWYdPidu2l1/24HGTx6Nuhhd2mnYCSgUGKROiUlY3YrbJMJ+mujBt6+mDAVR/ ZTh/k3huiSP5mnE+zB9iGs6TTAW24skidX/YCfgHViCfxPD5SH0sfiFNnXae6rDQfyJJ xi0bbKIayVJhuGpT1q8aOCSAkzVKXgD3sAmRWtWgmlkp1qssiicCB/Hln+R+qSk5zOj1 U/MvPbW5MswURFZ809hR+3kvgL6Eg0Nra6K6QAYRMiRJa//vy5h+VL7Sb2zLs74LXz4b IYrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=ab4EMeg2V1GNvrF4isGq5h3MQhKi7yi0KGUuDXlyvfQ=; fh=tF/FjG7igJhcOEGq79wqr3ldeoZUVk5V7TNEGxaLUD4=; b=v8x/8UFzWJh/cOQkypZOE+Eb1e8fHEU7dFvQSW9W77RGq6+3tznjXffOYnQ1pUkXE1 uRxtgxNl34ATq4RhbELtViIjF3xZT9OQciByKs04hC+91gbFIa/kSQJK0GcLmlEMZr4v tOqTHVkW3/tEEr7/7VV/C3LtjuO9G1MClGBuEtHzOzfM/igIB6dVj0mY8g0iu5txmKpO o0xCvTn/paGJi+kMkUPEFFRx64DaMZSou2fy88ieFhyNvVyXxdkxJ7O+fW26JQ1HaO7i /XYuCL0E/HqNB7/zK1aymfSvGvC8gc/svvuXu8DB3HHTjLl4+sN4WFJ67PdteYkdzDoX R+9g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=HkBJ9FAR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id wg19-20020a05620a569300b0078407b4492fsi2100871qkn.19.2024.01.30.04.35.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:35:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=HkBJ9FAR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F09A438319FB for ; Tue, 30 Jan 2024 12:34:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id EE3953857839 for ; Tue, 30 Jan 2024 12:11:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE3953857839 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 EE3953857839 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616763; cv=none; b=g53xaWCYHybwec3oiba8IA0brJoH/qNp2K3ujjsezMTYPVif8yOIt/0ydcxuJvFUmbsFG1Mn7AQaVRqzg/acTD4Navt+gFLSaTR8lwFgk6AjYQwKwiHCu4v2uBrQudwpe+QRFZyYxkeS0MwdNGmO5R17FLTlBtX3L5a79/JG7m8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616763; c=relaxed/simple; bh=WQeaKoMZ0XC9Duhk/KKrzQ1d+2MTz0jXu3xHclgxsYQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MkvI9Pi7Zvl6j2y1qxYlomxJfVywe+kAgDrCU08rAc3Qq21x8M3NDYgsXlEC3QPV0l1nOoDq77SpZ37/d385r1b/dhyZr3cNd89/se0tNvYJIZZcJnmbG3LipVf3BM3Flo4+L7gDBGV1S3FTAedny86D0Wl/Ef2Y0lanEoWGSoc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33aeb088324so1539677f8f.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=aofaq1tpOVmLaCqL1lzQZfdBOoL/eJMA0fb3rA5+iEq6ULV0cr341eiEFEGgFNCdU0 E4/SP+Sn+cu1qNQkYLrYQpkMGS+0JSd3Z2UkU8aLN2A4way1FM3YjusGLw1qXqfhSjsY G73mepxAtAKFZBqhugOUYK8CYr54tXncRmafinOFyizOmFIihEd2UJkVaEwmTdHnNDos 5DHQykxL6BPencXauoTK7eBDyBpe/PV/oMovb7uSXAPIsNI04uyWYPswxgAaJ0BBFy+K fZ4/yt0xg4QsE3QLEG9aqLHA3komfpAvNWb4Cz4wdLHdmEI7MHadinEM9Guh4eGUKD52 pN1Q== X-Gm-Message-State: AOJu0YyL7wRWQ1SI0bVyz0dlsV8z7Wtfa7Y4nX9+aOCqJTcd1x9O9wgs BRGgIQmkhM2pNoIM6hQE89ibL61zdKuNRehBXKRzSYJgPgpp0Fp1EiQGGYWZNUhuKDkIALECqkk rGg== 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> MIME-Version: 1.0 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789518797099444188 X-GMAIL-MSGID: 1789518797099444188 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);