New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
derive: Add base for builtin derives and #[derive(Clone)] #2216
Conversation
gcc/rust/expand/rust-derive-clone.cc
Outdated
std::unique_ptr<Expr> | ||
DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone) | ||
{ | ||
// ::core::clone::Clone::clone for the fully qualified path - we don't link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's $crate::clone::Clone::clone
, the pretty printing from rustc prints $crate
as the appropriate crate name.
13c1948
to
e5079a7
Compare
{ | ||
auto new_item | ||
= derive_item (item, attr, maybe_builtin->second); | ||
// this inserts the derive *before* the item - is it a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustc inserts the functions after the item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be an issue, but we'll see in the future if it arises. it's not too hard of a fix either way :)
e5079a7
to
8e8c383
Compare
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: New file. * ast/rust-ast-builder.h: New file.
8e8c383
to
7b1da01
Compare
gcc/rust/ChangeLog: * Make-lang.in: Add new object files to Makefile. * expand/rust-expand-visitor.cc (is_derive): Move function. (is_builtin): Likewise. (get_traits_to_derive): New function. (derive_item): Likewise. (ExpandVisitor::visit): Visit item/statements containers. (ExpandVisitor::visit_outer_attrs): Take a reference on the attribute instead of a copy. (ExpandVisitor::is_derive): Deleted function. (ExpandVisitor::is_builtin): Likewise. * expand/rust-expand-visitor.h (RUST_EXPAND_VISITOR_H): Add missing #ifdef guards. (is_derive): Declare function. (is_builtin): Likewise. * expand/rust-macro-builtins.cc (builtin_macro_from_string): Use new MacroBuiltin::builtins map. (make_macro_path_str): Likewise. * expand/rust-macro-builtins.h (enum class): Add builtin derive macros. * expand/rust-derive-clone.cc: New file. * expand/rust-derive-clone.h: New file. * expand/rust-derive.cc: New file. * expand/rust-derive.h: New file. * util/rust-hir-map.cc (Mappings::insert_macro_def): Fix logic for setting builtin macro transcribers. gcc/testsuite/ChangeLog: * rust/compile/macro43.rs: Fix test with new derive macros. * rust/compile/derive_macro1.rs: New test. * rust/compile/derive_macro3.rs: New test. * rust/execute/torture/derive_macro1.rs: New test. * rust/execute/torture/derive_macro3.rs: New test.
7b1da01
to
bec74b0
Compare
This PR adds basic support for builtin derive macros and, more specifically, deriving Clone on some simple structures (tuple structs and empty structs). Keeping it as a draft as it still needs some work. Needs #2214