about summary refs log tree commit diff
path: root/src/libcore/slice
AgeCommit message (Collapse)AuthorLines
2018-09-21Simplify slice's first(_mut) and last(_mut) with getljedrz-6/+6
2018-09-20define copy_within on slicesJack O'Connor-0/+57
This is a safe wrapper around ptr::copy, for regions within a single slice. Previously, safe in-place copying was only available as a side effect of Vec::drain.
2018-09-17Adjust the docs of `from_raw_parts` to match the implementationTobias Bucher-4/+4
2018-09-17Use more obvious calculation for slice size checkTobias Bucher-4/+2
2018-09-16Auto merge of #53754 - RalfJung:slice_align_to, r=alexcrichtonbors-8/+8
stabilize slice_align_to This is very hard to implement correctly, and leads to [serious bugs](https://github.com/llogiq/bytecount/pull/42) when done incorrectly. Moreover, this is needed to be able to run code that opportunistically exploits alignment on miri. So code using `align_to`/`align_to_mut` gets the benefit of a well-tested implementation *and* of being able to run in miri to test for (some kinds of) UB. This PR also clarifies the guarantee wrt. the middle part being as long as possible. Should the docs say under which circumstances the middle part could be shorter? Currently, that can only happen when running in miri.
2018-09-11Fix overflow in `from_raw_parts` size checkTobias Bucher-3/+5
2018-09-10A slice covering exactly half the address space is not OKTobias Bucher-6/+6
2018-09-04Add `debug_assert!`s to `slice::from_raw_parts`Tobias Bucher-2/+11
Copy the documentation over to `slice::from_raw_parts_mut`.
2018-09-04Document that slices cannot be larger than `isize::MAX` bytesTobias Bucher-0/+4
Fixes #53676.
2018-09-03Link to more detailed docs in `slice::from_raw_parts_mut`Tobias Bucher-4/+7
2018-08-29Fix a comment in src/libcore/slice/mod.rsTobias Bucher-6/+1
2018-08-28stabilize slice_align_toRalf Jung-8/+8
2018-08-21Rollup merge of #53329 - frewsxcv:frewsxcv-ptr-add-sub, r=RalfJungkennytm-35/+35
Replace usages of ptr::offset with ptr::{add,sub}. Rust provides these helper methods – so let's use them!
2018-08-21Rollup merge of #53496 - matthiaskrgr:codespell_08_2018, r=varkorkennytm-3/+3
Fix typos found by codespell.
2018-08-20Replace usages of ptr::offset with ptr::{add,sub}.Corey Farwell-35/+35
2018-08-19Fix typos found by codespell.Matthias Krüger-3/+3
2018-08-19Auto merge of #52972 - RalfJung:from_raw_parts_align, r=alexcrichtonbors-0/+4
debug_assert to ensure that from_raw_parts is only used properly aligned This does not help nearly as much as I would hope because everybody uses the distributed libstd which is compiled without debug assertions. For this reason, I am not sure if this is even worth it. OTOH, this would have caught the misalignment fixed by https://github.com/rust-lang/rust/issues/42789 *if* there had been any tests actually using ZSTs with alignment >1 (we have a CI runner which has debug assertions in libstd enabled), and it seems to currently [fail in the rg testsuite](https://ci.appveyor.com/project/rust-lang/rust/build/1.0.8403/job/v7dfdcgn8ay5j6sb). So maybe it is worth it, after all. I have seen the attribute `#[rustc_inherit_overflow_checks]` in some places, does that make it so that the *caller's* debug status is relevant? Is there a similar attribute for `debug_assert!`? That could even subsume `rustc_inherit_overflow_checks`: Something like `rustc_inherit_debug_flag` could affect *all* places that change the generated code depending on whether we are in debug or release mode. In fact, given that we have to keep around the MIR for generic functions anyway, is there ever a reason *not* to handle the debug flag that way? I guess currently we apply debug flags like `cfg` so this is dropped early during the MIR pipeline? EDIT: I learned from @eddyb that because of how `debug_assert!` works, this is not realistic. Well, we could still have it for the rustc CI runs and then maybe, eventually, when libstd gets compiled client-side and there is both a debug and a release build... then this will also benefit users.^^
2018-08-12Rollup merge of #53059 - ljedrz:unneeded_returns, r=kennytmGuillaume Gomez-10/+10
Remove explicit returns where unnecessary
2018-08-05Correct invalid feature attributesvarkor-5/+5
2018-08-04Remove redundant field names in structsljedrz-6/+6
2018-08-04Remove explicit returns where unnecessaryljedrz-10/+10
2018-08-02test that align_of handles alignment properly for the mid partRalf Jung-0/+2
2018-08-02debug_assert to ensure that from_raw_parts is only used properly alignedRalf Jung-0/+2
2018-08-02Auto merge of #52206 - RalfJung:zst-slices, r=alexcrichtonbors-212/+151
slices: fix ZST slice iterators making up pointers; debug_assert alignment in from_raw_parts This fixes the problem that we are fabricating pointers out of thin air. I also managed to share more code between the mutable and shared iterators, while reducing the amount of macros. I am not sure how useful it really is to add a `debug_assert!` in libcore. Everybody gets a release version of that anyway, right? Is there at least a CI job that runs the test suite with a debug version? Fixes #42789
2018-08-02use the same length computation everywhereRalf Jung-21/+10
2018-08-02Introduce another way to compute the length, to fix position codegen regressionRalf Jung-8/+21
2018-08-02simplify len macro: No longer require the typeRalf Jung-12/+19
Also use ident, not expr, to avoid accidental side-effects
2018-08-02macro-inline len() and is_empty() to fix performance regressionsRalf Jung-20/+29
This also changes the IR for nth(), but the new IR actually looks nicer that the old (and it is one instruction shorter).
2018-08-02make the code for nth closer to what it used to beRalf Jung-3/+4
2018-08-02use wrapping_offset; fix logic error in nthRalf Jung-10/+12
2018-08-02commentsRalf Jung-2/+3
2018-08-02slice iterators: ZST iterators no longer just "make up" addressesRalf Jung-211/+128
2018-07-30fix memrchr in miriRalf Jung-10/+16
2018-07-28Auto merge of #52744 - RalfJung:align_offset, r=Kimundibors-10/+7
make memrchr use align_offset I hope I did not screw that up... Cc @oli-obk who authored the original https://github.com/rust-lang/rust/pull/44537 Fixes #50567 (thanks @bjorn3)
2018-07-27use slice::align_toRalf Jung-26/+7
2018-07-26make memrchr use align_offsetRalf Jung-1/+17
2018-07-19fix safety-related comment in slice::rotateRalf Jung-1/+1
2018-07-13Auto merge of #51622 - kennytm:three-field-range-inclusive, r=SimonSapinbors-10/+10
Change RangeInclusive to a three-field struct. Fix #45222. This PR also reverts #48012 (i.e. removed the `try_fold`/`try_rfold` specialization for `RangeInclusive`) because LLVM no longer has trouble recognizing a RangeInclusive loop.
2018-07-13Change RangeInclusive to a three-field struct.kennytm-10/+10
Fix #45222.
2018-07-12Auto merge of #51339 - sdroege:exact-chunks-remainder, r=alexcrichtonbors-8/+40
Add ExactChunks::remainder and ExactChunks::into_remainder These allow to get the leftover items of the slice that are not being iterated as part of the iterator due to not filling a complete chunk. The mutable version consumes the slice because otherwise we would either a) have to borrow the iterator instead of taking the lifetime of the underlying slice, which is not what *any* of the other iterator functions is doing, or b) would allow returning multiple mutable references to the same data The current behaviour of consuming the iterator is consistent with IterMut::into_slice for the normal iterator. ---- This is related to https://github.com/rust-lang/rust/issues/47115#issuecomment-392685177 and the following comments. While there the discussion was first about a way to get the "tail" of the iterator (everything from the slice that is still not iterated yet), this gives kind of unintuitive behaviour and is inconsistent with how the other slice iterators work. Unintuitive because the `next_back` would have no effect on the tail (or otherwise the tail could not include the remainder items), inconsistent because a) generally the idea of the slice iterators seems to be to only ever return items that were not iterated yet (and don't provide a way to access the same item twice) and b) we would return a "flat" `&[T]` slice but the iterator's shape is `&[[T]]` instead, c) the mutable variant would have to borrow from the iterator instead of the underlying slice (all other iterator functions borrow from the underlying slice!) As such, I've only implemented functions to get the remainder. This also allows the implementation to be completely safe still (and around slices instead of raw pointers), while getting the tail would either be inefficient or would have to be implemented around raw pointers. CC @kerollmops
2018-07-11Rollup merge of #51701 - anirudhb:master, r=frewsxcvGuillaume Gomez-0/+6
Better docs for copy_from_slice & clone_from_slice I copy-pasted the text from clone_from_slice to copy_from_slice :smile: @steveklabnik feel free to suggest changes. edit: closes #49769
2018-07-10Change wording for {copy, clone}_from_sliceAnirudh Balaji-6/+6
2018-07-09Add "or destination" to {copy, clone}_from_slice exampleAnirudh Balaji-4/+4
2018-06-30Auto merge of #51717 - Mark-Simulacrum:snap, r=alexcrichtonbors-3/+0
Bootstrap from 1.28.0 beta
2018-06-30Bootstrap from 1.28.0-beta.3Mark Simulacrum-3/+0
2018-06-28Rollup merge of #51765 - jonas-schievink:patch-1, r=KodrAusMark Rousskov-2/+2
Use assert_eq! in copy_from_slice This will print both lengths when the assertion fails instead of just saying that they're different. Output of current stable and nightly (modulo the exact line number): ``` thread 'main' panicked at 'destination and source slices have different lengths', libcore/slice/mod.rs:1645:9 ``` Output after this PR: ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `123`, right: `456`: destination and source slices have different lengths', libcore/slice/mod.rs:1645:9 ``` Note that I have not run the tests locally.
2018-06-27Nit: Remove leading whitespaceAnirudh Balaji-2/+2
2018-06-26migrate codebase to `..=` inclusive range patternsZack M. Davis-3/+3
These were stabilized in March 2018's #47813, and are the Preferred Way to Do It going forward (q.v. #51043).
2018-06-24Make line-breaking more consistent.Anirudh Balaji-8/+6
2018-06-24Use assert_eq! in copy_from_sliceJonas Schievink-2/+2
This will print both lengths when the assertion fails instead of just saying that they're different.