]> git.ipfire.org Git - people/ms/gcc.git/commitdiff
gccrs: Fix missing move and copy constructors missing the associated-path
authorPhilip Herron <herron.philip@googlemail.com>
Wed, 1 Mar 2023 22:09:47 +0000 (22:09 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Fri, 3 Mar 2023 19:27:24 +0000 (19:27 +0000)
Addresses #1524

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* ast/rust-ast.cc (QualifiedPathInType::as_string): add missing to string
* ast/rust-path.h: add missing copy+move constructors and assignment overloads
* hir/tree/rust-hir-path.h: likewise
* hir/tree/rust-hir.cc (QualifiedPathInType::as_string): add missing to string

gcc/testsuite/ChangeLog:

* rust/compile/parse_associated_type_as_generic_arg.rs: it now works without -fsyntax-only
* rust/compile/parse_associated_type_as_generic_arg2.rs: likewise

gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-path.h
gcc/rust/hir/tree/rust-hir-path.h
gcc/rust/hir/tree/rust-hir.cc
gcc/testsuite/rust/compile/parse_associated_type_as_generic_arg.rs
gcc/testsuite/rust/compile/parse_associated_type_as_generic_arg2.rs

index 3d1b573968f0171f02f0b5b0d428bb6d78b95a03..bb3562a73a3f6c44198003523f90b155b6b3da68 100644 (file)
@@ -2397,6 +2397,7 @@ QualifiedPathInType::as_string () const
    * literalised */
   std::string str = path_type.as_string ();
 
+  str += "::" + associated_segment->as_string ();
   for (const auto &segment : segments)
     str += "::" + segment->as_string ();
 
index b5c9c3aab3a1d59952bd75117f467e7ff46af8ae..5f7c5e35f25855c27ec6bef65162a28c9a51988e 100644 (file)
@@ -202,6 +202,9 @@ public:
     return *this;
   }
 
+  GenericArg (GenericArg &&other) = default;
+  GenericArg &operator= (GenericArg &&other) = default;
+
   bool is_error () const { return kind == Kind::Error; }
 
   Kind get_kind () const { return kind; }
@@ -411,9 +414,16 @@ public:
 
   // copy constructor with vector clone
   GenericArgs (GenericArgs const &other)
-    : lifetime_args (other.lifetime_args), generic_args (other.generic_args),
-      binding_args (other.binding_args), locus (other.locus)
-  {}
+    : lifetime_args (other.lifetime_args), binding_args (other.binding_args),
+      locus (other.locus)
+  {
+    generic_args.clear ();
+    generic_args.reserve (other.generic_args.size ());
+    for (const auto &arg : other.generic_args)
+      {
+       generic_args.push_back (GenericArg (arg));
+      }
+  }
 
   ~GenericArgs () = default;
 
@@ -421,10 +431,16 @@ public:
   GenericArgs &operator= (GenericArgs const &other)
   {
     lifetime_args = other.lifetime_args;
-    generic_args = other.generic_args;
     binding_args = other.binding_args;
     locus = other.locus;
 
+    generic_args.clear ();
+    generic_args.reserve (other.generic_args.size ());
+    for (const auto &arg : other.generic_args)
+      {
+       generic_args.push_back (GenericArg (arg));
+      }
+
     return *this;
   }
 
@@ -672,6 +688,7 @@ protected:
   bool has_separating_scope_resolution;
   NodeId node_id;
 
+public:
   // Clone function implementation - not pure virtual as overrided by
   // subclasses
   virtual TypePathSegment *clone_type_path_segment_impl () const
@@ -705,6 +722,25 @@ public:
       node_id (Analysis::Mappings::get ()->get_next_node_id ())
   {}
 
