about summary refs log tree commit diff
path: root/library/core/tests
AgeCommit message (Collapse)AuthorLines
2022-10-07make const_err a hard errorRalf Jung-3/+0
2022-10-03Rollup merge of #101308 - nerdypepper:feature/is-ascii-octdigit, r=joshtriplettMatthias Krüger-0/+19
introduce `{char, u8}::is_ascii_octdigit` This feature adds two new APIs: `char::is_ascii_octdigit` and `u8::is_ascii_octdigit`, under the feature gate `is_ascii_octdigit`. These methods are shorthands for `char::is_digit(self, 8)` and `u8::is_digit(self, 8)`: ```rust // core::char impl char { pub fn is_ascii_octdigit(self) -> bool; } // core::num impl u8 { pub fn is_ascii_octdigit(self) -> bool; } ``` --- Couple of things I need help understanding: - `const`ness: have I used the right attribute in this case? - is there a way to run the tests for `core::char` alone, instead of `./x.py test library/core`?
2022-10-02add tests for panicking integer logarithmsLukas Markeffsky-0/+30
2022-09-29Fix integer overflow in `format!("{:.0?}", Duration::MAX)`beetrees-1/+23
2022-09-27Sort modwoppopo-1/+1
2022-09-27Fix indentwoppopo-11/+11
2022-09-27Add newlineswoppopo-2/+2
2022-09-27Add test cases for const `Location`woppopo-0/+34
2022-09-27Stabilize bench_black_boxUrgau-1/+0
2022-09-27introduce `{char, u8}::is_ascii_octdigit`Akshay-0/+19
2022-09-14Made from_waker, waker, from_raw consty86-dev-1/+17
2022-09-09Auto merge of #93873 - Stovent:big-ints, r=m-ou-sebors-0/+49
Reimplement `carrying_add` and `borrowing_sub` for signed integers. As per the discussion in #85532, this PR reimplements `carrying_add` and `borrowing_sub` for signed integers. It also adds unit tests for both unsigned and signed integers, emphasing on the behaviours of the methods.
2022-09-02Rollup merge of #99583 - shepmaster:provider-plus-plus, r=yaahcGuillaume Gomez-1/+1
Add additional methods to the Demand type This adds on to the original tracking issue #96024 r? `````@yaahc`````
2022-08-29Rollup merge of #100819 - WaffleLapkin:use_ptr_byte_methods, r=scottmcmDylan DPC-2/+2
Make use of `[wrapping_]byte_{add,sub}` These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code. Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing. r? ``@scottmcm`` _split off from #100746_
2022-08-26Rollup merge of #100604 - dtolnay:okorerr, r=m-ou-seYuki Okushi-10/+0
Remove unstable Result::into_ok_or_err Pending FCP: https://github.com/rust-lang/rust/issues/82223#issuecomment-1214920203 ```@rustbot``` label +waiting-on-fcp
2022-08-24Rollup merge of #100220 - scottmcm:fix-by-ref-sized, r=joshtriplettMatthias Krüger-0/+21
Properly forward `ByRefSized::fold` to the inner iterator cc ``@timvermeulen,`` who noticed this mistake in https://github.com/rust-lang/rust/pull/100214#issuecomment-1207317625
2022-08-23Make use of `[wrapping_]byte_{add,sub}`Maybe Waffle-2/+2
...replacing `.cast().wrapping_offset().cast()` & similar code.
2022-08-23Support eager and lazy methods for providing references and valuesJake Goulding-1/+1
There are times where computing a value may be cheap, or where computing a reference may be expensive, so this fills out the possibilities.
2022-08-20Rollup merge of #99544 - dylni:expose-utf8lossy, r=Mark-SimulacrumMatthias Krüger-69/+70
Expose `Utf8Lossy` as `Utf8Chunks` This PR changes the feature for `Utf8Lossy` from `str_internals` to `utf8_lossy` and improves the API. This is done to eventually expose the API as stable. Proposal: rust-lang/libs-team#54 Tracking Issue: #99543
2022-08-20Expose `Utf8Lossy` as `Utf8Chunks`dylni-69/+70
2022-08-19Auto merge of #99541 - timvermeulen:flatten_cleanup, r=the8472bors-0/+42
Refactor iteration logic in the `Flatten` and `FlatMap` iterators The `Flatten` and `FlatMap` iterators both delegate to `FlattenCompat`: ```rust struct FlattenCompat<I, U> { iter: Fuse<I>, frontiter: Option<U>, backiter: Option<U>, } ``` Every individual iterator method that `FlattenCompat` implements needs to carefully manage this state, checking whether the `frontiter` and `backiter` are present, and storing the current iterator appropriately if iteration is aborted. This has led to methods such as `next`, `advance_by`, and `try_fold` all having similar code for managing the iterator's state. I have extracted this common logic of iterating the inner iterators with the option to exit early into a `iter_try_fold` method: ```rust impl<I, U> FlattenCompat<I, U> where I: Iterator<Item: IntoIterator<IntoIter = U>>, { fn iter_try_fold<Acc, Fold, R>(&mut self, acc: Acc, fold: Fold) -> R where Fold: FnMut(Acc, &mut U) -> R, R: Try<Output = Acc>, { ... } } ``` It passes each of the inner iterators to the given function as long as it keep succeeding. It takes care of managing `FlattenCompat`'s state, so that the actual `Iterator` methods don't need to. The resulting code that makes use of this abstraction is much more straightforward: ```rust fn next(&mut self) -> Option<U::Item> { #[inline] fn next<U: Iterator>((): (), iter: &mut U) -> ControlFlow<U::Item> { match iter.next() { None => ControlFlow::CONTINUE, Some(x) => ControlFlow::Break(x), } } self.iter_try_fold((), next).break_value() } ``` Note that despite being implemented in terms of `iter_try_fold`, `next` is still able to benefit from `U`'s `next` method. It therefore does not take the performance hit that implementing `next` directly in terms of `Self::try_fold` causes (in some benchmarks). This PR also adds `iter_try_rfold` which captures the shared logic of `try_rfold` and `advance_back_by`, as well as `iter_fold` and `iter_rfold` for folding without early exits (used by `fold`, `rfold`, `count`, and `last`). Benchmark results: ``` before after bench_flat_map_sum 423,255 ns/iter 414,338 ns/iter bench_flat_map_ref_sum 1,942,139 ns/iter 2,216,643 ns/iter bench_flat_map_chain_sum 1,616,840 ns/iter 1,246,445 ns/iter bench_flat_map_chain_ref_sum 4,348,110 ns/iter 3,574,775 ns/iter bench_flat_map_chain_option_sum 780,037 ns/iter 780,679 ns/iter bench_flat_map_chain_option_ref_sum 2,056,458 ns/iter 834,932 ns/iter ``` I added the last two benchmarks specifically to demonstrate an extreme case where `FlatMap::next` can benefit from custom internal iteration of the outer iterator, so take it with a grain of salt. We should probably do a perf run to see if the changes to `next` are worth it in practice.
2022-08-17Remove unstable Result::into_ok_or_errDavid Tolnay-10/+0
2022-08-14Properly forward `ByRefSized::fold` to the inner iteratorScott McMurray-0/+21
2022-08-14fix(iter::skip): Optimize `next` and `nth` implementations of `Skip`austinabell-0/+31
2022-08-14Rollup merge of #100026 - WaffleLapkin:array-chunks, r=scottmcmDylan DPC-0/+203
Add `Iterator::array_chunks` (take N+1) A revival of https://github.com/rust-lang/rust/pull/92393. r? `@Mark-Simulacrum` cc `@rossmacarthur` `@scottmcm` `@the8472` I've tried to address most of the review comments on the previous attempt. The only thing I didn't address is `try_fold` implementation, I've left the "custom" one for now, not sure what exactly should it use.
2022-08-12Rollup merge of #100030 - WaffleLapkin:nice_pointer_sis, r=scottmcmDylan DPC-3/+5
cleanup code w/ pointers in std a little Use pointer methods (`byte_add`, `null_mut`, etc) to make code in std a little nicer.
2022-08-11Rollup merge of #100112 - RalfJung:assert_send_and_sync, r=m-ou-seMatthias Krüger-1/+2
Fix test: chunks_mut_are_send_and_sync Follow-up to https://github.com/rust-lang/rust/pull/100023 to make the test actually effective
2022-08-10Auto merge of #99174 - scottmcm:reoptimize-layout-array, r=joshtriplettbors-0/+44
Reoptimize layout array This way it's one check instead of two, so hopefully (cc #99117) it'll be simpler for rustc perf too 🤞 Quick demonstration: ```rust pub fn demo(n: usize) -> Option<Layout> { Layout::array::<i32>(n).ok() } ``` Nightly: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e97bf33508aa03f38968101cdeb5322d> ```nasm mov rax, rdi mov ecx, 4 mul rcx seto cl movabs rdx, 9223372036854775805 xor esi, esi cmp rax, rdx setb sil shl rsi, 2 xor edx, edx test cl, cl cmove rdx, rsi ret ``` This PR (note no `mul`, in addition to being much shorter): ```nasm xor edx, edx lea rax, [4*rcx] shr rcx, 61 sete dl shl rdx, 2 ret ``` This is built atop `@CAD97` 's #99136; the new changes are cb8aba66ef6a0e17f08a0574e4820653e31b45a0. I added a bunch more tests for `Layout::from_size_align` and `Layout::array` too.
2022-08-09Rename integer log* methods to ilog*Eric Holk-78/+78
This reflects the concensus from the libs team as reported at https://github.com/rust-lang/rust/issues/70887#issuecomment-1209513261 Co-authored-by: Yosh Wuyts <github@yosh.is>
2022-08-05cleanup code w/ pointers in std a littleMaybe Waffle-3/+5
2022-08-05Move `fold` logic to `iter_fold` method and reuse it in `count` and `last`Tim Vermeulen-0/+42
2022-08-03actually call assert_send_and_syncRalf Jung-1/+2
2022-08-01Remove incorrect impl `TrustedLen` for `ArrayChunks`Maybe Waffle-1/+1
As explained in the review of the previous attempt to add `ArrayChunks`, adapters that shrink the length can't implement `TrustedLen`.
2022-08-01Add back Send and Sync impls on ChunksMut iteratorsBen Kimock-0/+21
These were accidentally removed in #94247 because the representation was changed from &mut [T] to *mut T, which has !Send + !Sync.
2022-08-01Use `array::IntoIter` for the `ArrayChunks` remainderRoss MacArthur-24/+5
2022-08-01Add `Iterator::array_chunks()`Ross MacArthur-0/+222
2022-07-27Rollup merge of #94247 - saethlin:chunksmut-aliasing, r=the8472Guillaume Gomez-0/+44
Fix slice::ChunksMut aliasing Fixes https://github.com/rust-lang/rust/issues/94231, details in that issue. cc `@RalfJung` This isn't done just yet, all the safety comments are placeholders. But otherwise, it seems to work. I don't really like this approach though. There's a lot of unsafe code where there wasn't before, but as far as I can tell the only other way to uphold the aliasing requirement imposed by `__iterator_get_unchecked` is to use raw slices, which I think require the same amount of unsafe code. All that would do is tie the `len` and `ptr` fields together. Oh I just looked and I'm pretty sure that `ChunksExactMut`, `RChunksMut`, and `RChunksExactMut` also need to be patched. Even more reason to put up a draft.
2022-07-22Auto merge of #99491 - workingjubilee:sync-psimd, r=workingjubileebors-0/+1
Sync in portable-simd subtree r? `@ghost`
2022-07-20Introduce core::simd trait imports in testsJubilee Young-0/+1
2022-07-19Auto merge of #98912 - nrc:provider-it, r=yaahcbors-11/+11
core::any: replace some generic types with impl Trait This gives a cleaner API since the caller only specifies the concrete type they usually want to. r? `@yaahc`
2022-07-19Rollup merge of #99434 - timvermeulen:skip_next_non_fused, r=scottmcmDylan DPC-0/+11
Fix `Skip::next` for non-fused inner iterators `iter.skip(n).next()` will currently call `nth` and `next` in succession on `iter`, without checking whether `nth` exhausts the iterator. Using `?` to propagate a `None` value returned by `nth` avoids this.
2022-07-18Add note to test about `Unfuse`Tim Vermeulen-0/+3
2022-07-18Fix `Skip::next` for non-fused inner iteratorsTim Vermeulen-0/+8
2022-07-18Rollup merge of #98839 - 5225225:assert_transmute_copy_size, r=thomccDylan DPC-0/+40
Add assertion that `transmute_copy`'s U is not larger than T This is called out as a safety requirement in the docs, but because knowing this can be done at compile time and constant folded (just like the `align_of` branch is removed), we can just panic here. I've looked at the asm (using `cargo-asm`) of a function that both is correct and incorrect, and the panic is completely removed, or is unconditional, without needing build-std. I don't expect this to cause much breakage in the wild. I scanned through https://miri.saethlin.dev/ub for issues that would look like this (error: Undefined Behavior: memory access failed: alloc1768 has size 1, so pointer to 8 bytes starting at offset 0 is out-of-bounds), but couldn't find any. That doesn't rule out it happening in crates tested that fail earlier for some other reason, though, but it indicates that doing this is rare, if it happens at all. A crater run for this would need to be build and test, since this is a runtime thing. Also added a few more transmute_copy tests.
2022-07-17Rollup merge of #99306 - JohnTitor:stabilize-future-poll-fn, r=joshtriplettYuki Okushi-1/+0
Stabilize `future_poll_fn` FCP is done: https://github.com/rust-lang/rust/issues/72302#issuecomment-1179620512 Closes #72302 r? `@joshtriplett` as you started FCP Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-07-16Auto merge of #98866 - nagisa:nagisa/align-offset-wroom, r=Mark-Simulacrumbors-27/+36
Add a special case for align_offset /w stride != 1 This generalizes the previous `stride == 1` special case to apply to any situation where the requested alignment is divisible by the stride. This in turn allows the test case from #98809 produce ideal assembly, along the lines of: leaq 15(%rdi), %rax andq $-16, %rax This also produces pretty high quality code for situations where the alignment of the input pointer isn’t known: pub unsafe fn ptr_u32(slice: *const u32) -> *const u32 { slice.offset(slice.align_offset(16) as isize) } // => movl %edi, %eax andl $3, %eax leaq 15(%rdi), %rcx andq $-16, %rcx subq %rdi, %rcx shrq $2, %rcx negq %rax sbbq %rax, %rax orq %rcx, %rax leaq (%rdi,%rax,4), %rax Here LLVM is smart enough to replace the `usize::MAX` special case with a branch-less bitwise-OR approach, where the mask is constructed using the neg and sbb instructions. This appears to work across various architectures I’ve tried. This change ends up introducing more branches and code in situations where there is less knowledge of the arguments. For example when the requested alignment is entirely unknown. This use-case was never really a focus of this function, so I’m not particularly worried, especially since llvm-mca is saying that the new code is still appreciably faster, despite all the new branching. Fixes #98809. Sadly, this does not help with #72356.
2022-07-17Add a special case for align_offset /w stride != 1Simonas Kazlauskas-27/+36
This generalizes the previous `stride == 1` special case to apply to any situation where the requested alignment is divisible by the stride. This in turn allows the test case from #98809 produce ideal assembly, along the lines of: leaq 15(%rdi), %rax andq $-16, %rax This also produces pretty high quality code for situations where the alignment of the input pointer isn’t known: pub unsafe fn ptr_u32(slice: *const u32) -> *const u32 { slice.offset(slice.align_offset(16) as isize) } // => movl %edi, %eax andl $3, %eax leaq 15(%rdi), %rcx andq $-16, %rcx subq %rdi, %rcx shrq $2, %rcx negq %rax sbbq %rax, %rax orq %rcx, %rax leaq (%rdi,%rax,4), %rax Here LLVM is smart enough to replace the `usize::MAX` special case with a branch-less bitwise-OR approach, where the mask is constructed using the neg and sbb instructions. This appears to work across various architectures I’ve tried. This change ends up introducing more branches and code in situations where there is less knowledge of the arguments. For example when the requested alignment is entirely unknown. This use-case was never really a focus of this function, so I’m not particularly worried, especially since llvm-mca is saying that the new code is still appreciably faster, despite all the new branching. Fixes #98809. Sadly, this does not help with #72356.
2022-07-16Stabilize `future_poll_fn`Yuki Okushi-1/+0
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-07-14Auto merge of #95956 - yaahc:stable-in-unstable, r=cjgillotbors-1/+1
Support unstable moves via stable in unstable items part of https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/moving.20items.20to.20core.20unstably and a blocker of https://github.com/rust-lang/rust/pull/90328. The libs-api team needs the ability to move an already stable item to a new location unstably, in this case for Error in core. Otherwise these changes are insta-stable making them much harder to merge. This PR attempts to solve the problem by checking the stability of path segments as well as the last item in the path itself, which is currently the only thing checked.
2022-07-14Rollup merge of #98315 - joshtriplett:stabilize-core-ffi-c, r=Mark-SimulacrumDylan DPC-1/+0
Stabilize `core::ffi:c_*` and rexport in `std::ffi` This only stabilizes the base types, not the non-zero variants, since those have their own separate tracking issue and have not gone through FCP to stabilize.