Commit Graph

296 Commits

Author SHA1 Message Date
David Tolnay
95e00bfed8 Format libcore with rustfmt
This commit applies rustfmt with default settings to files in
src/libcore *that are not involved in any currently open PR* to minimize
merge conflicts. The list of files involved in open PRs was determined
by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in `outstanding_files`, the
relevant commands were:

    $ find src/libcore -name '*.rs' | xargs rustfmt --edition=2018
    $ rg libcore outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of libcore.
2019-11-26 23:02:11 -08:00
Mazdak Farrokhzad
379b19c17f Rollup merge of #63793 - oli-obk:🧹, r=dtolnay
Have tidy ensure that we document all `unsafe` blocks in libcore

cc @rust-lang/libs

I documented a few and added ignore flags on the other files. We can incrementally document the files, but won't regress any files this way.
2019-11-07 14:27:20 +01:00
Oliver Scherer
02f9167f94 Have tidy ensure that we document all unsafe blocks in libcore 2019-11-06 11:04:42 +01:00
Ralf Jung
b1d0a68fd7 fix link to ptr docs 2019-11-05 13:22:43 +01:00
Ralf Jung
1a254e4f43 expand slice from_raw_part docs 2019-11-05 09:55:33 +01:00
Mara Bos
381c4425b7 Fix slice::as_ptr_range doctest. 2019-10-25 18:01:31 +02:00
Mara Bos
de9b660a40 Explain why pointer::add in slice::as_ptr_range is safe. 2019-10-25 15:46:42 +02:00
Mara Bos
f1b69b0a87 Add slice_ptr_range tracking issue number. 2019-10-25 14:33:07 +02:00
Mara Bos
4936f96d42 Add [T]::as_ptr_range() and [T]::as_mut_ptr_range().
See https://github.com/rust-lang/rfcs/pull/2791 for motivation.
2019-10-25 14:09:32 +02:00
Mark Rousskov
d0a6805b0e Allow unused attributes to avoid incremental bug 2019-10-04 11:11:58 -04:00
bors
e0436d912d Auto merge of #64600 - scottmcm:no-slice-tryfold-unroll, r=bluss
Remove manual unrolling from slice::Iter(Mut)::try_fold

While this definitely helps sometimes (particularly for trivial closures), it's also a pessimization sometimes, so it's better to leave this to (hypothetical) future LLVM improvements instead of forcing this on everyone.

I think it's better for the advice to be that sometimes you need to unroll manually than you sometimes need to not-unroll manually (like #64545).

---

For context see https://github.com/rust-lang/rust/pull/64572#issuecomment-532961046
2019-09-30 09:52:29 +00:00
Mark Rousskov
f359a94849 Snap cfgs to new beta 2019-09-25 08:42:46 -04:00
Oliver Scherer
7767e7fb16 Stabilize str::len, [T]::len, is_empty and str::as_bytes as const fn 2019-09-24 12:56:44 +02:00
Scott McMurray
6ac64abd6d Just delete the overrides now that they match the default implementations 2019-09-23 23:10:45 -07:00
Scott McMurray
92e91f7541 Remove manual unrolling from slice::Iter(Mut)::try_fold
While this definitely helps sometimes (particularly for trivial closures), it's also a pessimization sometimes, so it's better to leave this to (hypothetical) future LLVM improvements instead of forcing this on everyone.

I think it's better for the advice to be that sometimes you need to unroll manually than you sometimes need to not-unroll manually (like #64545).
2019-09-21 21:16:24 -07:00
Mateusz Mikuła
edabcddf4d Apply clippy::let_and_return suggestion 2019-08-22 12:02:02 +02:00
Mazdak Farrokhzad
60649e3a2e Rollup merge of #63265 - JohnTitor:implement-nth-back-for-chunksexactmut, r=scottmcm
Implement `nth_back` for ChunksExactMut

This is a part of #54054.

