summary refs log tree commit diff
path: root/src/libcore/tests
AgeCommit message (Collapse)AuthorLines
2018-11-20fix testАртём Павлов [Artyom Pavlov]-1/+1
2018-11-20testsАртём Павлов [Artyom Pavlov]-0/+10
2018-11-20revertАртём Павлов [Artyom Pavlov]-5/+2
2018-10-19Stabilize impl_header_lifetime_elision in 2015Scott McMurray-1/+1
It's already stable in 2018; this finishes the stabilization.
2018-10-18Stabilize slice::rchunks(), rchunks_mut(), rchunks_exact(), rchunk_exact_mut()Sebastian Dröge-1/+0
Fixes #55177
2018-10-18Stabilize slice::chunks_exact() and slice::chunks_exact_mut()Sebastian Dröge-1/+0
Fixes #47115
2018-10-18Add slice::rchunks(), rchunks_mut(), rchunks_exact() and rchunks_exact_mut()Sebastian Dröge-0/+223
These work exactly like the normal chunks iterators but start creating chunks from the end of the slice. See #55177 for the tracking issue
2018-10-08Stabilize the `Option::replace` methodClément Renault-1/+0
2018-09-29Activate the feature in the libcore tests tooScott McMurray-0/+1
2018-09-29Use impl_header_lifetime_elision in libcoreScott McMurray-1/+1
2018-09-29Auto merge of #54240 - csmoe:nonzero_from, r=alexcrichtonbors-0/+7
Impl From<NonZero<T>> for T Closes https://github.com/rust-lang/rust/issues/54171 r? @SimonSapin
2018-09-25Rollup merge of #54537 - sdroege:chunks-exact, r=alexcrichtonPietro Albini-30/+30
Rename slice::exact_chunks() to slice::chunks_exact() See https://github.com/rust-lang/rust/issues/47115#issuecomment-403090815 and https://github.com/rust-lang/rust/issues/47115#issuecomment-424053547
2018-09-24Rename slice::exact_chunks() to slice::chunks_exact()Sebastian Dröge-30/+30
See https://github.com/rust-lang/rust/issues/47115#issuecomment-403090815 and https://github.com/rust-lang/rust/issues/47115#issuecomment-424053547
2018-09-23Introduce the partition_dedup/by/by_key methods for slicesClément Renault-0/+60
2018-09-20add tests for copy_withinJack O'Connor-0/+47
2018-09-17move from_nonzero test from run-pass to libcorecsmoe-0/+7
2018-09-16Auto merge of #53754 - RalfJung:slice_align_to, r=alexcrichtonbors-1/+0
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-04Breaking change upgradesMark Rousskov-10/+10
2018-08-28stabilize slice_align_toRalf Jung-1/+0
2018-08-25Auto merge of #53385 - matklad:stabilize-find-map, r=KodrAusbors-1/+0
Stablize Iterator::find_map Stabilization PR for https://github.com/rust-lang/rust/issues/49602
2018-08-19Auto merge of #52972 - RalfJung:from_raw_parts_align, r=alexcrichtonbors-0/+14
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-15Stablize Iterator::find_mapAleksey Kladov-1/+0
2018-08-14Auto merge of #53033 - RalfJung:manually_dro, r=SimonSapinbors-0/+5
unsized ManuallyDrop I think this matches what @eddyb had in https://github.com/rust-lang/rust/pull/52711 originally. ~~However, I have never added a `CoerceUnsized` before so I am not sure if I did this right. I copied the `unstable` attribute on the `impl` from elsewhere, but AFAIK it is useless because `impl`'s are insta-stable... so shouldn't this rather say "stable since 1.30"?~~ This is insta-stable and hence requires FCP, at least. Fixes https://github.com/rust-lang/rust/issues/47034
2018-08-06unconfuse @eddybRalf Jung-1/+2
2018-08-05Fix 2018 edition testsvarkor-1/+0
2018-08-05Fix stage 2 testsvarkor-1/+0
2018-08-05Remove unnecessary or invalid feature attributesvarkor-3/+0
2018-08-03unsized ManuallyDropRalf Jung-0/+4
2018-08-02test that align_of handles alignment properly for the mid partRalf Jung-0/+14
2018-08-02Auto merge of #52206 - RalfJung:zst-slices, r=alexcrichtonbors-0/+126
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-02test nth betterRalf Jung-11/+37
2018-08-02slice iterators: ZST iterators no longer just "make up" addressesRalf Jung-0/+100
2018-08-01Auto merge of #51609 - dscorbett:is_numeric, r=alexcrichtonbors-1/+2
Treat gc=No characters as numeric [`char::is_numeric`](https://doc.rust-lang.org/std/primitive.char.html#method.is_numeric) and [`char::is_alphanumeric`](https://doc.rust-lang.org/std/primitive.char.html#method.is_alphanumeric) are documented to be defined “in terms of the Unicode General Categories 'Nd', 'Nl', 'No'”, but unicode.py does not group 'No' with the other 'N' categories. These functions therefore currently return `false` for characters like ⟨¾⟩ and ⟨①⟩.
2018-08-01Rollup merge of #52732 - SimonSapin:spring, r=Mark-SimulacrumPietro Albini-51/+0
Remove unstable and deprecated APIs
2018-07-30Remove unstable and deprecated APIsSimon Sapin-51/+0
2018-07-29resolved upstream merge conflictsBrad Gibson-133/+885
2018-07-29Auto merge of #52767 - ljedrz:avoid_format, r=petrochenkovbors-1/+1
Prefer to_string() to format!() Simple benchmarks suggest in some cases it can be faster by even 37%: ``` test converting_f64_long ... bench: 339 ns/iter (+/- 199) test converting_f64_short ... bench: 136 ns/iter (+/- 34) test converting_i32_long ... bench: 87 ns/iter (+/- 16) test converting_i32_short ... bench: 87 ns/iter (+/- 49) test converting_str ... bench: 54 ns/iter (+/- 15) test formatting_f64_long ... bench: 349 ns/iter (+/- 176) test formatting_f64_short ... bench: 145 ns/iter (+/- 14) test formatting_i32_long ... bench: 98 ns/iter (+/- 14) test formatting_i32_short ... bench: 93 ns/iter (+/- 15) test formatting_str ... bench: 86 ns/iter (+/- 23) ```
2018-07-29Auto merge of #52764 - sinkuu:cleanup, r=nikomatsakisbors-2/+1
Misc cleanups
2018-07-28Auto merge of #52711 - eddyb:unsized-manuallydrop, r=nikomatsakisbors-0/+25
Change ManuallyDrop<T> to a lang item. This PR implements the approach @RalfJung proposes in https://internals.rust-lang.org/t/pre-rfc-unions-drop-types-and-manuallydrop/8025 (lang item `struct` instead of `union`). A followup PR can easily solve #47034 as well, by just adding a few `?Sized` to `libcore/mem.rs`. r? @nikomatsakis
2018-07-27Use str::repeatShotaro Yamada-2/+1
2018-07-27add smoke test for ManuallyDropRalf Jung-0/+25
2018-07-27Prefer to_string() to format!()ljedrz-1/+1
2018-07-25Add missing dynTatsuyuki Ishi-22/+26
2018-07-14Rollup merge of #52003 - Kerollmops:option-replace, r=Kimundikennytm-0/+16
Implement `Option::replace` in the core library Here is the implementation of the `Option::replace` method. The first step of [the tracking issue #51998](https://github.com/rust-lang/rust/issues/51998).
2018-07-12Auto merge of #51339 - sdroege:exact-chunks-remainder, r=alexcrichtonbors-0/+14
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-09Add a basic test to `Option::replace`Clément RENAULT-0/+16
2018-07-03Auto merge of #51564 - SimonSapin:try-int, r=alexcrichtonbors-0/+127
Implement always-fallible TryFrom for usize/isize conversions that are infallible on some platforms This reverts commit 837d6c70233715a0ae8e15c703d40e3046a2f36a "Remove TryFrom impls that might become conditionally-infallible with a portability lint". This fixes #49415 by adding (restoring) missing `TryFrom` impls for integer conversions to or from `usize` or `isize`, by making them always fallible at the type system level (that is, with `Error=TryFromIntError`) even though they happen to be infallible on some platforms (for some values of `size_of::<usize>()`). They had been removed to allow the possibility to conditionally having some of them be infallible `From` impls instead, depending on the platforms, and have the [portability lint](https://github.com/rust-lang/rfcs/pull/1868) warn when they are used in code that is not already opting into non-portability. For example `#[allow(some_lint)] usize::from(x: u64)` would be valid on code that only targets 64-bit platforms. This PR gives up on this possiblity for two reasons: * Based on discussion with @aturon, it seems that the portability lint is not happening any time soon. It’s better to have the conversions be available *at all* than keep blocking them for so long. Portability-lint-gated platform-specific APIs can always be added separately later. * For code that is fine with fallibility, the alternative would force it to opt into "non-portability" even though there would be no real portability issue.
2018-07-01Rollup merge of #51511 - Centril:feature/stabilize_iterator_flatten, ↵Pietro Albini-1/+0
r=SimonSapin Stabilize Iterator::flatten in 1.29, fixes #48213. This PR stabilizes [`Iterator::flatten`](https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.flatten) in *version 1.29* (1.28 goes to beta in 10 days, I don't think there's enough time to land it in that time, but let's see...). Tracking issue is: #48213. cc @bluss re. itertools. r? @SimonSapin ping @pietroalbini -- let's do a crater run when this passes CI :)
2018-06-28Rollup merge of #50342 - fkjogu:euclidean, r=BurntSushikennytm-0/+19
Document round-off error in `.mod_euc()`-method, see issue #50179 Due to a round-off error the method `.mod_euc()` of both `f32` and `f64` can produce mathematical invalid outputs. If `self` in magnitude is much small than the modulus `rhs` and negative, `self + rhs` in the first branch cannot be represented in the given precision and results into `rhs`. In the mathematical strict sense, this breaks the definition. But given the limitation of floating point arithmetic it can be thought of the closest representable value to the true result, although it is not strictly in the domain `[0.0, rhs)` of the function. It is rather the left side asymptotical limit. It would be desirable that it produces the mathematical more sound approximation of `0.0`, the right side asymptotical limit. But this breaks the property, that `self == self.div_euc(rhs) * rhs + a.mod_euc(rhs)`. The discussion in issue #50179 did not find an satisfying conclusion to which property is deemed more important. But at least we can document the behaviour. Which this pull request does.
2018-06-27Auto merge of #51598 - Pazzaz:master, r=sfacklerbors-0/+14
Optimize sum of Durations by using custom function The current `impl Sum for Duration` uses `fold` to perform several `add`s (or really `checked_add`s) of durations. In doing so, it has to guarantee the number of nanoseconds is valid after every addition. If you squeese the current implementation into a single function it looks kind of like this: ````rust fn sum<I: Iterator<Item = Duration>>(iter: I) -> Duration { let mut sum = Duration::new(0, 0); for rhs in iter { if let Some(mut secs) = sum.secs.checked_add(rhs.secs) { let mut nanos = sum.nanos + rhs.nanos; if nanos >= NANOS_PER_SEC { nanos -= NANOS_PER_SEC; if let Some(new_secs) = secs.checked_add(1) { secs = new_secs; } else { panic!("overflow when adding durations"); } } sum = Duration { secs, nanos } } else { panic!("overflow when adding durations"); } } sum } ```` We only need to check if `nanos` is in the correct range when giving our final answer so we can have a more optimized version like so: ````rust fn sum<I: Iterator<Item = Duration>>(iter: I) -> Duration { let mut total_secs: u64 = 0; let mut total_nanos: u64 = 0; for entry in iter { total_secs = total_secs .checked_add(entry.secs) .expect("overflow in iter::sum over durations"); total_nanos = match total_nanos.checked_add(entry.nanos as u64) { Some(n) => n, None => { total_secs = total_secs .checked_add(total_nanos / NANOS_PER_SEC as u64) .expect("overflow in iter::sum over durations"); (total_nanos % NANOS_PER_SEC as u64) + entry.nanos as u64 } }; } total_secs = total_secs .checked_add(total_nanos / NANOS_PER_SEC as u64) .expect("overflow in iter::sum over durations"); total_nanos = total_nanos % NANOS_PER_SEC as u64; Duration { secs: total_secs, nanos: total_nanos as u32, } } ```` We now only convert `total_nanos` to `total_secs` (1) if `total_nanos` overflows and (2) at the end of the function when we have to output a valid `Duration`. This gave a 5-22% performance improvement when I benchmarked it, depending on how big the `nano` value of the `Duration`s in `iter` were.