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

Vec: removed Clone trait and introduced TryClone trait #8

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

amunra
Copy link
Collaborator

@amunra amunra commented Oct 8, 2024

This change drops support for the Clone trait, since that would have internally allocated and failed. It introduces a new TryClone in its place.

This issue was spotted here: https://www.reddit.com/r/rust/comments/1fy7cu8/comment/lqvd9me/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

This PR does not provide complete support for the TryClone trait. Some outstanding work is detailed here: #7

@amunra amunra requested a review from eugenels October 8, 2024 09:25
@amunra amunra changed the title removed Clone trait and introduced TryClone trait Vec: removed Clone trait and introduced TryClone trait Oct 8, 2024
@amunra
Copy link
Collaborator Author

amunra commented Oct 8, 2024

A fair question is if to allow Vec cloning for T: Clone or restrict it to T: Copy.

Elements that are cloneable may or may not allocate. There's nothing in the type system that can help us distinguish between the two cases.

@nikomatsakis's Claim trait would be ideal here, alas, it does not exist (yet). See:

@amunra amunra merged commit 80f3e20 into main Oct 8, 2024
18 checks passed
@amunra amunra deleted the no_clone_for_vec branch October 8, 2024 12:57
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.

2 participants