-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add array_windows fn #75026
Add array_windows fn #75026
Conversation
Added a separate tracking issue for Please update the the links for |
Would it make sense to define Edit: decided to go with defining in terms of this, just reduces the code size and centralizes the logic. |
Looks fairly good to me. It might be more intuitive to only define I personally don't care either way here. Not part of |
ca8e8d5
to
8998844
Compare
This comment has been minimized.
This comment has been minimized.
eec9e0c
to
858e817
Compare
858e817
to
58610fd
Compare
This comment has been minimized.
This comment has been minimized.
58610fd
to
8fe4b0f
Compare
This seems to be a spurious error, is it possible for tests to be rerun? |
r? @Amanieu |
☔ The latest upstream changes (presumably #76311) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
a5fc8d3
to
8af9677
Compare
Updated issue to rust-lang#75027 Update to rm oob access And hopefully fix docs as well Fixed naming conflict in test Fix test which used 1-indexing Nth starts from 0, woops Fix a bunch of off by 1 errors See https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=757b311987e3fae1ca47122969acda5a Add even more off by 1 errors And also write `next` and `next_back` in terms of `nth` and `nth_back`. Run fmt Fix forgetting to change fn name in test add nth_back test & document unsafe Remove as_ref().unwrap() Documented occurrences of unsafe, noting what invariants are maintained
8af9677
to
f240abc
Compare
@bors r+ |
📌 Commit f240abc has been approved by |
Rollup of 16 pull requests Successful merges: - rust-lang#75026 (Add array_windows fn) - rust-lang#76642 (Do not lint ignored private doc tests) - rust-lang#76719 (Change error message for ty param in const) - rust-lang#76721 (Use intra-doc links in `core::mem`) - rust-lang#76728 (Add a comment why `extern crate` is necessary for rustdoc) - rust-lang#76735 (Remove unnecessary `clone()`s in bootstrap) - rust-lang#76741 (Avoid printing dry run timings) - rust-lang#76747 (Add missing code examples in libcore) - rust-lang#76756 (fix a couple of stylistic clippy warnings) - rust-lang#76758 ([fuchsia] Propagate the userspace UTC clock) - rust-lang#76759 (Fix stabilization marker for future_readiness_fns) - rust-lang#76760 (don't lazily evaluate some trivial values for Option::None replacements (clippy::unnecessary_lazy_evaluations)) - rust-lang#76764 (Update books) - rust-lang#76775 (Strip a single leading tab when rendering dataflow diffs) - rust-lang#76778 (Simplify iter fuse struct doc) - rust-lang#76794 (Make graphviz font configurable) Failed merges: r? `@ghost`
Implement split_array and split_array_mut This implements `[T]::split_array::<const N>() -> (&[T; N], &[T])` and `[T; N]::split_array::<const M>() -> (&[T; M], &[T])` and their mutable equivalents. These are another few “missing” array implementations now that const generics are a thing, similar to rust-lang#74373, rust-lang#75026, etc. Fixes rust-lang#74674. This implements `[T; N]::split_array` returning an array and a slice. Ultimately, this is probably not what we want, we would want the second return value to be an array of length N-M, which will likely be possible with future const generics enhancements. We need to implement the array method now though, to immediately shadow the slice method. This way, when the slice methods get stabilized, calling them on an array will not be automatic through coercion, so we won't have trouble stabilizing the array methods later (cf. into_iter debacle). An unchecked version of `[T]::split_array` could also be added as in rust-lang#76014. This would not be needed for `[T; N]::split_array` as that can be compile-time checked. Edit: actually, since split_at_unchecked is internal-only it could be changed to be split_array-only.
Implement split_array and split_array_mut This implements `[T]::split_array::<const N>() -> (&[T; N], &[T])` and `[T; N]::split_array::<const M>() -> (&[T; M], &[T])` and their mutable equivalents. These are another few “missing” array implementations now that const generics are a thing, similar to rust-lang#74373, rust-lang#75026, etc. Fixes rust-lang#74674. This implements `[T; N]::split_array` returning an array and a slice. Ultimately, this is probably not what we want, we would want the second return value to be an array of length N-M, which will likely be possible with future const generics enhancements. We need to implement the array method now though, to immediately shadow the slice method. This way, when the slice methods get stabilized, calling them on an array will not be automatic through coercion, so we won't have trouble stabilizing the array methods later (cf. into_iter debacle). An unchecked version of `[T]::split_array` could also be added as in rust-lang#76014. This would not be needed for `[T; N]::split_array` as that can be compile-time checked. Edit: actually, since split_at_unchecked is internal-only it could be changed to be split_array-only.
Implement split_array and split_array_mut This implements `[T]::split_array::<const N>() -> (&[T; N], &[T])` and `[T; N]::split_array::<const M>() -> (&[T; M], &[T])` and their mutable equivalents. These are another few “missing” array implementations now that const generics are a thing, similar to rust-lang#74373, rust-lang#75026, etc. Fixes rust-lang#74674. This implements `[T; N]::split_array` returning an array and a slice. Ultimately, this is probably not what we want, we would want the second return value to be an array of length N-M, which will likely be possible with future const generics enhancements. We need to implement the array method now though, to immediately shadow the slice method. This way, when the slice methods get stabilized, calling them on an array will not be automatic through coercion, so we won't have trouble stabilizing the array methods later (cf. into_iter debacle). An unchecked version of `[T]::split_array` could also be added as in rust-lang#76014. This would not be needed for `[T; N]::split_array` as that can be compile-time checked. Edit: actually, since split_at_unchecked is internal-only it could be changed to be split_array-only.
This mimicks the functionality added by array_chunks, and implements a const-generic form of
windows
. It makes egregious use ofunsafe
, but by necessity because the array must bere-interpreted as a slice of arrays, and unlike array_chunks this cannot be done by casting the
original array once, since each time the index is advanced it needs to move one element, not
N
.I'm planning on adding more tests, but this should be good enough as a premise for the functionality.
Notably: should there be more functions overwritten for the iterator implementation/in general?
I've marked the issue as #74985 as there is no corresponding exact issue forarray_windows
, but it's based of offarray_chunks
.Edit: See Issue #75027 created by @lcnr for tracking issue
Do not merge until I add more tests, please.r? @lcnr