about summary refs log tree commit diff
path: root/src/libcore/tests
AgeCommit message (Collapse)AuthorLines
2020-03-11Rollup merge of #69645 - DutchGhost:const-forget-tests, r=Dylan-DPCMazdak Farrokhzad-0/+19
const forget tests Adds tests for https://github.com/rust-lang/rust/pull/69617
2020-03-07Implement BitOr and BitOrAssign for the NonZero integer typesThom Chiovoloni-0/+35
2020-03-07Add `Layout::dangling()` to return a well-aligned `NonNull<u8>`Tim Diekmann-0/+4
2020-03-02remove unused mut, restructure the testDodo-6/+6
2020-03-02An enter as last character pleases tidy it seemsDodo-1/+1
2020-03-02const forget testsDodo-0/+19
2020-03-01Remove assert that had been replaced by assert_neMichael Mc Donnell-1/+0
2020-02-29Rollup merge of #69581 - RalfJung:align_to_mut, r=CentrilDylan DPC-0/+12
fix aliasing violation in align_to_mut Fixes https://github.com/rust-lang/rust/issues/68549 I decided to add the testcase here to make it all one PR, but if you prefer I can also add that test case in the Miri repo instead.
2020-02-29fix aliasing violation in align_to_mutRalf Jung-0/+12
2020-02-26Use assert_ne in hash testsMichael Mc Donnell-17/+20
The hash tests were written before the assert_ne macro was added to the standard library. The assert_ne macro provides better output in case of a failure.
2020-02-26Rollup merge of #69209 - Mark-Simulacrum:strip-unsafe, r=dtolnayDylan DPC-236/+224
Miscellaneous cleanup to formatting Each commit stands alone. This pull request will also resolve #58320.
2020-02-21Test `Duration::new` panics on overflowMichael Mc Donnell-0/+6
A `Duration` is created from a second and nanoseconds variable. The documentation says: "This constructor will panic if the carry from the nanoseconds overflows the seconds counter". This was, however, not tested in the tests. I doubt the behavior will ever regress, but it is usually a good idea to test all documented behavior.
2020-02-17Drop unused argument to float functionsMark Rousskov-236/+224
2020-02-14implement LowerExp and UpperExp for integersMax Blachman-0/+80
2020-02-08Auto merge of #68358 - matthewjasper:spec-fix, r=nikomatsakisbors-0/+16
Remove some unsound specializations This removes the unsound and exploitable specializations in the standard library * The `PartialEq` and `Hash` implementations for `RangeInclusive` are changed to avoid specialization. * The `PartialOrd` specialization for slices now specializes on a limited set of concrete types. * Added some tests for the soundness problems.
2020-02-04Auto merge of #68708 - Mark-Simulacrum:stage0-step, r=pietroalbinibors-1/+0
Step stage0 to bootstrap from 1.42 This also includes a commit which fixes the rustfmt downloading logic to redownload when the rustfmt channel changes, and bumps rustfmt to a more recent version.
2020-02-04Stabilize `core::iter::once_with()`Yuki Okushi-1/+0
2020-02-01Remove some unsound specializationsMatthew Jasper-0/+16
2020-01-31Drop cfg(bootstrap) codeMark Rousskov-1/+0
2020-01-28Add `Iterator::map_while` method and corresponding `MapWhile` adapterWaffle-0/+3
2020-01-28Auto merge of #68234 - CAD97:slice-from-raw-parts, r=KodrAusbors-1/+0
Stabilize ptr::slice_from_raw_parts[_mut] Closes #36925, the tracking issue. Initial impl: #60667 r? @rust-lang/libs In addition to stabilizing, I've adjusted the example of `ptr::slice_from_raw_parts` to use `slice_from_raw_parts` instead of `slice_from_raw_parts_mut`, which was unnecessary for the example as written.
2020-01-28stabilize the debug_map_key_value featureAshley Mannix-1/+0
2020-01-27Auto merge of #68165 - thomcc:lt_ones, r=sfacklerbors-0/+55
Add leading_ones and trailing_ones methods to the primitive integer types I was surprised these were missing (given that `leading_zeros` and `trailing_zeros` exist), and they seem trivial and hopefully not controversial. Note that there's some precedent in that `count_ones` and `count_zeros` are both supported even though only one of these has an intrinsic. I'm not sure if these need a `rustc_const_unstable` flag (the tests don't seem to mind that it's missing). I just made them const, since there's not really any reason for these to be non-const when the `_zeros` variants are const. Note: My understanding is trivial stuff like (hopefully) this can land without an RFC, but I'm not fully sure about the process though. Questions like "when does the tracking issue get filed?", are a total mystery to me. So, any guidance is appreciated, and sorry in advance if I should have gone through some more involved process for this.
2020-01-18slice_patterns: remove internal uses of gateMazdak Farrokhzad-1/+1
2020-01-17Auto merge of #66716 - derekdreery:debug_non_exhaustive, r=dtolnaybors-0/+86
Implement `DebugStruct::non_exhaustive`. This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using `DebugStruct`. ## Example ```rust #![feature(debug_non_exhaustive)] use std::fmt; struct Bar { bar: i32, hidden: f32, } impl fmt::Debug for Bar { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Bar") .field("bar", &self.bar) .non_exhaustive(true) // Show that some other field(s) exist. .finish() } } assert_eq!( format!("{:?}", Bar { bar: 10, hidden: 1.0 }), "Bar { bar: 10, .. }", ); ```
2020-01-16Rust ./x.py fmtRichard Dodd-12/+14
2020-01-15Rollup merge of #67784 - Mark-Simulacrum:residual-pad-integral, r=dtolnayYuki Okushi-0/+15
Reset Formatter flags on exit from pad_integral This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case. A manual check leads me to believe this is the only case where we failed to reset the flags appropriately, but I could have missed something.
2020-01-14Stabilize ptr::slice_from_raw_parts[_mut]CAD97-1/+0
2020-01-14Implement `finish_non_exhaustive` for `DebugStruct`.Richard Dodd-0/+84
2020-01-12Tests for leading_trailing_onesThom Chiovoloni-0/+55
2020-01-11Rollup merge of #68114 - ecstatic-morse:fix-feature-gating, r=CentrilMazdak Farrokhzad-1/+0
Don't require `allow_internal_unstable` unless `staged_api` is enabled. #63770 changed `qualify_min_const_fn` to require `allow_internal_unstable` for *all* crates that used an unstable feature, regardless of whether `staged_api` was enabled or the `fn` that used that feature was stably const. In practice, this meant that every crate in the ecosystem that wanted to use nightly features added `#![feature(const_fn)]`, which skips `qualify_min_const_fn` entirely. After this PR, crates that do not have `#![feature(staged_api)]` will only need to enable the feature they are interested in. For example, `#![feature(const_if_match)]` will be enough to enable `if` and `match` in constants. Crates with `staged_api` (e.g., `libstd`) require `#[allow_internal_unstable]` to be added to a function if it uses nightly features unless that function is also marked `#[rustc_const_unstable]`. This prevents proliferation of `#[allow_internal_unstable]` into functions that are not callable in a `const` context on stable. r? @oli-obk (author of #63770) cc @Centril
2020-01-11Update test after renaming Result::as_derefLzu Tao-58/+27
2020-01-10Remove unnecessary `const_fn` feature gatesDylan MacKenzie-1/+0
This flag opts out of the min-const-fn checks entirely, which is usually not what we want. The few cases where the flag is still necessary have been annotated.
2020-01-11Rollup merge of #66045 - mzabaluev:unwrap-infallible, r=dtolnayYuki Okushi-0/+24
Add method Result::into_ok Implementation of https://github.com/rust-lang/rfcs/pull/2799 Tracking issue #61695
2020-01-02Add Iterator::try_findMOZGIII-0/+41
2020-01-01Reset Formatter flags on exit from pad_integralMark Rousskov-0/+15
This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case.
2019-12-24x.py fmt after previous deignoreMark Rousskov-2/+0
2019-12-22Format the worldMark Rousskov-1004/+1352
2019-12-22Rename Result::unwrap_infallible to into_okMikhail Zabaluev-3/+3
2019-12-22libcore: test Result::unwrap_infallibleMikhail Zabaluev-0/+24
2019-12-20Make ptr::slice_from_raw_parts a const fn available under a feature flagDodo-0/+14
2019-12-11Rollup merge of #66881 - ↵Mazdak Farrokhzad-0/+8
krishna-veerareddy:issue-66780-bool-ord-optimization, r=sfackler Optimize Ord trait implementation for bool Casting the booleans to `i8`s and converting their difference into `Ordering` generates better assembly than casting them to `u8`s and comparing them. Fixes #66780 #### Comparison([Godbolt link](https://rust.godbolt.org/z/PjBpvF)) ##### Old assembly: ```asm example::boolean_cmp: mov ecx, edi xor ecx, esi test esi, esi mov eax, 255 cmove eax, ecx test edi, edi cmovne eax, ecx ret ``` ##### New assembly: ```asm example::boolean_cmp: mov eax, edi sub al, sil ret ``` ##### Old LLVM-MCA statistics: ``` Iterations: 100 Instructions: 800 Total Cycles: 234 Total uOps: 1000 Dispatch Width: 6 uOps Per Cycle: 4.27 IPC: 3.42 Block RThroughput: 1.7 ``` ##### New LLVM-MCA statistics: ``` Iterations: 100 Instructions: 300 Total Cycles: 110 Total uOps: 500 Dispatch Width: 6 uOps Per Cycle: 4.55 IPC: 2.73 Block RThroughput: 1.0 ```
2019-12-09Rollup merge of #67119 - RalfJung:miri-test-libstd, r=alexcrichtonTyler Mandry-18/+25
libstd miri tests: avoid warnings Ignore tests in a way that all the code still gets compiled, to get rid of all the "unused" warnings that otherwise show up when running the test suite in Miri.
2019-12-07fix warnings with cfg(miri)Ralf Jung-5/+14
2019-12-07libcore: ignore tests in Miri instead of removing them entirelyRalf Jung-13/+11
2019-12-06Format libcore with rustfmt (including tests and benches)David Tolnay-920/+1021
2019-12-06Rename to `then_some` and `then`varkor-4/+4
2019-12-06Fix libcore testsvarkor-4/+4
2019-11-29Remove unneeded prelude imports in libcore testsDavid Tolnay-3/+0
These three lines are from c82da7a54b9efb1a0ccbe11de66c71f547bf7db9 in 2015. They cause problems when applying rustfmt to the codebase, because reordering wildcard imports can trigger new unused import warnings. As a minimized example, the following program compiles successfully: #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use std::prelude::v1::*; use super::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; but putting it through rustfmt produces a program that fails to compile: #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use super::*; use std::prelude::v1::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; The error is: error: unused import: `std::prelude::v1::*` --> src/main.rs:8:9 | 8 | use std::prelude::v1::*; | ^^^^^^^^^^^^^^^^^^^
2019-11-29Optimize Ord trait implementation for boolKrishna Sai Veera Reddy-0/+8
Casting the booleans to `i8`s and converting their difference into `Ordering` generates better assembly than casting them to `u8`s and comparing them.