From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id B3F613857713 for ; Tue, 30 Jan 2024 12:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3F613857713 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 B3F613857713 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616756; cv=none; b=CUkTMMrKTWGYVi70Tt70Wa1cJf5gF3gqUa2K/M3XMbZk5h/mrRWVvNrzaS5SnNsxb5w6HK4K7v5FVq6aIRuX/IdFrRx2/+N42ddANy2mMUP/8Dlcl/q50cNDQs9MH+DKA++UYKtTIaYH+k09jN180s4qrVKHlJcLVCrTiYfTYNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616756; c=relaxed/simple; bh=B4ADjOzKdm3sYx0AaonWIbwdt6jbi9atqLgpk8PdbCo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HGoLmODq/MP/mhK4/537KsbhiAR+trk42hU4dFW+39IB5YMZlhQkZtA1XcSWKIfP+hG1KikJcajqk/AjqPoZlgSmlBlWFYmUwf/iiJ65o3DWpW0gP1i3lFNKR+dquvOduyPKBrY/ElQ/+DazE2UrhsIZycHV9NNtKMEuJ7gXcNE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33ae42033e2so2236798f8f.1 for ; Tue, 30 Jan 2024 04:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616710; x=1707221510; 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=INjL0mXwk11RZ5qYUshsl68a1MU/pQHo+PS67zkndzA=; b=LXY11vOupJF3dbMyrLbR6r5ZKWJ8S3F6//WxbMVQKMYUtMhS/M2Y7+4nqSNz+9Iw5x WpsIoGQDh6R38LCWVCv9KRVqgHAU5Ov1W+u5EqMlqGbjLDUsEBQ9UfJ0d4eqpdNKmZh1 XvLIsVpgAD4In47rCe9qwUOJWzuRJsLBG+FlKXdQrXjWBBLexaph1GkWuzcGsibD/uVa Ii5w6Ee5SQxVLmDAMpXnprE9O7Zs1/GltFcZQ1IiwooclJoEfH0AMcQQSROqGqrF1RxG nIwc6izW3eOgzm41cjCY5MqWdPxY+RkVRrvs32TTPtdC8mLpz2qMkoeD7vas6ePxgCbh 8AFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616710; x=1707221510; 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=INjL0mXwk11RZ5qYUshsl68a1MU/pQHo+PS67zkndzA=; b=oN7Yt3WZnx/f83qoUy8z3tuOnZO3EfjW5XRQFlgTf4u+iXRui/h++5F4zV/xhLEtiE 9Yeg/nXO9IEz9/ez1ivjfrWw5d3MKx/Xf7MGw5TeJkKws7ONW9UhAipCUkjG+2aMur0E Nxux/bQqM0I5s0/xImbGITcu6jVsn4DThTouELHOxqp2Odx/MWTsTSQpPV9OjvCm12SX 8ZBes8jS5CVH02v3jmd4x24LmbztwXryiJ2OKNZTfMerCE7NwyBDvcOAg3G0+oaCcETJ fI2XhMnSJtQYX7q2Ty+aTZLaaUDyjRmn2y/c5zy/4F/XDi7sEJkN5h581s2tlNVQNWTA c9fw== X-Gm-Message-State: AOJu0Ywmqb47fTidZC/9Jr7qsnuvJ63dXyhwQxqKBJUsPfxX+kP8UdXb kFf8V2NE9X/WSP8nSKRccobvFGosyC+Ale5g7TLcJMSkEItg1qSkWPPgYJB8qA== X-Google-Smtp-Source: AGHT+IGlUEnYmL0/iWvJBaQdZN8pHWpG8rDTo0oaO5KY1oix5mgNHD2jONe8J4oRJlL52nGaluNGdg== X-Received: by 2002:a5d:588a:0:b0:33a:f41e:f68b with SMTP id n10-20020a5d588a000000b0033af41ef68bmr4261432wrf.25.1706616710525; 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 083/101] gccrs: ast: Unify explicitly and implicitly elided lifettimes Date: Tue, 30 Jan 2024 13:07:39 +0100 Message-ID: <20240130121026.807464-86-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: * ast/rust-ast.h: Elided lifetime static constructor * ast/rust-type.h: Default lifetime to elided. * parse/rust-parse-impl.h (Parser::parse_lifetime_param): Use elided lifetime. (Parser::parse_lifetime): Use elided lifetime/ (Parser::lifetime_from_token): Use elided lifetime. (Parser::parse_self_param): Use elided lifetime. (Parser::parse_reference_type_inner): Use elided lifetime. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast.h | 2 ++ gcc/rust/ast/rust-type.h | 2 +- gcc/rust/parse/rust-parse-impl.h | 10 ++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index b193c67c69e..a45085489e8 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1512,6 +1512,8 @@ public: // Creates an "error" lifetime. static Lifetime error () { return Lifetime (NAMED, ""); } + static Lifetime elided () { return Lifetime (WILDCARD, ""); } + // Returns true if the lifetime is in an error state. bool is_error () const { diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 1637367791c..91a9d2f5999 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -547,7 +547,7 @@ public: // Constructor ReferenceType (bool is_mut, std::unique_ptr type_no_bounds, - location_t locus, Lifetime lifetime = Lifetime::error ()) + location_t locus, Lifetime lifetime = Lifetime::elided ()) : lifetime (std::move (lifetime)), has_mut (is_mut), type (std::move (type_no_bounds)), locus (locus) {} diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 90bc2e214e4..0e2cfce1e19 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3470,8 +3470,6 @@ Parser::parse_lifetime_param () return AST::LifetimeParam::create_error (); } lexer.skip_token (); - /* TODO: does this always create a named lifetime? or can a different type - * be made? */ AST::Lifetime lifetime (AST::Lifetime::NAMED, lifetime_tok->get_str (), lifetime_tok->get_locus ()); @@ -4141,10 +4139,9 @@ AST::Lifetime Parser::parse_lifetime () { const_TokenPtr lifetime_tok = lexer.peek_token (); - // create error lifetime if doesn't exist if (lifetime_tok->get_id () != LIFETIME) { - return AST::Lifetime::error (); + return AST::Lifetime::elided (); } lexer.skip_token (); @@ -4164,6 +4161,7 @@ Parser::lifetime_from_token (const_TokenPtr tok) } else if (lifetime_ident == "_") { + // Explicitly and implicitly elided lifetimes follow the same rules. return AST::Lifetime (AST::Lifetime::WILDCARD, "", locus); } else @@ -7177,7 +7175,7 @@ tl::expected, ParseSelfError> Parser::parse_self_param () { bool has_reference = false; - AST::Lifetime lifetime = AST::Lifetime::error (); + AST::Lifetime lifetime = AST::Lifetime::elided (); location_t locus = lexer.peek_token ()->get_locus (); @@ -9837,7 +9835,7 @@ std::unique_ptr Parser::parse_reference_type_inner (location_t locus) { // parse optional lifetime - AST::Lifetime lifetime = AST::Lifetime::error (); + AST::Lifetime lifetime = AST::Lifetime::elided (); if (lexer.peek_token ()->get_id () == LIFETIME) { lifetime = parse_lifetime (); -- 2.42.1