about summary refs log tree commit diff
path: root/library/core/tests
AgeCommit message (Collapse)AuthorLines
2020-09-18Make some methods of `Pin<&mut T>` unstable constChristiaan Dirkx-1/+12
Make the following methods unstable const under the `const_pin` feature: - `into_ref` - `get_mut` - `get_unchecked_mut`
2020-09-16Rollup merge of #75026 - JulianKnodt:array_windows, r=AmanieuTyler Mandry-0/+50
Add array_windows fn This mimicks the functionality added by array_chunks, and implements a const-generic form of `windows`. It makes egregious use of `unsafe`, but by necessity because the array must be re-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 for `array_windows`, but it's based of off `array_chunks`.~~ Edit: See Issue #75027 created by @lcnr for tracking issue ~~Do not merge until I add more tests, please.~~ r? @lcnr
2020-09-16Add array window fnkadmin-0/+50
Updated issue to #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
2020-09-16Rollup merge of #76366 - ayushmishra2005:arith_tests_in_library, r=jyn514Ralf Jung-0/+29
Add Arith Tests in Library Added Arith Tests library as a part of #76268 r? @matklad
2020-09-16Rollup merge of #76335 - CDirkx:const-duration, r=ecstatic-morseRalf Jung-0/+104
Make all methods of `Duration` unstably const Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Moved the tests to `library` as part of #76268. Possible because of #72449, which made the relevant `f32` and `f64` methods const. Tracking issue: #72440 r? @ecstatic-morse
2020-09-16Rollup merge of #76198 - CDirkx:const-ordering, r=dtolnayDylan DPC-1/+17
Make some Ordering methods const Resubmission of [PR#75463](https://github.com/rust-lang/rust/pull/75463) as per [PR#76172](https://github.com/rust-lang/rust/pull/76172). Constify the following methods of `core::cmp::Ordering`: - `reverse` - `then` Insta-stabilizes these methods as const under the `const_ordering` feature, as their implementation is a trivial match and the recent stabilization of #49146 (Allow `if` and `match` in constants). Note: the `const_ordering` feature has never actually been used as these methods have not been `#[rustc_const_unstable]`. Tracking issue: #76113
2020-09-15Fix to libstd testJubilee Young-42/+44
2020-09-15Move Wrapping<T> ui tests into libraryJubilee Young-0/+77
2020-09-13Make some methods of `Pin` unstable constChristiaan Dirkx-0/+23
Make the following methods unstable const under the `const_pin` feature: - `new` - `new_unchecked` - `into_inner` - `into_inner_unchecked` - `get_ref` - `into_ref` Also adds tests for these methods in a const context. Tracking issue: #76654
2020-09-12Make all methods of `Duration` constChristiaan Dirkx-0/+104
Make the following methods of `Duration` unstable const under `duration_const_2`: - `from_secs_f64` - `from_secs_f32` - `mul_f64` - `mul_f32` - `div_f64` - `div_f32` This results in all methods of `Duration` being (unstable) const. Also adds tests for these methods in a const context, moved the test to `library` as part of #76268. Possible because of #72449, which made the relevant `f32` and `f64` methods const. Tracking issue: #72440
2020-09-12Rollup merge of #76114 - marmeladema:duration-saturating-ops, r=shepmasterRalf Jung-0/+32
Add saturating methods for `Duration` In some project, I needed a `saturating_add` method for `Duration`. I implemented it myself but i thought it would be a nice addition to the standard library as it matches closely with the integers types. 3 new methods have been introduced and are gated by the new `duration_saturating_ops` unstable feature: * `Duration::saturating_add` * `Duration::saturating_sub` * `Duration::saturating_mul` If have left the tracking issue to `none` for now as I want first to understand if those methods would be acceptable at all. If agreed, I'll update the PR with the tracking issue. Further more, to match the behavior of integers types, I introduced 2 associated constants: * `Duration::MIN`: this one is somehow a duplicate from `Duration::zero()` method, but at the time this method was added, `MIN` was rejected as it was considered a different semantic (see https://github.com/rust-lang/rust/pull/72790#issuecomment-636511743). * `Duration::MAX` Both have been gated by the already existing unstable feature `duration_constants`, I can introduce a new unstable feature if needed or just re-use the `duration_saturating_ops`. We might have to decide whether: * `MIN` should be replaced by `ZERO`? * associated constants over methods?
2020-09-12Auto merge of #75021 - cuviper:array_chunks_mut, r=scottmcmbors-0/+93
Add `slice::array_chunks_mut` This follows `array_chunks` from #74373 with a mutable version, `array_chunks_mut`. The implementation is identical apart from mutability. The new tests are adaptations of the `chunks_exact_mut` tests, plus an inference test like the one for `array_chunks`. I reused the unstable feature `array_chunks` and tracking issue #74985, but I can separate that if desired. r? `@withoutboats` cc `@lcnr`
2020-09-08Add saturating methods for `Duration`marmeladema-0/+32
2020-09-07Rollup merge of #76305 - CDirkx:const-tests, r=matkladDylan DPC-0/+28
Move various ui const tests to `library` Move: - `src\test\ui\consts\const-nonzero.rs` to `library\core` - `src\test\ui\consts\ascii.rs` to `library\core` - `src\test\ui\consts\cow-is-borrowed` to `library\alloc` Part of #76268 r? @matklad
2020-09-05Minor refactoringAyush Kumar Mishra-2/+4
2020-09-05Add Arith Tests in LibraryAyush Kumar Mishra-0/+27
2020-09-04Add tests for array_chunks_mutJosh Stone-0/+93
2020-09-04Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAusbors-2/+2
Add `slice::check_range` This method is useful for [`RangeBounds`] parameters. It's even been [rewritten](https://github.com/rust-lang/rust/blob/22ee68dc586440f96b76b32fbd6087507c6afdb9/src/librustc_data_structures/sorted_map.rs#L214) [many](https://github.com/rust-lang/rust/blob/22ee68dc586440f96b76b32fbd6087507c6afdb9/library/alloc/src/vec.rs#L1299) [times](https://github.com/rust-lang/rust/blob/22ee68dc586440f96b76b32fbd6087507c6afdb9/library/core/src/slice/mod.rs#L2441) in the standard library, sometimes assuming that the bounds won't be [`usize::MAX`]. For example, [`Vec::drain`] creates an empty iterator when [`usize::MAX`] is used as an inclusive end bound: ```rust assert!(vec![1].drain(..=usize::max_value()).eq(iter::empty())); ``` If this PR is merged, I'll create another to use it for those methods. [`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html [`usize::MAX`]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.MAX [`Vec::drain`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
2020-09-04Move various ui const tests to `library`Christiaan Dirkx-0/+28
Move: - `src\test\ui\consts\const-nonzero.rs` to `library\core` - `src\test\ui\consts\ascii.rs` to `library\core` - `src\test\ui\consts\cow-is-borrowed` to `library\alloc` Part of #76268
2020-09-04Move const tests for `Poll` to `library\core`Christiaan Dirkx-0/+15
Part of #76268
2020-09-04Move const tests for `Ordering` to `library\core`Christiaan Dirkx-1/+17
Part of #76268
2020-09-04Move const tests for `Result` to `library\core`Christiaan Dirkx-0/+16
Part of #76268
2020-09-03Rollup merge of #76120 - LukasKalbertodt:add-as-slice-method-to-array, ↵Dylan DPC-2/+1
r=Mark-Simulacrum Add `[T; N]::as_[mut_]slice` Part of me trying to populate arrays with a couple of basic useful methods, like slices already have. The ability to add methods to arrays were added in #75212. Tracking issue: #76118 This adds: ```rust impl<T, const N: usize> [T; N] { pub fn as_slice(&self) -> &[T]; pub fn as_mut_slice(&mut self) -> &mut [T]; } ``` These methods are like the ones on `std::array::FixedSizeArray` and in the crate `arraytools`.
2020-09-02flt2dec: properly handle uninitialized memoryRalf Jung-50/+52
2020-08-30Fix tests using `FixedSizeArray` methods (which are now shadowed)Lukas Kalbertodt-2/+1
2020-08-24Stabilize Range[Inclusive]::is_emptyScott McMurray-1/+0
I would like to propose these two simple methods for stabilization: - Knowing that a range is exhaused isn't otherwise trivial - Clippy would like to suggest them, but had to do extra work to disable that path <https://github.com/rust-lang/rust-clippy/issues/3807> because they're unstable - These work on `PartialOrd`, consistently with now-stable `contains`, and are thus more general than iterator-based approaches that need `Step` - They've been unchanged for some time, and have picked up uses in the compiler - Stabilizing them doesn't block any future iterator-based is_empty plans, as the inherent ones are preferred in name resolution
2020-08-21Auto merge of #75694 - RalfJung:miri-align-to, r=nagisabors-11/+6
enable align_to tests in Miri With https://github.com/rust-lang/miri/issues/1074 resolved, we can enable these tests in Miri. I also tweaked the test sized to get reasonable execution times with decent test coverage.
2020-08-20Auto merge of #73565 - matthewjasper:core-min-spec, r=nagisabors-0/+97
Use min_specialization in libcore Getting `TrustedRandomAccess` to work is the main interesting thing here. - `get_unchecked` is now an unstable, hidden method on `Iterator` - The contract for `TrustedRandomAccess` is made clearer in documentation - Fixed a bug where `Debug` would create aliasing references when using the specialized zip impl - Added tests for the side effects of `next_back` and `nth`. closes #68536
2020-08-19Use min_specialization in libcoreMatthew Jasper-0/+97
2020-08-19enable align_to tests in MiriRalf Jung-11/+6
2020-08-18Make OnceCell<T> transparent to dropckAleksey Kladov-0/+9
See the failed build in https://github.com/rust-lang/rust/pull/75555#issuecomment-675016718 for an example where we need this in real life
2020-08-16Replace ad hoc implementations with `slice::check_range`dylni-2/+2
2020-08-13Add drop check test & MaybeUninit::first_ptr_mutkadmin-0/+29
Also in drop check test add hacky workaround for platforms that don't support panic=unwind
2020-08-13Add recommend changes to arraykadmin-0/+4
Switch from indexing to zip, and also use `write` on `MaybeUninit`. Add array_map feature to core/src/lib Attempt to fix issue of no such feature Update w/ pickfire's review This changes a couple of names around, adds another small test of variable size, and hides the rustdoc #![feature(..)]. Fmt doctest Add suggestions from lcnr
2020-08-13Add Array Impl Lang Item in various placeskadmin-0/+8
Add basic test And also run fmt which is where the other changes are from Fix mut issues These only appear when running tests, so resolved by adding mut Swap order of forget Add pub and rm guard impl Add explicit type to guard Add safety note Change guard type from T to S It should never have been T, as it guards over [MaybeUninit<S>; N] Also add feature to test
2020-08-02Auto merge of #74948 - lzutao:stalize-result-as-deref, r=dtolnaybors-119/+9
Stabilize `Result::as_deref` and `as_deref_mut` FCP completed in https://github.com/rust-lang/rust/issues/50264#issuecomment-645681400. This PR stabilizes two new APIs for `std::result::Result`: ```rust fn as_deref(&self) -> Result<&T::Target, &E> where T: Deref; fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> where T: DerefMut; ``` This PR also removes two rarely used unstable APIs from `Result`: ```rust fn as_deref_err(&self) -> Result<&T, &E::Target> where E: Deref; fn as_deref_mut_err(&mut self) -> Result<&mut T, &mut E::Target> where E: DerefMut; ``` Closes #50264
2020-08-03Rollup merge of #74974 - RalfJung:miri-tests, r=Mark-SimulacrumYuki Okushi-4/+5
Make tests faster in Miri Reduce some test iteration counts in Miri.
2020-07-31expand commentsRalf Jung-1/+1
2020-07-31also reduce some libcore test iteration countsRalf Jung-3/+4
2020-07-31Update testsLzu Tao-118/+9
2020-07-31Stabilize as_deref and as_deref on ResultLzu Tao-1/+0
2020-07-30add tests for array_chunksBastian Kauschke-0/+92
2020-07-27mv std libs to library/mark-0/+14441