r? @scottmcm
2019-08-20 16:26:37 +02:00
Lzu Tao
30ba4bd8e2 Use Result::unwrap_or_else instead of matching 2019-08-10 17:16:58 +00:00
Lzu Tao
93839c3fb4 Add an example to show how to insert item to a sorted vec 2019-08-10 16:31:38 +00:00
bors
d8f8be4636 Auto merge of #61937 - AaronKutch:master, r=scottmcm
Improve `ptr_rotate` performance, tests, and benches

The corresponding issue is #61784. I am not actually sure if miri can handle the test, but I can change the commit if necessary.
2019-08-09 04:41:20 +00:00
Aaron Kutch
ad7fdb6859 Improve ptr_rotate performance, tests, and benchmarks 2019-08-06 10:42:48 -05:00
Jake Goulding
571e22d7e8 Clarify align_to's requirements and obligations 2019-08-05 19:44:07 -04:00
Yuki Okushi
d3019d16b9 Implement nth_back for ChunksExactMut 2019-08-05 02:44:08 +09:00
Ralf Jung
9b5623f8bc fix links
relative links do not work because this is included in several places
2019-08-04 09:52:36 +02:00
Ralf Jung
3b9cda4693 Apply suggestions from code review
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-08-03 13:45:15 +02:00
Ralf Jung
f44abba4ec clarify that unchecked indexing is UB even if the reference is never used 2019-08-03 12:46:20 +02:00
Mazdak Farrokhzad
cb8b491a65 Rollup merge of #62074 - wizAmit:feature/mut_chunks_nth_back, r=scottmcm
squash of all commits for nth_back on ChunksMut

wip nth_back for chunks_mut

working chunksmut

fixed nth_back for chunksmut

Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>

r? @timvermeulen
r? @scottmcm
2019-07-28 03:01:44 +02:00
bors
890881f8f4 Auto merge of #60340 - mgeier:cap-vs-capacity, r=alexcrichton
Rename .cap() methods to .capacity()

As mentioned in #60316, there are a few `.cap()` methods, which seem out-of-place because such methods are called `.capacity()` in the rest of the code.

This PR renames them to `.capacity()` but leaves `RawVec::cap()` in there for backwards compatibility.

I didn't try to mark the old version as "deprecated", because I guess this would cause too much noise.
2019-07-25 18:45:42 +00:00
Mark Rousskov
4264f8376a Rollup merge of #62656 - RalfJung:contains-no-own, r=Dylan-DPC
explain how to search in slice without owned data

Cc https://github.com/rust-lang/rust/issues/62367
2019-07-23 12:51:05 -04:00
Ralf Jung
ad261f6852 avoid uninit_array! macro where it is not needed 2019-07-19 17:23:47 +02:00
Ralf Jung
e074db764a use const array repeat expressions for uninit_array 2019-07-19 14:47:56 +02:00
Mark Rousskov
831d33b8b0 Rollup merge of #62728 - DutchGhost:fix-double-wording, r=jonas-schievink
Fix repeated wording in slice documentation

Changes `of the slice of the slice` to `of the slice` in the chunk- and friends documentation of slices
2019-07-18 11:29:42 -04:00
Dodo
9341e90b44 found more repeated wording 2019-07-16 21:57:32 +02:00
Dodo
4785311893 fix double wording 2019-07-16 21:49:01 +02:00
Valentin Tolmer
009c4a7efe Add debug assertions to write_bytes and copy* 2019-07-15 16:56:43 +02:00
Ralf Jung
3f77f2cd5b better comments 2019-07-14 10:03:04 +02:00
Ralf Jung
d73c23d114 explain how to search without owned data 2019-07-13 15:16:05 +02:00
Mazdak Farrokhzad
ea62f9b3ec Rollup merge of #61665 - aschampion:slice-eq-ptr, r=sfackler
core: check for pointer equality when comparing Eq slices

Because `Eq` types must be reflexively equal, an equal-length slice to the same memory location must be equal.

