diff options
Diffstat (limited to 'gcc/rust/expand/rust-derive.h')
-rw-r--r-- | gcc/rust/expand/rust-derive.h | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index 1924432..d8cc0a4 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -34,8 +34,12 @@ namespace AST { class DeriveVisitor : public AST::ASTVisitor { public: - static std::unique_ptr<Item> derive (Item &item, const Attribute &derive, - BuiltinMacro to_derive); + /** + * Expand a built-in derive macro on an item. This may generate multiple items + * which all need to be integrated to the existing AST + */ + static std::vector<std::unique_ptr<Item>> + derive (Item &item, const Attribute &derive, BuiltinMacro to_derive); protected: DeriveVisitor (location_t loc); @@ -43,6 +47,29 @@ protected: location_t loc; Builder builder; + struct ImplGenerics + { + /* The type we are deriving the impl for */ + std::unique_ptr<Type> self_type; + + /* Generics for the impl itself */ + std::vector<std::unique_ptr<GenericParam>> impl; + }; + + /** + * Create the generic parameters for a derive impl block. Derived impl blocks + * will often share the same structure of reusing the exact same bounds as + * their original type, plus adding an extra one for the trait we are + * deriving. For example, when deriving `Clone` on `Foo<T>`, you want to make + * sure that you implement `Clone` only if `T: Clone` - so you add an extra + * `Clone` bound to all of your generics. + */ + ImplGenerics setup_impl_generics ( + const std::string &type_name, + const std::vector<std::unique_ptr<GenericParam>> &type_generics, + tl::optional<std::unique_ptr<TypeParamBound>> &&extra_bound + = tl::nullopt) const; + private: // the 4 "allowed" visitors, which a derive-visitor can specify and override virtual void visit_struct (StructStruct &struct_item) = 0; |