public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8607] gccrs: ast: Unify explicitly and implicitly elided lifettimes
@ 2024-01-30 12:01 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-30 12:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:50f305926810ca9ac9efacd6daeebad01f0cd68b

commit r14-8607-g50f305926810ca9ac9efacd6daeebad01f0cd68b
Author: Jakub Dupak <dev@jakubdupak.com>
Date:   Sun Dec 3 12:25:23 2023 +0100

    gccrs: ast: Unify explicitly and implicitly elided lifettimes
    
    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 <dev@jakubdupak.com>

Diff:
---
 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 b193c67c69e5..a45085489e82 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 1637367791cf..91a9d2f5999a 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<TypeNoBounds> 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 90bc2e214e47..0e2cfce1e19c 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -3470,8 +3470,6 @@ Parser<ManagedTokenSource>::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<ManagedTokenSource>::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<ManagedTokenSource>::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<std::unique_ptr<AST::Param>, ParseSelfError>
 Parser<ManagedTokenSource>::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<AST::ReferenceType>
 Parser<ManagedTokenSource>::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 ();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-30 12:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 12:01 [gcc r14-8607] gccrs: ast: Unify explicitly and implicitly elided lifettimes Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).