+  TypePathSegment (TypePathSegment const &other)
+    : ident_segment (other.ident_segment), locus (other.locus),
+      has_separating_scope_resolution (other.has_separating_scope_resolution),
+      node_id (other.node_id)
+  {}
+
+  TypePathSegment &operator= (TypePathSegment const &other)
+  {
+    ident_segment = other.ident_segment;
+    locus = other.locus;
+    has_separating_scope_resolution = other.has_separating_scope_resolution;
+    node_id = other.node_id;
+
+    return *this;
+  }
+
+  TypePathSegment (TypePathSegment &&other) = default;
+  TypePathSegment &operator= (TypePathSegment &&other) = default;
+
   virtual std::string as_string () const { return ident_segment.as_string (); }
 
   /* Returns whether the type path segment is in an error state. May be
@@ -780,6 +816,23 @@ public:
                                 std::move (binding_args)))
   {}
 
+  // Copy constructor with vector clone
+  TypePathSegmentGeneric (TypePathSegmentGeneric const &other)
+    : TypePathSegment (other), generic_args (other.generic_args)
+  {}
+
+  // Overloaded assignment operator with vector clone
+  TypePathSegmentGeneric &operator= (TypePathSegmentGeneric const &other)
+  {
+    generic_args = other.generic_args;
+
+    return *this;
+  }
+
+  // move constructors
+  TypePathSegmentGeneric (TypePathSegmentGeneric &&other) = default;
+  TypePathSegmentGeneric &operator= (TypePathSegmentGeneric &&other) = default;
+
   std::string as_string () const override;
 
   void accept_vis (ASTVisitor &vis) override;
@@ -791,7 +844,6 @@ public:
     return generic_args;
   }
 
-protected:
   // Use covariance to override base class method
   TypePathSegmentGeneric *clone_type_path_segment_impl () const override
   {
@@ -941,7 +993,6 @@ public:
     return function_path;
   }
 
-protected:
   // Use covariance to override base class method
   TypePathSegmentFunction *clone_type_path_segment_impl () const override
   {
@@ -1242,13 +1293,13 @@ public:
       segments (std::move (path_segments)), locus (locus)
   {}
 
-  /* TODO: maybe make a shortcut constructor that has QualifiedPathType
-   * elements as params */
-
   // Copy constructor with vector clone
   QualifiedPathInType (QualifiedPathInType const &other)
     : path_type (other.path_type), locus (other.locus)
   {
+    auto seg = other.associated_segment->clone_type_path_segment_impl ();
+    associated_segment = std::unique_ptr<TypePathSegment> (seg);
+
     segments.reserve (other.segments.size ());
     for (const auto &e : other.segments)
       segments.push_back (e->clone_type_path_segment ());
@@ -1257,6 +1308,9 @@ public:
   // Overloaded assignment operator with vector clone
   QualifiedPathInType &operator= (QualifiedPathInType const &other)
   {
+    auto seg = other.associated_segment->clone_type_path_segment_impl ();
+    associated_segment = std::unique_ptr<TypePathSegment> (seg);
+
     path_type = other.path_type;
     locus = other.locus;
 
index 740de9391a062604673627ed5d02fb85913bddc1..f8a7dab00010dd8f4627d3b8c0de6bc7a51e67f4 100644 (file)
@@ -431,6 +431,7 @@ protected:
   bool has_separating_scope_resolution;
   SegmentType type;
 
+public:
   // Clone function implementation - not pure virtual as overrided by subclasses
   virtual TypePathSegment *clone_type_path_segment_impl () const
   {
@@ -538,7 +539,6 @@ public:
     return SegmentType::GENERIC;
   }
 
-protected:
   // Use covariance to override base class method
   TypePathSegmentGeneric *clone_type_path_segment_impl () const override
   {
@@ -654,7 +654,6 @@ public:
 
   TypePathFunction &get_function_path () { return function_path; }
 
-protected:
   // Use covariance to override base class method
   TypePathSegmentFunction *clone_type_path_segment_impl () const override
   {
@@ -933,24 +932,24 @@ public:
       segments (std::move (path_segments))
   {}
 
-  /* TODO: maybe make a shortcut constructor that has QualifiedPathType elements
-   * as params */
-
   // Copy constructor with vector clone
   QualifiedPathInType (QualifiedPathInType const &other)
     : TypeNoBounds (other.mappings, other.locus), path_type (other.path_type)
   {
+    auto seg = other.associated_segment->clone_type_path_segment_impl ();
+    associated_segment = std::unique_ptr<TypePathSegment> (seg);
+
     segments.reserve (other.segments.size ());
     for (const auto &e : other.segments)
       segments.push_back (e->clone_type_path_segment ());
-
-    // Untested.
-    gcc_unreachable ();
   }
 
   // Overloaded assignment operator with vector clone
   QualifiedPathInType &operator= (QualifiedPathInType const &other)
   {
+    auto seg = other.associated_segment->clone_type_path_segment_impl ();
+    associated_segment = std::unique_ptr<TypePathSegment> (seg);
+
     path_type = other.path_type;
     locus = other.locus;
     mappings = other.mappings;
index 0ddb8418e950df657bacfc3e30ba57b9b8614c4d..3a4362f92b4769e3721ebbe368e367ef2191b8ee 100644 (file)
@@ -2112,6 +2112,7 @@ QualifiedPathInType::as_string () const
 {
   std::string str = path_type.as_string ();
 
+  str += "::" + associated_segment->as_string ();
   for (const auto &segment : segments)
     {
       str += "::" + segment->as_string ();
index dc05c068359bcdcd2bc006a6220118ef51e57567..fbe79f00bde0246a6ab82beee99d9ee2786a7201 100644 (file)
@@ -1,12 +1,10 @@
-// { dg-additional-options "-fsyntax-only" }
-
 trait Foo {
     type A;
 
     fn foo();
 }
 
-struct S;
+struct S; // { dg-warning "struct is never constructed" }
 
 impl Foo for S {
     type A = i32;
@@ -19,6 +17,6 @@ enum Maybe<T> {
     Nothing,
 }
 
-fn foo() -> Maybe<<S as Foo>::A> {
+pub fn foo() -> Maybe<<S as Foo>::A> {
     Maybe::Something(15)
 }
index 9c518a03ca75fbdb339a42bfbc323e95e440c3f3..ba5d9a3936c94a9b6e165b26e47b7eaf54ea8295 100644 (file)
@@ -1,12 +1,10 @@
-// { dg-additional-options "-fsyntax-only" }
-
 trait Foo {
     type A;
 
     fn foo();
 }
 
-struct S;
+struct S; // { dg-warning "struct is never constructed" }
 
 impl Foo for S {
     type A = ();
@@ -19,6 +17,6 @@ enum Maybe<T> {
     Nothing,
 }
 
-fn main() {
-    let a: Maybe<<S as Foo>::A> = Maybe::Something(());
+pub fn test() {
+    let _a: Maybe<<S as Foo>::A> = Maybe::Something(());
 }