From 9e0c8a0fd7fa95730c0f2f20f51f2affbcd6fdad Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 15 Oct 2024 15:22:56 +0200 Subject: [PATCH] Use more smart pointers in HIR member functions gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.h: * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): * hir/rust-hir-dump.cc (Dump::visit): * hir/tree/rust-hir-expr.h (RUST_HIR_EXPR_H): (class ArrayElemsValues): (class TupleExpr): (struct StructBase): (class StructExprStructFields): (class CallExpr): (class MethodCallExpr): (class WhileLetLoopExpr): (class IfLetExpr): * hir/tree/rust-hir-path.h: * hir/tree/rust-hir-type.h: * hir/tree/rust-hir.cc (TypePath::to_trait_bound): (StructExprStructFields::as_string): * hir/tree/rust-hir.h: * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): * typecheck/rust-tyty-bounds.cc: Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/lints/rust-lint-marklive.h | 4 +- gcc/rust/hir/rust-ast-lower-expr.cc | 19 +-- gcc/rust/hir/rust-hir-dump.cc | 4 +- gcc/rust/hir/tree/rust-hir-expr.h | 120 +++++++++--------- gcc/rust/hir/tree/rust-hir-path.h | 21 ++- gcc/rust/hir/tree/rust-hir-type.h | 3 +- gcc/rust/hir/tree/rust-hir.cc | 8 +- gcc/rust/hir/tree/rust-hir.h | 5 +- .../typecheck/rust-hir-type-check-struct.cc | 30 +++-- gcc/rust/typecheck/rust-tyty-bounds.cc | 27 ++-- 10 files changed, 126 insertions(+), 115 deletions(-) diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h b/gcc/rust/checks/lints/rust-lint-marklive.h index a1e8c110a3d3..8cb65ef957fe 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.h +++ b/gcc/rust/checks/lints/rust-lint-marklive.h @@ -247,7 +247,7 @@ class MarkLive : public MarkLiveBase stct.get_struct_name ().accept_vis (*this); if (stct.has_struct_base ()) { - stct.struct_base->base_struct->accept_vis (*this); + stct.get_struct_base ().get_base ().accept_vis (*this); } } @@ -258,7 +258,7 @@ class MarkLive : public MarkLiveBase void visit (HIR::StructExprStructBase &stct) override { - stct.get_struct_base ()->base_struct->accept_vis (*this); + stct.get_struct_base ().get_base ().accept_vis (*this); } void visit (HIR::Module &module) override diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index 9bb20ca73f18..fb24a72efa70 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -17,6 +17,7 @@ // . #include "rust-ast-lower-expr.h" +#include "optional.h" #include "rust-ast-lower-base.h" #include "rust-ast-lower-block.h" #include "rust-ast-lower-struct-field-expr.h" @@ -77,7 +78,7 @@ ASTLoweringExpr::visit (AST::TupleIndexExpr &expr) void ASTLoweringExpr::visit (AST::TupleExpr &expr) { - std::vector > tuple_elements; + std::vector> tuple_elements; for (auto &e : expr.get_tuple_elems ()) { HIR::Expr *t = ASTLoweringExpr::translate (*e); @@ -174,7 +175,7 @@ ASTLoweringExpr::visit (AST::CallExpr &expr) HIR::Expr *func = ASTLoweringExpr::translate (expr.get_function_expr ()); auto const &in_params = expr.get_params (); - std::vector > params; + std::vector> params; for (auto ¶m : in_params) { auto trans = ASTLoweringExpr::translate (*param); @@ -200,7 +201,7 @@ ASTLoweringExpr::visit (AST::MethodCallExpr &expr) HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ()); auto const &in_params = expr.get_params (); - std::vector > params; + std::vector> params; for (auto ¶m : in_params) { auto trans = ASTLoweringExpr::translate (*param); @@ -290,7 +291,7 @@ ASTLoweringExpr::visit (AST::ArrayIndexExpr &expr) void ASTLoweringExpr::visit (AST::ArrayElemsValues &elems) { - std::vector > elements; + std::vector> elements; for (auto &elem : elems.get_values ()) { HIR::Expr *translated_elem = ASTLoweringExpr::translate (*elem); @@ -511,16 +512,17 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr) HIR::PathInExpression copied_path (*path); delete path; - HIR::StructBase *base = nullptr; + tl::optional> base = tl::nullopt; if (struct_expr.has_struct_base ()) { HIR::Expr *translated_base = ASTLoweringExpr::translate ( struct_expr.get_struct_base ().get_base_struct ()); - base = new HIR::StructBase (std::unique_ptr (translated_base)); + base = tl::optional (Rust::make_unique ( + std::unique_ptr (translated_base))); } auto const &in_fields = struct_expr.get_fields (); - std::vector > fields; + std::vector> fields; for (auto &field : in_fields) { HIR::StructExprField *translated @@ -535,7 +537,8 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr) translated = new HIR::StructExprStructFields (mapping, copied_path, std::move (fields), - struct_expr.get_locus (), base, + struct_expr.get_locus (), + std::move (base), struct_expr.get_inner_attrs (), struct_expr.get_outer_attrs ()); } diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 5dcc63783583..3411315c8f57 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -1182,7 +1182,7 @@ Dump::visit (StructExprStructFields &e) if (!e.has_struct_base ()) put_field ("struct_base", "none"); else - put_field ("struct_base", e.get_struct_base ()->as_string ()); + put_field ("struct_base", e.get_struct_base ().as_string ()); end ("StructExprStructFields"); } @@ -1193,7 +1193,7 @@ Dump::visit (StructExprStructBase &e) begin ("StructExprStructBase"); do_structexprstruct (e); - put_field ("struct_base", e.get_struct_base ()->as_string ()); + put_field ("struct_base", e.get_struct_base ().as_string ()); end ("StructExprStructBase"); } diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index f7ee581331cd..7f2de6445191 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -19,12 +19,14 @@ #ifndef RUST_HIR_EXPR_H #define RUST_HIR_EXPR_H +#include "optional.h" #include "rust-common.h" #include "rust-ast-full-decls.h" #include "rust-hir.h" #include "rust-hir-path.h" #include "rust-operators.h" #include "rust-expr.h" +#include "rust-system.h" namespace Rust { namespace HIR { @@ -893,13 +895,13 @@ class ArrayElems : public FullVisitable // Value array elements class ArrayElemsValues : public ArrayElems { - std::vector > values; + std::vector> values; // TODO: should this store location data? public: ArrayElemsValues (Analysis::NodeMapping mappings, - std::vector > elems) + std::vector> elems) : ArrayElems (mappings), values (std::move (elems)) {} @@ -931,7 +933,7 @@ class ArrayElemsValues : public ArrayElems size_t get_num_elements () const { return values.size (); } - std::vector > &get_values () { return values; } + std::vector> &get_values () { return values; } ArrayElems::ArrayExprType get_array_expr_type () const override final { @@ -1146,7 +1148,7 @@ class ArrayIndexExpr : public ExprWithoutBlock // HIR representation of a tuple class TupleExpr : public ExprWithoutBlock, public WithInnerAttrs { - std::vector > tuple_elems; + std::vector> tuple_elems; // replaces (inlined version of) TupleElements location_t locus; @@ -1155,7 +1157,7 @@ class TupleExpr : public ExprWithoutBlock, public WithInnerAttrs std::string as_string () const override; TupleExpr (Analysis::NodeMapping mappings, - std::vector > tuple_elements, + std::vector> tuple_elements, AST::AttrVec inner_attribs, AST::AttrVec outer_attribs, location_t locus) : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)), @@ -1199,14 +1201,11 @@ class TupleExpr : public ExprWithoutBlock, public WithInnerAttrs void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - const std::vector > &get_tuple_elems () const - { - return tuple_elems; - } - std::vector > &get_tuple_elems () + const std::vector> &get_tuple_elems () const { return tuple_elems; } + std::vector> &get_tuple_elems () { return tuple_elems; } bool is_unit () const { return tuple_elems.size () == 0; } @@ -1362,9 +1361,10 @@ class StructExprStruct : public StructExpr, public WithInnerAttrs * struct */ struct StructBase { -public: +private: std::unique_ptr base_struct; +public: // TODO: should this store location data? StructBase (std::unique_ptr base_struct_ptr) : base_struct (std::move (base_struct_ptr)) @@ -1402,7 +1402,7 @@ struct StructBase std::string as_string () const; - Expr *get_base () { return base_struct.get (); } + Expr &get_base () { return *base_struct; } }; /* Base HIR node for a single struct expression field (in struct instance @@ -1598,38 +1598,39 @@ class StructExprFieldIndexValue : public StructExprFieldWithVal // HIR node of a struct creator with fields class StructExprStructFields : public StructExprStruct { -public: // std::vector fields; - std::vector > fields; - - // bool has_struct_base; - // FIXME make unique_ptr - StructBase *struct_base; + std::vector> fields; + tl::optional> struct_base; +public: // For unions there is just one field, the index // is set when type checking int union_index = -1; std::string as_string () const override; - bool has_struct_base () const { return struct_base != nullptr; } + bool has_struct_base () const { return struct_base.has_value (); } // Constructor for StructExprStructFields when no struct base is used StructExprStructFields ( Analysis::NodeMapping mappings, PathInExpression struct_path, - std::vector > expr_fields, - location_t locus, StructBase *base_struct, + std::vector> expr_fields, location_t locus, + tl::optional> base_struct, AST::AttrVec inner_attribs = AST::AttrVec (), AST::AttrVec outer_attribs = AST::AttrVec ()) : StructExprStruct (std::move (mappings), std::move (struct_path), std::move (inner_attribs), std::move (outer_attribs), locus), - fields (std::move (expr_fields)), struct_base (base_struct) + fields (std::move (expr_fields)), struct_base (std::move (base_struct)) {} // copy constructor with vector clone StructExprStructFields (StructExprStructFields const &other) - : StructExprStruct (other), struct_base (other.struct_base), + : StructExprStruct (other), + struct_base ( + other.has_struct_base () ? tl::optional> ( + Rust::make_unique (*other.struct_base.value ())) + : tl::nullopt), union_index (other.union_index) { fields.reserve (other.fields.size ()); @@ -1641,7 +1642,10 @@ class StructExprStructFields : public StructExprStruct StructExprStructFields &operator= (StructExprStructFields const &other) { StructExprStruct::operator= (other); - struct_base = other.struct_base; + struct_base + = other.has_struct_base () ? tl::optional> ( + Rust::make_unique (*other.struct_base.value ())) + : tl::nullopt; union_index = other.union_index; fields.reserve (other.fields.size ()); @@ -1658,20 +1662,20 @@ class StructExprStructFields : public StructExprStruct void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::vector > &get_fields () + std::vector> &get_fields () { return fields; }; - const std::vector > &get_fields () const + const std::vector> &get_fields () const { return fields; }; - StructBase *get_struct_base () { return struct_base; } + StructBase &get_struct_base () { return *struct_base.value (); } - void set_fields_as_owner ( - std::vector > new_fields) + void + set_fields_as_owner (std::vector> new_fields) { fields = std::move (new_fields); } @@ -1717,7 +1721,7 @@ class StructExprStructBase : public StructExprStruct void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - StructBase *get_struct_base () { return &struct_base; } + StructBase &get_struct_base () { return struct_base; } protected: /* Use covariance to implement clone function as returning this object rather @@ -1739,14 +1743,14 @@ class StructExprStructBase : public StructExprStruct class CallExpr : public ExprWithoutBlock { std::unique_ptr function; - std::vector > params; + std::vector> params; location_t locus; public: std::string as_string () const override; CallExpr (Analysis::NodeMapping mappings, std::unique_ptr function_expr, - std::vector > function_params, + std::vector> function_params, AST::AttrVec outer_attribs, location_t locus) : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)), function (std::move (function_expr)), @@ -1796,9 +1800,9 @@ class CallExpr : public ExprWithoutBlock size_t num_params () const { return params.size (); } - std::vector > &get_arguments () { return params; } + std::vector> &get_arguments () { return params; } - const std::vector > &get_arguments () const + const std::vector> &get_arguments () const { return params; } @@ -1826,7 +1830,7 @@ class MethodCallExpr : public ExprWithoutBlock { std::unique_ptr receiver; PathExprSegment method_name; - std::vector > params; + std::vector> params; location_t locus; public: @@ -1835,7 +1839,7 @@ class MethodCallExpr : public ExprWithoutBlock MethodCallExpr (Analysis::NodeMapping mappings, std::unique_ptr call_receiver, PathExprSegment method_path, - std::vector > method_params, + std::vector> method_params, AST::AttrVec outer_attribs, location_t locus) : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)), receiver (std::move (call_receiver)), @@ -1887,9 +1891,9 @@ class MethodCallExpr : public ExprWithoutBlock bool has_params () const { return !params.empty (); } size_t num_params () const { return params.size (); } - std::vector > &get_arguments () { return params; } + std::vector> &get_arguments () { return params; } - const std::vector > &get_arguments () const + const std::vector> &get_arguments () const { return params; } @@ -2153,7 +2157,7 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs { // FIXME this should be private + get/set public: - std::vector > statements; + std::vector> statements; std::unique_ptr expr; bool tail_reachable; LoopLabel label; @@ -2173,7 +2177,7 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs bool is_tail_reachable () const { return tail_reachable; } BlockExpr (Analysis::NodeMapping mappings, - std::vector > block_statements, + std::vector> block_statements, std::unique_ptr block_expr, bool tail_reachable, AST::AttrVec inner_attribs, AST::AttrVec outer_attribs, LoopLabel label, location_t start_locus, location_t end_locus) @@ -2241,7 +2245,7 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs bool has_final_expr () { return expr != nullptr; } Expr &get_final_expr () { return *expr; } - std::vector > &get_statements () { return statements; } + std::vector> &get_statements () { return statements; } ExprType get_expression_type () const final override { @@ -3029,7 +3033,7 @@ class WhileLoopExpr : public BaseLoopExpr class WhileLetLoopExpr : public BaseLoopExpr { // MatchArmPatterns patterns; - std::vector > match_arm_patterns; // inlined + std::vector> match_arm_patterns; // inlined std::unique_ptr condition; public: @@ -3037,7 +3041,7 @@ class WhileLetLoopExpr : public BaseLoopExpr // Constructor with a loop label WhileLetLoopExpr (Analysis::NodeMapping mappings, - std::vector > match_arm_patterns, + std::vector> match_arm_patterns, std::unique_ptr condition, std::unique_ptr loop_block, location_t locus, LoopLabel loop_label, @@ -3084,7 +3088,7 @@ class WhileLetLoopExpr : public BaseLoopExpr void accept_vis (HIRExpressionVisitor &vis) override; Expr &get_cond () { return *condition; } - std::vector > &get_patterns () + std::vector> &get_patterns () { return match_arm_patterns; } @@ -3259,7 +3263,7 @@ class IfExprConseqElse : public IfExpr class IfLetExpr : public ExprWithBlock { // MatchArmPatterns patterns; - std::vector > match_arm_patterns; // inlined + std::vector> match_arm_patterns; // inlined std::unique_ptr value; std::unique_ptr if_block; @@ -3269,7 +3273,7 @@ class IfLetExpr : public ExprWithBlock std::string as_string () const override; IfLetExpr (Analysis::NodeMapping mappings, - std::vector > match_arm_patterns, + std::vector> match_arm_patterns, std::unique_ptr value, std::unique_ptr if_block, location_t locus) : ExprWithBlock (std::move (mappings), AST::AttrVec ()), @@ -3323,7 +3327,7 @@ class IfLetExpr : public ExprWithBlock Expr &get_scrutinee_expr () { return *value; } - std::vector > &get_patterns () + std::vector> &get_patterns () { return match_arm_patterns; } @@ -3363,11 +3367,12 @@ class IfLetExprConseqElse : public IfLetExpr public: std::string as_string () const override; - IfLetExprConseqElse ( - Analysis::NodeMapping mappings, - std::vector > match_arm_patterns, - std::unique_ptr value, std::unique_ptr if_block, - std::unique_ptr else_block, location_t locus) + IfLetExprConseqElse (Analysis::NodeMapping mappings, + std::vector> match_arm_patterns, + std::unique_ptr value, + std::unique_ptr if_block, + std::unique_ptr else_block, + location_t locus) : IfLetExpr (std::move (mappings), std::move (match_arm_patterns), std::move (value), std::move (if_block), locus), else_block (std::move (else_block)) @@ -3431,7 +3436,7 @@ struct MatchArm { private: AST::AttrVec outer_attrs; - std::vector > match_arm_patterns; + std::vector> match_arm_patterns; std::unique_ptr guard_expr; location_t locus; @@ -3440,7 +3445,7 @@ struct MatchArm bool has_match_arm_guard () const { return guard_expr != nullptr; } // Constructor for match arm with a guard expression - MatchArm (std::vector > match_arm_patterns, + MatchArm (std::vector> match_arm_patterns, location_t locus, std::unique_ptr guard_expr = nullptr, AST::AttrVec outer_attrs = AST::AttrVec ()) : outer_attrs (std::move (outer_attrs)), @@ -3491,12 +3496,12 @@ struct MatchArm static MatchArm create_error () { location_t locus = UNDEF_LOCATION; - return MatchArm (std::vector > (), locus); + return MatchArm (std::vector> (), locus); } std::string as_string () const; - std::vector > &get_patterns () + std::vector> &get_patterns () { return match_arm_patterns; } @@ -3871,7 +3876,6 @@ struct AnonConst return *this; } }; -; class InlineAsmOperand { @@ -4101,6 +4105,8 @@ class InlineAsmOperand struct Const get_const () const { return cnst.value (); } struct Sym get_sym () const { return sym.value (); } struct Label get_label () const { return label.value (); } + + location_t get_locus () const { return locus; } }; // Inline Assembly Node class InlineAsm : public ExprWithoutBlock diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index b561c30c49dc..0bca5b1afbb3 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -739,7 +739,7 @@ class TypePath : public TypeNoBounds AST::SimplePath as_simple_path () const; // Creates a trait bound with a clone of this type path as its only element. - TraitBound *to_trait_bound (bool in_parens) const override; + std::unique_ptr to_trait_bound (bool in_parens) const override; void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRTypeVisitor &vis) override; @@ -751,10 +751,7 @@ class TypePath : public TypeNoBounds return segments; } - std::unique_ptr &get_final_segment () - { - return segments.back (); - } + TypePathSegment &get_final_segment () { return *segments.back (); } }; class QualifiedPathType @@ -818,22 +815,22 @@ class QualifiedPathType bool trait_has_generic_args () const { rust_assert (has_as_clause ()); - bool is_generic_seg = trait->get_final_segment ()->get_type () + bool is_generic_seg = trait->get_final_segment ().get_type () == TypePathSegment::SegmentType::GENERIC; if (!is_generic_seg) return false; - TypePathSegmentGeneric *seg = static_cast ( - trait->get_final_segment ().get ()); - return seg->has_generic_args (); + auto &seg + = static_cast (trait->get_final_segment ()); + return seg.has_generic_args (); } GenericArgs &get_trait_generic_args () { rust_assert (trait_has_generic_args ()); - TypePathSegmentGeneric *seg = static_cast ( - trait->get_final_segment ().get ()); - return seg->get_generic_args (); + auto &seg + = static_cast (trait->get_final_segment ()); + return seg.get_generic_args (); } }; diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h index a8ac4a1b076e..63247768aea7 100644 --- a/gcc/rust/hir/tree/rust-hir-type.h +++ b/gcc/rust/hir/tree/rust-hir-type.h @@ -264,7 +264,8 @@ class ParenthesisedType : public TypeNoBounds } // Creates a trait bound (clone of this one's trait bound) - HACK - TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override + std::unique_ptr + to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const override { /* NOTE: obviously it is unknown whether the internal type is a trait bound * due to polymorphism, so just let the internal type handle it. As diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc index d5ca95c1cc06..efb8b49bd27e 100644 --- a/gcc/rust/hir/tree/rust-hir.cc +++ b/gcc/rust/hir/tree/rust-hir.cc @@ -2712,14 +2712,14 @@ Expr::as_string () const } // hopefully definition here will prevent circular dependency issue -TraitBound * +std::unique_ptr TypePath::to_trait_bound (bool in_parens) const { // create clone FIXME is this required? or is copy constructor automatically // called? TypePath copy (*this); - return new TraitBound (mappings, std::move (copy), copy.get_locus (), - in_parens); + return Rust::make_unique (mappings, std::move (copy), + copy.get_locus (), in_parens); } std::string @@ -3047,7 +3047,7 @@ StructExprStructFields::as_string () const } else { - str += struct_base->as_string (); + str += (*struct_base)->as_string (); } return str; diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 90663f52da1e..1326b82a85f3 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -457,7 +457,8 @@ class Type : public Node, public FullVisitable /* HACK: convert to trait bound. Virtual method overriden by classes that * enable this. */ - virtual TraitBound *to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const + virtual std::unique_ptr + to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const { return nullptr; } @@ -677,7 +678,7 @@ class LifetimeParam : public GenericParam // Returns whether the lifetime param has an outer attribute. bool has_outer_attribute () const override { return outer_attrs.size () > 1; } - AST::AttrVec &get_outer_attrs () { return outer_attrs; } + AST::AttrVec &get_outer_attrs () override { return outer_attrs; } // Returns whether the lifetime param is in an error state. bool is_error () const { return lifetime.is_error (); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc index 47881021b699..1931f08ff4d2 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc @@ -56,17 +56,18 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) if (struct_expr.has_struct_base ()) { TyTy::BaseType *base_resolved - = TypeCheckExpr::Resolve (*struct_expr.struct_base->base_struct); + = TypeCheckExpr::Resolve (struct_expr.get_struct_base ().get_base ()); TyTy::BaseType *base_unify = unify_site ( - struct_expr.struct_base->base_struct->get_mappings ().get_hirid (), + struct_expr.get_struct_base ().get_base ().get_mappings ().get_hirid (), TyTy::TyWithLocation (struct_path_resolved), TyTy::TyWithLocation (base_resolved), - struct_expr.struct_base->base_struct->get_locus ()); + struct_expr.get_struct_base ().get_base ().get_locus ()); if (base_unify->get_kind () != struct_path_ty->get_kind ()) { - rust_fatal_error (struct_expr.struct_base->base_struct->get_locus (), - "incompatible types for base struct reference"); + rust_fatal_error ( + struct_expr.get_struct_base ().get_base ().get_locus (), + "incompatible types for base struct reference"); return; } @@ -190,26 +191,29 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) for (auto &missing : missing_fields) { HIR::Expr *receiver - = struct_expr.struct_base->base_struct->clone_expr_impl (); + = struct_expr.get_struct_base ().get_base ().clone_expr_impl (); HIR::StructExprField *implicit_field = nullptr; AST::AttrVec outer_attribs; auto crate_num = mappings.get_current_crate (); - Analysis::NodeMapping mapping ( - crate_num, - struct_expr.struct_base->base_struct->get_mappings () - .get_nodeid (), - mappings.get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); + Analysis::NodeMapping mapping (crate_num, + struct_expr.get_struct_base () + .get_base () + .get_mappings () + .get_nodeid (), + mappings.get_next_hir_id ( + crate_num), + UNKNOWN_LOCAL_DEFID); HIR::Expr *field_value = new HIR::FieldAccessExpr ( mapping, std::unique_ptr (receiver), missing, std::move (outer_attribs), - struct_expr.struct_base->base_struct->get_locus ()); + struct_expr.get_struct_base ().get_base ().get_locus ()); implicit_field = new HIR::StructExprFieldIdentifierValue ( mapping, missing, std::unique_ptr (field_value), - struct_expr.struct_base->base_struct->get_locus ()); + struct_expr.get_struct_base ().get_base ().get_locus ()); size_t field_index; bool ok = variant->lookup_field (missing, nullptr, &field_index); diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index b3c19efadee9..a5f415a33d4c 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -16,6 +16,7 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-hir-full-decls.h" #include "rust-hir-type-bounds.h" #include "rust-hir-trait-resolve.h" #include "rust-substitution-mapper.h" @@ -203,21 +204,21 @@ TypeCheckBase::get_predicate_from_bound ( = HIR::GenericArgs::create_empty (type_path.get_locus ()); auto &final_seg = type_path.get_final_segment (); - switch (final_seg->get_type ()) + switch (final_seg.get_type ()) { case HIR::TypePathSegment::SegmentType::GENERIC: { - auto final_generic_seg - = static_cast (final_seg.get ()); - if (final_generic_seg->has_generic_args ()) + auto &final_generic_seg + = static_cast (final_seg); + if (final_generic_seg.has_generic_args ()) { - args = final_generic_seg->get_generic_args (); + args = final_generic_seg.get_generic_args (); } } break; case HIR::TypePathSegment::SegmentType::FUNCTION: { auto &final_function_seg - = static_cast (*final_seg); + = static_cast (final_seg); auto &fn = final_function_seg.get_function_path (); // we need to make implicit generic args which must be an implicit @@ -225,7 +226,7 @@ TypeCheckBase::get_predicate_from_bound ( auto crate_num = mappings.get_current_crate (); HirId implicit_args_id = mappings.get_next_hir_id (); Analysis::NodeMapping mapping (crate_num, - final_seg->get_mappings ().get_nodeid (), + final_seg.get_mappings ().get_nodeid (), implicit_args_id, UNKNOWN_LOCAL_DEFID); std::vector> params_copy; @@ -234,12 +235,10 @@ TypeCheckBase::get_predicate_from_bound ( params_copy.push_back (p->clone_type ()); } - HIR::TupleType *implicit_tuple - = new HIR::TupleType (mapping, std::move (params_copy), - final_seg->get_locus ()); - std::vector> inputs; - inputs.push_back (std::unique_ptr (implicit_tuple)); + inputs.push_back ( + Rust::make_unique (mapping, std::move (params_copy), + final_seg.get_locus ())); // resolve the fn_once_output type which assumes there must be an output // set @@ -249,7 +248,7 @@ TypeCheckBase::get_predicate_from_bound ( HIR::TraitItem *trait_item = mappings .lookup_trait_item_lang_item (LangItem::Kind::FN_ONCE_OUTPUT, - final_seg->get_locus ()) + final_seg.get_locus ()) .value (); std::vector bindings; @@ -263,7 +262,7 @@ TypeCheckBase::get_predicate_from_bound ( args = HIR::GenericArgs ({} /* lifetimes */, std::move (inputs) /* type_args*/, std::move (bindings) /* binding_args*/, - {} /* const_args */, final_seg->get_locus ()); + {} /* const_args */, final_seg.get_locus ()); } break;