This is related to #33892 (and #32699) answering this comment from that PR:

> Great! One more easy question: why does this optimization not apply in the non-BytewiseEquality implementation directly above?

Because slices of non-reflexively equal types (like `f64`) are not equal even if it's the same slice. But if the types are `Eq`, we can use this same-address optimization, which this PR implements. Obviously this changes behavior if types violate the reflexivity condition of `Eq`, because their impls of `PartialEq` will no longer be called per-item, but 🤷‍♂ .

It's not clear how often this optimization comes up in the real world outside of the same-`&str` case covered by #33892, so **I'm requesting a perf run** (on MacOS today, so can't run `rustc_perf` myself). I'm going ahead and making the PR on the basis of being surprised things didn't already work this way.

This is my first time hacking rust itself, so as a perf sanity check I ran `./x.py bench --stage 0 src/lib{std,alloc}`, but the differences were noisy.

To make the existing specialization for `BytewiseEquality` explicit, it's now a supertrait of `Eq + Copy`. `Eq` should be sufficient, but `Copy` was included for clarity.
2019-07-11 04:33:11 +02:00
bors
78ca1bda35 Auto merge of #62473 - timvermeulen:is_sorted_by_key, r=scottmcm
Only call the closure parameter of Iterator::is_sorted_by_key once per item

See https://github.com/rust-lang/rust/issues/53485#issuecomment-472314004.

This changes `Iterator::is_sorted_by_key` to only call the given closure once for each item, which allows us to pass the items to the closure by value instead of by reference.

**Important**: `is_sorted_by_key` for slices and slice iterators is now no longer implemented in terms of the custom `slice::Iter::is_sorted_by` implementation. It's a trade-off: we could forward `slice::Iter::is_sorted_by_key` to it directly for potential SIMD benefits, but that would mean that the closure is potentially called twice for (almost) every element of the slice.
2019-07-08 12:03:06 +00:00
Tim Vermeulen
98b54fbd7a Only call the closure parameter of Iterator::is_sorted_by_key once per item 2019-07-07 20:46:38 +02:00
@amit.chandra
b95bde4491 squash of all commits for nth_back on ChunksMut
wip nth_back for chunks_mut

working chunksmut

fixed nth_back for chunksmut

Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-06-23 12:45:59 +05:30
@amit.chandra
45832383af squash commit for nth_back on chunks exact
wip nth_back for chunks_exact

working nth_back for chunks exact

Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-06-23 02:02:21 +05:30
Mazdak Farrokhzad
2e7e131b8e Rollup merge of #60772 - timvermeulen:slice_iter_nth_back, r=scottmcm
Implement nth_back for slice::{Iter, IterMut}

Part of #54054.

I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂

I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me.

I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.
2019-06-20 08:36:00 +02:00
Oliver Scherer
8b21b075f7 Add functions to build raw slices 2019-06-19 09:21:44 +02:00
Scott McMurray
af0e35e6a6 Help LLVM better optimize slice::Iter(Mut)::len 2019-06-15 21:15:25 -07:00
Mazdak Farrokhzad
a1ff450a68 Rollup merge of #61398 - kennytm:stabilize-copy-within, r=SimonSapin
Stabilize copy_within

Closes #54236.
2019-06-13 01:49:26 +02:00
Andrew Champion
d3461bf6a0 core: use memcmp optimization for 128 bit integer slices 2019-06-10 18:08:05 +01:00
Andrew Champion
d482589f29 core: use iterators for slice equality comparison 2019-06-08 20:16:50 +01:00
Andrew Champion
30b27f350c core: check for pointer equality when comparing Eq slices
Because Eq types must be reflexively equal, an equal-length slice to the
same memory location must be equal.
2019-06-08 16:26:34 +01:00
kennytm
aac9bc5ffa copy_within: replace element access by pointer arithmetic to avoid UB
This ensures we won't accidentally read *src or *dest even when count = 0.
2019-06-02 23:30:18 +08:00