add must_use to partial_shuffle#1768
Conversation
|
If you follow the lifetime elison rules for functions, namely:
then it is clear that the returned slices must be sub-slices of the input Only one implementation is provided and it does the latter (potentially confusing since the ranges are swapped in the output; it would perhaps have been more intuitive if the two output slices were in order but obviously that's not something we should change now). Since this is an unsealed trait, foreign implementations on foreign types are possible (I don't see any in a GitHub search).
From the first two pages of GitHub search results, I count:
One of the samples linked uses: vec.split_off(vec.len() - num_woken)This is a neat way to gain an owned
I don't see any possible scope for optimizations, aside from for use-cases which want the SuggestionWe document the expected output order within the input slice clearly (since many examples assumed this incorrectly) and add Further, in the next breaking release of |
|
I think this is superseded by #1769. |
- [x] Added a `CHANGELOG.md` entry See discussion in #1768.
CHANGELOG.mdentrySummary
partial_shuffle's returned slices are the only correct way to access the regions. Not using them is almost certainly an error.Motivation
I noticed that some users don't use the returned subslices of
partial_shuffle.Instead they typically assume the shuffled region is at the start of the original slice and are incorrect. Or assume correctly and may silently become incorrect if the implementation changes.
Here's a Github search of examples.
About 13 out of 60 uses ignore the returned slices.
Mostly due to the borrow checker or cloning/
Vecrelated inflexibility.Many users are accessing the unshuffled region instead of the shuffled. When
slice.len()is much larger thanamount, this means practically no shuffling occurs in the data they actually use.Alternatives
Of course we could instead just guarantee an order but that might prevent future optimizations and would break some users' code anyway.