We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Warns the user when that for n > 1 only the last of the Vec created by the macro will actually have the requested capacity.
n > 1
Vec
Alerts the user to some likely unintended behaviour.
The text was updated successfully, but these errors were encountered:
std::iter::repeat would run into a similar thing, except none of the vecs would have the desired capacity
std::iter::repeat
Sorry, something went wrong.
Can you elaborate on why this is the case? That is quite unintuitive ^^
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b0444384a560393618dd26639192ca49
Basically, why does only the final element have the correct capacity?
(the unspecialised) vec![foo; n] works by cloning the result of foo, it uses the result directly for the last one since it can avoid an extra clone - https://github.com/rust-lang/rust/blob/62d9034a0d571b78e518727d6cb4b090569e5238/library/alloc/src/vec/mod.rs#L2529-L2555
vec![foo; n]
foo
Cloning a vec doesn't preserve its capacity
repeat_vec_with_capacity
5ac76ac
Successfully merging a pull request may close this issue.
What it does
Warns the user when that for
n > 1
only the last of theVec
created by the macro will actually have the requested capacity.Advantage
Alerts the user to some likely unintended behaviour.
The text was updated successfully, but these errors were encountered: