]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ast: Unify explicitly and implicitly elided lifettimes
authorJakub Dupak <dev@jakubdupak.com>
Sun, 3 Dec 2023 11:25:23 +0000 (12:25 +0100)
committerCohenArthur <arthur.cohen@embecosm.com>
Wed, 27 Dec 2023 19:03:10 +0000 (19:03 +0000)
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>
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-type.h
gcc/rust/parse/rust-parse-impl.h

index 8d04be76a5686e68740aef541b84f65b071f85e6..8c2282573c7e45ba417085090f6d7ed1daa1ea17 100644 (file)
@@ -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
   {
index e1ef1b6c4ad9d1b950e9f92f5ed3da5ee10a619a..33c7827a973459ec928c97e1a6b06060d5f5f71e 100644 (file)
@@ -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)
   {}
index 2d835673545b14dd1b7107ac5c50469bc33f0cb0..0b53e57bd8cea13e8bbe3c55473bb0a0cdfd71f5 100644 (file)
@@ -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 ();