diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-07-28 21:06:15 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-05 18:18:35 +0100 |
commit | 443d4d1f7cf6aa1570670e728b0cb59aada0e10f (patch) | |
tree | d8595ffdb329b548655682bd0b256f5626929f0c | |
parent | b333711461c8244bc2b46c736858950837ba7bbf (diff) | |
download | gcc-443d4d1f7cf6aa1570670e728b0cb59aada0e10f.zip gcc-443d4d1f7cf6aa1570670e728b0cb59aada0e10f.tar.gz gcc-443d4d1f7cf6aa1570670e728b0cb59aada0e10f.tar.bz2 |
Fix clone on TypeBounds
Covariance was causing issues for the default clone on these classes. Such that the NodeId became messed up. This causes name resolution issues.
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 23 | ||||
-rw-r--r-- | gcc/rust/ast/rust-type.h | 18 |
2 files changed, 31 insertions, 10 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 6baef3f..e376488 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1128,12 +1128,13 @@ public: NodeId get_node_id () const { return node_id; } + virtual Location get_locus_slow () const = 0; + protected: // Clone function implementation as pure virtual method virtual TypeParamBound *clone_type_param_bound_impl () const = 0; - TypeParamBound () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) - {} + TypeParamBound (NodeId node_id) : node_id (node_id) {} NodeId node_id; }; @@ -1159,8 +1160,14 @@ public: // Constructor Lifetime (LifetimeType type, std::string name = std::string (), Location locus = Location ()) - : lifetime_type (type), lifetime_name (std::move (name)), locus (locus), - node_id (Analysis::Mappings::get ()->get_next_node_id ()) + : TypeParamBound (Analysis::Mappings::get ()->get_next_node_id ()), + lifetime_type (type), lifetime_name (std::move (name)), locus (locus) + {} + + Lifetime (NodeId id, LifetimeType type, std::string name = std::string (), + Location locus = Location ()) + : TypeParamBound (id), lifetime_type (type), + lifetime_name (std::move (name)), locus (locus) {} // Creates an "error" lifetime. @@ -1178,18 +1185,18 @@ public: LifetimeType get_lifetime_type () { return lifetime_type; } - Location get_locus () { return locus; } + Location get_locus () const { return locus; } - std::string get_lifetime_name () const { return lifetime_name; } + Location get_locus_slow () const override final { return get_locus (); } - NodeId get_node_id () const { return node_id; } + std::string get_lifetime_name () const { return lifetime_name; } protected: /* Use covariance to implement clone function as returning this object rather * than base */ Lifetime *clone_type_param_bound_impl () const override { - return new Lifetime (*this); + return new Lifetime (node_id, lifetime_type, lifetime_name, locus); } }; diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index e179bb7..b658a53 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -50,7 +50,18 @@ public: bool opening_question_mark = false, std::vector<LifetimeParam> for_lifetimes = std::vector<LifetimeParam> ()) - : in_parens (in_parens), opening_question_mark (opening_question_mark), + : TypeParamBound (Analysis::Mappings::get ()->get_next_node_id ()), + in_parens (in_parens), opening_question_mark (opening_question_mark), + for_lifetimes (std::move (for_lifetimes)), + type_path (std::move (type_path)), locus (locus) + {} + + TraitBound (NodeId id, TypePath type_path, Location locus, + bool in_parens = false, bool opening_question_mark = false, + std::vector<LifetimeParam> for_lifetimes + = std::vector<LifetimeParam> ()) + : TypeParamBound (id), in_parens (in_parens), + opening_question_mark (opening_question_mark), for_lifetimes (std::move (for_lifetimes)), type_path (std::move (type_path)), locus (locus) {} @@ -59,6 +70,8 @@ public: Location get_locus () const { return locus; } + Location get_locus_slow () const override final { return get_locus (); } + void accept_vis (ASTVisitor &vis) override; // TODO: this mutable getter seems kinda dodgy @@ -73,7 +86,8 @@ protected: * than base */ TraitBound *clone_type_param_bound_impl () const override { - return new TraitBound (*this); + return new TraitBound (node_id, type_path, locus, in_parens, + opening_question_mark, for_lifetimes); } }; |