about summary refs log tree commit diff
path: root/library/core/tests
AgeCommit message (Collapse)AuthorLines
2022-02-28Rollup merge of #89793 - ibraheemdev:from_ptr_range, r=m-ou-seMatthias Krüger-0/+23
Add `slice::{from_ptr_range, from_mut_ptr_range} ` Adds `slice::{from_ptr_range, from_mut_ptr_range}` as counterparts to `slice::{as_ptr_range, as_mut_ptr_range}`.
2022-02-27add `slice::{from_ptr_range, from_mut_ptr_range}`Ibraheem Ahmed-0/+23
2022-02-25Switch bootstrap cfgsMark Rousskov-4/+0
2022-02-19Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplettMatthias Krüger-1/+1
Stabilize `#[cfg(panic = "...")]` [Stabilization PR](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr) for #77443
2022-02-16Add a `try_collect()` helper method to `Iterator`Arthur Lafrance-0/+47
Tweaked `try_collect()` to accept more `Try` types Updated feature attribute for tracking issue
2022-02-14Write {ui,} tests for `pin_macro` and `pin!`Daniel Henry-Mantilla-0/+35
2022-02-10added spaceCharisee-1/+1
2022-02-10add cfg_panic bootstrapCharisee-0/+6
2022-02-10remove mention of cfg_panic from library testsCharisee-6/+0
2022-02-10replace feature expression (cfg_panic) in lib and remove expression from testsCharisee-1/+1
Rebase commit
2022-02-09Stabilize cfg_target_has_atomicAmanieu d'Antras-1/+1
Closes #32976
2022-02-02add teststamaron-0/+24
2022-02-01Rollup merge of #91828 - oxalica:feat/waker-getters, r=dtolnayMatthias Krüger-0/+24
Implement `RawWaker` and `Waker` getters for underlying pointers implement #87021 New APIs: - `RawWaker::data(&self) -> *const ()` - `RawWaker::vtable(&self) -> &'static RawWakerVTable` - ~`Waker::as_raw_waker(&self) -> &RawWaker`~ `Waker::as_raw(&self) -> &RawWaker` This third one is an auxiliary function to make the two APIs above more useful. Since we can only get `&Waker` in `Future::poll`, without this, we need to `transmute` it into `&RawWaker` (relying on `repr(transparent)`) in order to access its data/vtable pointers. ~Not sure if it should be named `as_raw` or `as_raw_waker`. Seems we always use `as_<something-raw>` instead of just `as_raw`. But `as_raw_waker` seems not quite consistent with `Waker::from_raw`.~ As suggested in https://github.com/rust-lang/rust/pull/91828#discussion_r770729837, use `as_raw`.
2022-02-01Auto merge of #86988 - thomcc:chunky-splitz-says-no-checking, r=the8472bors-0/+102
Carefully remove bounds checks from some chunk iterator functions So, I was writing code that requires the equivalent of `rchunks(N).rev()` (which isn't the same as forward `chunks(N)` — in particular, if the buffer length is not a multiple of `N`, I must handle the "remainder" first). I happened to look at the codegen output of the function (I was actually interested in whether or not a nested loop was being unrolled — it was), and noticed that in the outer `rchunks(n).rev()` loop, LLVM seemed to be unable to remove the bounds checks from the iteration: https://rust.godbolt.org/z/Tnz4MYY8f (this panic was from the split_at in `RChunks::next_back`). After doing some experimentation, it seems all of the `next_back` in the non-exact chunk iterators have the issue: (`Chunks::next_back`, `RChunks::next_back`, `ChunksMut::next_back`, and `RChunksMut::next_back`)... Even worse, the forward `rchunks` iterators sometimes have the issue as well (... but only sometimes). For example https://rust.godbolt.org/z/oGhbqv53r has bounds checks, but if I uncomment the loop body, it manages to remove the check (which is bizarre, since I'd expect the opposite...). I suspect it's highly dependent on the surrounding code, so I decided to remove the bounds checks from them anyway. Overall, this change includes: - All `next_back` functions on the non-`Exact` iterators (e.g. `R?Chunks(Mut)?`). - All `next` functions on the non-exact rchunks iterators (e.g. `RChunks(Mut)?`). I wasn't able to catch any of the other chunk iterators failing to remove the bounds checks (I checked iterations over `r?chunks(_exact)?(_mut)?` with constant chunk sizes under `-O3`, `-Os`, and `-Oz`), which makes sense, since these were the cases where it was harder to prove the bounds check correct to remove... In fact, it took quite a bit of thinking to convince myself that using unchecked_ here was valid — so I'm not really surprised that LLVM had trouble (although compilers are slightly better at this sort of reasoning than humans). A consequence of that is the fact that the `// SAFETY` comment for these are... kinda long... --- I didn't do this for, or even think about it for, any of the other iteration methods; just `next` and `next_back` (where it mattered). If this PR is accepted, I'll file a follow up for someone (possibly me) to look at the others later (in particular, `nth`/`nth_back` looked like they had similar logic), but I wanted to do this now, as IMO `next`/`next_back` are the most important here, since they're what gets used by the iteration protocol. --- Note: While I don't expect this to impact performance directly, the panic is a side effect, which would otherwise not exist in these loops. That is, this could prevent the compiler from being able to move/remove/otherwise rework a loop over these iterators (as an example, it could not delete the code for a loop whose body computes a value which doesn't get used). Also, some like to be able to have confidence this code has no panicking branches in the optimized code, and "no bounds checks" is kinda part of the selling point of Rust's iterators anyway.
2022-01-31Improve test coverage of {Chunks,RChunks,RChunksMut}::{next,next_back}Thom Chiovoloni-0/+102
2022-01-31Auto merge of #93498 - matthiaskrgr:rollup-k5shwrc, r=matthiaskrgrbors-0/+27
Rollup of 8 pull requests Successful merges: - #90277 (Improve terminology around "after typeck") - #92918 (Allow eliding GATs in expression position) - #93039 (Don't suggest inaccessible fields) - #93155 (Switch pretty printer to block-based indentation) - #93214 (Respect doc(hidden) when suggesting available fields) - #93347 (Make `char::DecodeUtf16::size_hist` more precise) - #93392 (Clarify documentation on char::MAX) - #93444 (Fix some CSS warnings and errors from VS Code) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-31Rollup merge of #93480 - est31:remove_unstable_deprecated, r=Mark-SimulacrumMatthias Krüger-1/+0
Remove deprecated and unstable slice_partition_at_index functions They have been deprecated since commit 01ac5a97c90c26ac35ca9d65f685dd6701edfa3b which was part of the 1.49.0 release, so from the point of nightly, 11 releases ago.
2022-01-31Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_hint, ↵Matthias Krüger-0/+27
r=dtolnay Make `char::DecodeUtf16::size_hist` more precise New implementation takes into account contents of `self.buf` and rounds lower bound up instead of down. Fixes #88762 Revival of #88763
2022-01-30Rollup merge of #92887 - pietroalbini:pa-bootstrap-update, r=Mark-SimulacrumEric Huss-3/+0
Bootstrap compiler update r? ``@Mark-Simulacrum``
2022-01-30Remove deprecated and unstable slice_partition_at_index functionsest31-1/+0
They have been deprecated since commit 01ac5a97c90c26ac35ca9d65f685dd6701edfa3b which was part of the 1.49.0 release, so from the point of nightly, 11 releases ago.
2022-01-30Fix an edge case in `chat::DecodeUtf16::size_hint`Maybe Waffle-0/+1
There are cases, when data in the buf might or might not be an error.
2022-01-29Rollup merge of #93236 - woppopo:const_nonnull_new, r=oli-obkMatthias Krüger-0/+17
Make `NonNull::new` `const` Tracking issue: #93235
2022-01-29Rollup merge of #92274 - woppopo:const_deallocate, r=oli-obkMatthias Krüger-0/+23
Add `intrinsics::const_deallocate` Tracking issue: #79597 Related: #91884 This allows deallocation of a memory allocated by `intrinsics::const_allocate`. At the moment, this can be only used to reduce memory usage, but in the future this may be useful to detect memory leaks (If an allocated memory remains after evaluation, raise an error...?).
2022-01-28update cfg(bootstrap)sPietro Albini-3/+0
2022-01-28Add a test case for using NonNull::new in const contextwoppopo-0/+17
2022-01-28Fix wrong assumption in `DecodeUtf16::size_hint`Maybe Waffle-1/+2
`self.buf` can contain a surrogate, but only a leading one.
2022-01-28test_const_allocate_at_runtimewoppopo-1/+10
2022-01-27Add a test for `char::DecodeUtf16::size_hint`Maybe Waffle-0/+25
2022-01-26`const_deallocate`: Don't deallocate memory allocated in an another const. ↵woppopo-0/+14
Does nothing at runtime. `const_allocate`: Returns a null pointer at runtime.
2022-01-23Rollup merge of #91122 - dtolnay:not, r=m-ou-seMatthias Krüger-0/+6
impl Not for ! The lack of this impl caused trouble for me in some degenerate cases of macro-generated code of the form `if !$cond {...}`, even without `feature(never_type)` on a stable compiler. Namely if `$cond` contains a `return` or `break` or similar diverging expression, which would otherwise be perfectly legal in boolean position, the code previously failed to compile with: ```console error[E0600]: cannot apply unary operator `!` to type `!` --> library/core/tests/ops.rs:239:8 | 239 | if !return () {} | ^^^^^^^^^^ cannot apply unary operator `!` ```
2022-01-15Rollup merge of #92747 - swenson:bignum-bit-length-optimization, r=scottmcmMatthias Krüger-0/+35
Simplification of BigNum::bit_length As indicated in the comment, the BigNum::bit_length function could be optimized by using CLZ, which is often a single instruction instead a loop. I think the code is also simpler now without the loop. I added some additional tests for Big8x3 and Big32x40 to ensure that there were no regressions.
2022-01-14Rollup merge of #92768 - ojeda:stabilize-maybe_uninit_extra, r=Mark-SimulacrumMatthias Krüger-1/+1
Partially stabilize `maybe_uninit_extra` This covers: ```rust impl<T> MaybeUninit<T> { pub unsafe fn assume_init_read(&self) -> T { ... } pub unsafe fn assume_init_drop(&mut self) { ... } } ``` It does not cover the const-ness of `write` under `const_maybe_uninit_write` nor the const-ness of `assume_init_read` (this commit adds `const_maybe_uninit_assume_init_read` for that). FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-11Partially stabilize `maybe_uninit_extra`Miguel Ojeda-1/+1
This covers: impl<T> MaybeUninit<T> { pub unsafe fn assume_init_read(&self) -> T { ... } pub unsafe fn assume_init_drop(&mut self) { ... } } It does not cover the const-ness of `write` under `const_maybe_uninit_write` nor the const-ness of `assume_init_read` (this commit adds `const_maybe_uninit_assume_init_read` for that). FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-10Simplification of BigNum::bit_lengthChristopher Swenson-0/+35
As indicated in the comment, the BigNum::bit_length function could be optimized by using CLZ, which is often a single instruction instead a loop. I think the code is also simpler now without the loop. I added some additional tests for Big8x3 and Big32x40 to ensure that there were no regressions.
2022-01-09eplace usages of vec![].into_iter with [].into_iterLucas Kent-10/+10
2021-12-24Auto merge of #92226 - woppopo:const_black_box, r=joshtriplettbors-0/+19
Constify `core::intrinsics::black_box` and `core::hint::black_box`. `core::intrinsics::black_box` is already constified, but it wasn't marked as const (see: https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs#L471). Tracking issue: None
2021-12-23Rollup merge of #92121 - RalfJung:miri-core-test, r=kennytmMatthias Krüger-0/+1
disable test with self-referential generator on Miri Running the libcore test suite in Miri currently fails due to the known incompatibility of self-referential generators with Miri's aliasing checks (https://github.com/rust-lang/unsafe-code-guidelines/issues/148). So let's disable that test in Miri for now.
2021-12-23Constify `core::intrinsics::black_box`woppopo-0/+19
2021-12-23Rollup merge of #88858 - spektom:to_lower_upper_rev, r=dtolnayMatthias Krüger-0/+6
Allow reverse iteration of lowercase'd/uppercase'd chars The PR implements `DoubleEndedIterator` trait for `ToLowercase` and `ToUppercase`. This enables reverse iteration of lowercase/uppercase variants of character sequences. One of use cases: determining whether a char sequence is a suffix of another one. Example: ```rust fn endswith_ignore_case(s1: &str, s2: &str) -> bool { for eob in s1 .chars() .flat_map(|c| c.to_lowercase()) .rev() .zip_longest(s2.chars().flat_map(|c| c.to_lowercase()).rev()) { match eob { EitherOrBoth::Both(c1, c2) => { if c1 != c2 { return false; } } EitherOrBoth::Left(_) => return true, EitherOrBoth::Right(_) => return false, } } true } ```
2021-12-20disable test with self-referential generator on MiriRalf Jung-0/+1
2021-12-19Rollup merge of #91141 - jhpratt:int_roundings, r=joshtriplettMatthias Krüger-22/+22
Revert "Temporarily rename int_roundings functions to avoid conflicts" This reverts commit 3ece63b64e192146fcdd1724e25856a93d7626aa. This should be okay because #90329 has been merged. r? `@joshtriplett`
2021-12-18Auto merge of #92062 - matthiaskrgr:rollup-en3p4sb, r=matthiaskrgrbors-0/+33
Rollup of 7 pull requests Successful merges: - #91439 (Mark defaulted `PartialEq`/`PartialOrd` methods as const) - #91516 (Improve suggestion to change struct field to &mut) - #91896 (Remove `in_band_lifetimes` for `rustc_passes`) - #91909 (:arrow_up: rust-analyzer) - #91922 (Remove `in_band_lifetimes` from `rustc_mir_dataflow`) - #92025 (Revert "socket ancillary data implementation for dragonflybsd.") - #92030 (Update stdlib to the 2021 edition) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-18Rollup merge of #91439 - ecstatic-morse:const-cmp-trait-default-methods, ↵Matthias Krüger-0/+33
r=oli-obk Mark defaulted `PartialEq`/`PartialOrd` methods as const WIthout it, `const` impls of these traits are unpleasant to write. I think this kind of change is allowed now. although it looks like it might require some Miri tweaks. Let's find out. r? ```@fee1-dead```
2021-12-18Rollup merge of #91928 - fee1-dead:constification1, r=oli-obkMatthias Krüger-10/+90
Constify (most) `Option` methods r? ``@oli-obk``
2021-12-17Auto merge of #91838 - scottmcm:array-slice-eq-via-arrays-not-slices, r=dtolnaybors-0/+44
Do array-slice equality via array equality, rather than always via slices ~~Draft because it needs a rebase after #91766 eventually gets through bors.~~ This enables the optimizations from #85828 to be used for array-to-slice comparisons too, not just array-to-array. For example, <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=5f9ba69b3d5825a782f897c830d3a6aa> ```rust pub fn demo(x: &[u8], y: [u8; 4]) -> bool { *x == y } ``` Currently writes the array to stack for no reason: ```nasm sub rsp, 4 mov dword ptr [rsp], edx cmp rsi, 4 jne .LBB0_1 mov eax, dword ptr [rdi] cmp eax, dword ptr [rsp] sete al add rsp, 4 ret .LBB0_1: xor eax, eax add rsp, 4 ret ``` Whereas with the change in this PR it just compares it directly: ```nasm cmp rsi, 4 jne .LBB1_1 cmp dword ptr [rdi], edx sete al ret .LBB1_1: xor eax, eax ret ```
2021-12-17Constify (most) `Option` methodsDeadbeef-10/+90
2021-12-16Disable test on bootstrap compilerDylan MacKenzie-20/+25
2021-12-16Test const impl of `cmp` traitsDylan MacKenzie-0/+28
2021-12-17Implement data and vtable getters for `RawWaker`oxalica-0/+24
2021-12-15Rollup merge of #91918 - ↵Matthias Krüger-0/+15
fee1-dead:constification0-the-great-constification-begins, r=oli-obk Constify `bool::then{,_some}` Note on `~const Drop`: it has no effect when called from runtime functions, when called from const contexts, the trait system ensures that the type can be dropped in const contexts.