From 443d4d1f7cf6aa1570670e728b0cb59aada0e10f Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 28 Jul 2021 21:06:15 +0100 Subject: 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. --- gcc/rust/ast/rust-ast.h | 23 +++++++++++++++-------- gcc/rust/ast/rust-type.h | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'gcc/rust') 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 for_lifetimes = std::vector ()) - : 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 for_lifetimes + = std::vector ()) + : 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); } }; -- cgit v1.1