Skip to content
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

Improve derive(Clone) for generic types #3367

Merged
merged 4 commits into from
Jan 21, 2025

Conversation

CohenArthur
Copy link
Member

@CohenArthur CohenArthur commented Jan 15, 2025

When deriving Clone for a type with generic, we need to bound the impl's generic to be : Clone. e.g. the derive of struct Foo<T> should always be impl<T: Clone> Clone for Foo<T> even if T isn't necessarily bound by Clone in the struct's definition. Requires #3343 and thus #3366 so only review the last 3 commits

@CohenArthur
Copy link
Member Author

Ah, we also need to do that for derive(Copy) I think

@CohenArthur CohenArthur force-pushed the derive-clone-generic branch 4 times, most recently from af273a5 to 4fed915 Compare January 21, 2025 13:27
gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::do_typepathsegment): Add handling for lang items.
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc (Builder::new_type_param): Add optional extra trait bounds.
	* ast/rust-ast-builder.h: Likewise.
gcc/rust/ChangeLog:

	* expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone
gcc/rust/ChangeLog:

	* expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and
	Sized bounds.

gcc/testsuite/ChangeLog:

	* rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.
@CohenArthur CohenArthur enabled auto-merge January 21, 2025 13:28
@CohenArthur CohenArthur added this pull request to the merge queue Jan 21, 2025
Merged via the queue into Rust-GCC:master with commit 1f39e0f Jan 21, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant