about summary refs log tree commit diff
path: root/library/core/tests
AgeCommit message (Collapse)AuthorLines
2023-12-10remove redundant importssurechen-17/+2
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-05Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errorsMichael Goulet-0/+1
Add support for making lib features internal We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug. This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal. Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-11-26Fix library testsCaleb Zulawski-2/+1
2023-11-22also make 'core_intrinsics' internalRalf Jung-0/+1
2023-11-22Stabilize RFC3324 dyn upcasting coercionUrgau-1/+1
Aka trait_upcasting feature. And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-21Auto merge of #117619 - elomatreb:add-duration-abs-diff, r=thomccbors-0/+14
Add `Duration::abs_diff` This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers. ACP: https://github.com/rust-lang/libs-team/issues/291 Tracking Issue: https://github.com/rust-lang/rust/issues/117618
2023-11-18Auto merge of #117525 - GKFX:remove_option_payload_ptr, r=petrochenkovbors-0/+8
Remove option_payload_ptr; redundant to offset_of The `option_payload_ptr` intrinsic is no longer required as `offset_of` supports traversing enums (#114208). This PR removes it in order to dogfood offset_of (as suggested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790907626). However, it will not build until those changes reach beta (which I think is within the next 8 days?) so I've opened it as a draft.
2023-11-16Remove option_payload_ptr; redundant to offset_ofGeorge Bateman-0/+8
2023-11-15avoid exhaustive i16 test in MiriRalf Jung-2/+5
2023-11-14Auto merge of #116301 - mj10021:issue-115737-fix, r=cuviperbors-4/+16
fix rounding issue with exponents in fmt fixes issue #115737 , where the decimal places are rounded incorrectly when formatting scientific notation
2023-11-11round to evenJames Dietz-343/+10
2023-11-11fix rounding issue with exponents in fmtJames Dietz-4/+349
2023-11-11Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnaybors-2/+2
Add `std::hash::{DefaultHasher, RandomState}` exports (needs FCP) This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`. <details><summary>The below no longer applies, but is kept for clarity.</summary> This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API. I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier. I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred. </details>
2023-11-09Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`John Millikin-0/+178
Assigned new feature name `core_io_borrowed_buf` to distinguish from the `Read::read_buf` functionality in `std::io`.
2023-11-05Add `Duration::abs_diff`Ole Bertram-0/+14
2023-11-05Auto merge of #116218 - tgross35:const-maybe-uninit-zeroed, r=dtolnaybors-0/+21
Stabilize `const_maybe_uninit_zeroed` and `const_mem_zeroed` Make `MaybeUninit::zeroed` and `mem::zeroed` const stable. Newly stable API: ```rust // core::mem pub const unsafe fn zeroed<T>() ->; impl<T> MaybeUninit<T> { pub const fn zeroed() -> MaybeUninit<T>; } ``` This relies on features based around `const_mut_refs`. Per `@RalfJung,` this should be OK since we do not leak any `&mut` to the user. For this to be possible, intrinsics `assert_zero_valid` and `assert_mem_uninitialized_valid` were made const stable. Tracking issue: #91850 Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const_mut_refs.60.20dependents r? libs-api `@rustbot` label -T-libs +T-libs-api +A-const-eval cc `@RalfJung` `@oli-obk` `@rust-lang/wg-const-eval`
2023-11-04Stabilize `const_maybe_uninit_zeroed`Trevor Gross-0/+21
Make `MaybeUninit::zeroed` const stable. Newly stable API: // core::mem impl<T> MaybeUninit<T> { pub const fn zeroed() -> MaybeUninit<T>; } Use of `const_mut_refs` should be acceptable since we do not leak the mutability. Tracking issue: #91850
2023-11-02Add insta-stable std::hash::{DefaultHasher, RandomState} exportsltdk-2/+2
2023-10-25Stabilize `[const_]pointer_byte_offsets`Maybe Waffle-2/+0
2023-10-24Rollup merge of #116714 - WaffleLapkin:order-the-order, r=joshtriplettMatthias Krüger-0/+11
Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*` Fixes #116711 The main pain of this PR is to fix the buggy impl of `Ord` for `SocketAddrV6`, which ignored half of the fields (while `PartialEq` is derived): https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L99-L106 https://github.com/rust-lang/rust/blob/4603f0b8afb495ae56cd4c8f70d5d478d906ac54/library/core/src/net/socket_addr.rs#L676 For me it looks like a simple copy-paste error made in https://github.com/rust-lang/rust/pull/72239 (copy from v4 impl) (cc `@hch12907),` as I don't see this behavior being mentioned anywhere on the PR and it also does not respect `cmp` trait "rules". I also do not see any reasons for those impls to _not_ be derived. It's a shame we did not notice this for 28 versions/3 years. I guess this is a bug fix, but I'm not sure what the process here should be. r? libs
2023-10-22use visibility to check unused imports and delete some stmtsbohan-4/+0
2023-10-15Add tests for `SocketAddrV6` ordering with scope_id and flowinfoMaybe Waffle-0/+11
2023-10-15Auto merge of #115515 - the8472:zip-for-arrays, r=scottmcmbors-1/+5
optimize zipping over array iterators Fixes #115339 (somewhat) the new assembly: ```asm zip_arrays: .cfi_startproc vmovups (%rdx), %ymm0 leaq 32(%rsi), %rcx vxorps %xmm1, %xmm1, %xmm1 vmovups %xmm1, -24(%rsp) movq $0, -8(%rsp) movq %rsi, -88(%rsp) movq %rdi, %rax movq %rcx, -80(%rsp) vmovups %ymm0, -72(%rsp) movq $0, -40(%rsp) movq $32, -32(%rsp) movq -24(%rsp), %rcx vmovups (%rsi,%rcx), %ymm0 vorps -72(%rsp,%rcx), %ymm0, %ymm0 vmovups %ymm0, (%rsi,%rcx) vmovups (%rsi), %ymm0 vmovups %ymm0, (%rdi) vzeroupper retq ``` This is still longer than the slice version given in the issue but at least it eliminates the terrible `vpextrb`/`orb` chain. I guess this is due to excessive memcpys again (haven't looked at the llvmir)? The `TrustedLen` specialization is a drive-by change since I had to do something for the default impl anyway to be able to specialize the `TrustedRandomAccessNoCoerce` impl.
2023-10-13Auto merge of #116233 - ↵bors-1/+0
DaniPopes:stabilize-const_maybe_uninit_assume_init_read, r=dtolnay Stabilize `const_maybe_uninit_assume_init_read` AFAICT the only reason this was not included in the `maybe_uninit_extra` stabilization was because `ptr::read` was unstable (https://github.com/rust-lang/rust/pull/92768#issuecomment-1011101383), which has since been stabilized in 1.71. Needs a separate FCP from the [original `maybe_uninit_extra` one](https://github.com/rust-lang/rust/issues/63567#issuecomment-964428807). Tracking issue: #63567
2023-10-11Auto merge of #112818 - Benjamin-L:add-slice_split_once, r=cuviperbors-0/+21
Implement `slice::split_once` and `slice::rsplit_once` Feature gate is `slice_split_once` and tracking issue is #112811. These are equivalents to the existing `str::split_once` and `str::rsplit_once` methods.
2023-10-06optimize zipping over array iteratorsThe 8472-1/+5
2023-10-02MIRI -> MiriRalf Jung-2/+2
2023-09-29Auto merge of #116176 - FedericoStra:isqrt, r=dtolnaybors-0/+62
Add "integer square root" method to integer primitive types For every suffix `N` among `8`, `16`, `32`, `64`, `128` and `size`, this PR adds the methods ```rust const fn uN::isqrt() -> uN; const fn iN::isqrt() -> iN; const fn iN::checked_isqrt() -> Option<iN>; ``` to compute the [integer square root](https://en.wikipedia.org/wiki/Integer_square_root), addressing issue #89273. The implementation is based on the [base 2 digit-by-digit algorithm](https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)) on Wikipedia, which after some benchmarking has proved to be faster than both binary search and Heron's/Newton's method. I haven't had the time to understand and port [this code](http://atoms.alife.co.uk/sqrt/SquareRoot.java) based on lookup tables instead, but I'm not sure whether it's worth complicating such a function this much for relatively little benefit.
2023-09-28isqrt: disable long running tests in MiriFederico Stra-0/+8
2023-09-28Stabilize `const_maybe_uninit_assume_init_read`DaniPopes-1/+0
2023-09-28isqrt: fix stabilityFederico Stra-0/+1
2023-09-26isqrt: add more testsFederico Stra-0/+32
2023-09-23Add the `cfg_match!` macroCaio-0/+156
2023-09-22isqrt: add testsFederico Stra-0/+21
2023-09-02Auto merge of #113295 - clarfonthey:ascii-step, r=cuviperbors-1/+19
Implement Step for ascii::Char This allows iterating over ranges of `ascii::Char`, similarly to ranges of `char`. Note that `ascii::Char` is still unstable, tracked in #110998.
2023-08-28Rollup merge of #114238 - jhpratt:fix-duration-div, r=thomccMatthias Krüger-0/+1
Fix implementation of `Duration::checked_div` I ran across this while running some sanity checks on `time`. Quickcheck immediately found a bug, and as I'd modified the code from `std` I knew there was a bug here as well. tl;dr this code fails ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1189a3efcdfc192c27d6d87815359353)) ```rust use std::time::Duration; fn main() { assert_eq!( Duration::new(1, 1).checked_div(7), Some(Duration::new(0, 142_857_143)), ); } ``` The existing code determines that 1/7 = 0 (seconds), 1/7 = 0 (nanoseconds), 1 billion / 7 = 142,857,142 (extra nanoseconds). The billion comes from multiplying the remainder of the seconds (1) by the number of nanoseconds in a second. However, **this wrongly ignores any remaining nanoseconds**. This PR takes that into consideration, adds a test, and also changes the roundabout way of calculating the remainder into directly computing it. Note: This is _not_ a rounding error. This result divides evenly. `@rustbot` label +A-time +C-bug +S-waiting-on-reviewer +T-libs
2023-08-14Auto merge of #113464 - waynr:remove-provider-trait, r=Amanieubors-63/+69
core/any: remove Provider trait, rename Demand to Request This touches on two WIP features: * `error_generic_member_access` * tracking issue: https://github.com/rust-lang/rust/issues/99301 * RFC (WIP): https://github.com/rust-lang/rfcs/pull/2895 * `provide_any` * tracking issue: https://github.com/rust-lang/rust/issues/96024 * RFC: https://github.com/rust-lang/rfcs/pull/3192 The changes in this PR are intended to address libs meeting feedback summarized by `@Amanieu` in https://github.com/rust-lang/rust/issues/96024#issuecomment-1554773172 The specific items this PR addresses so far are: > We feel that the names "demand" and "request" are somewhat synonymous and would like only one of those to be used for better consistency. I went with `Request` here since it sounds nicer, but I'm mildly concerned that at first glance it could be confused with the use of the word in networking context. > The Provider trait should be deleted and its functionality should be merged into Error. We are happy to only provide an API that is only usable with Error. If there is demand for other uses then this can be provided through an external crate. The net impact this PR has is that examples which previously looked like ``` core::any::request_ref::<String>(&err).unwramp() ``` now look like ``` (&err as &dyn core::error::Error).request_value::<String>().unwrap() ``` These are methods that based on the type hint when called return an `Option<T>` of that type. I'll admit I don't fully understand how that's done, but it involves `core::any::tags::Type` and `core::any::TaggedOption`, neither of which are exposed in the public API, to construct a `Request` which is then passed to the `Error.provide` method. Something that I'm curious about is whether or not they are essential to the use of `Request` types (prior to this PR referred to as `Demand`) and if so does the fact that they are kept private imply that `Request`s are only meant to be constructed privately within the standard library? That's what it looks like to me. These methods ultimately call into code that looks like: ``` /// Request a specific value by tag from the `Error`. fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified> where I: tags::Type<'a>, { let mut tagged = core::any::TaggedOption::<'a, I>(None); err.provide(tagged.as_request()); tagged.0 } ``` As far as the `Request` API is concerned, one suggestion I would like to make is that the previous example should look more like this: ``` /// Request a specific value by tag from the `Error`. fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified> where I: tags::Type<'a>, { let tagged_request = core::any::Request<I>::new_tagged(); err.provide(tagged_request); tagged.0 } ``` This makes it possible for anyone to construct a `Request` for use in their own projects without exposing an implementation detail like `TaggedOption` in the API surface. Otherwise noteworthy is that I had to add `pub(crate)` on both `core::any::TaggedOption` and `core::any::tags` since `Request`s now need to be constructed in the `core::error` module. I considered moving `TaggedOption` into the `core::error` module but again I figured it's an implementation detail of `Request` and belongs closer to that. At the time I am opening this PR, I have not yet looked into the following bit of feedback: > We took a look at the generated code and found that LLVM is unable to optimize multiple .provide_* calls into a switch table because each call fetches the type id from Erased::type_id separately each time and the compiler doesn't know that these calls all return the same value. This should be fixed. This is what I'll focus on next while waiting for feedback on the progress so far. I suspect that learning more about the type IDs will help me understand the need for `TaggedOption` a little better.
2023-08-14Implement Step for AsciiCharltdk-1/+19
2023-08-13core/any: remove Provider traitwayne warren-63/+69
* remove `impl Provider for Error` * rename `Demand` to `Request` * update docstrings to focus on the conceptual API provided by `Request` * move `core::any::{request_ref, request_value}` functions into `core::error` * move `core::any::tag`, `core::any::Request`, an `core::any::TaggedOption` into `core::error` * replace `provide_any` feature name w/ `error_generic_member_access` * move `core::error::request_{ref,value} tests into core::tests::error module * update unit and doc tests
2023-08-11Add Iterator::map_windowsFrank King-0/+285
This is inherited from the old PR. This method returns an iterator over mapped windows of the starting iterator. Adding the more straight-forward `Iterator::windows` is not easily possible right now as the items are stored in the iterator type, meaning the `next` call would return references to `self`. This is not allowed by the current `Iterator` trait design. This might change once GATs have landed. The idea has been brought up by @m-ou-se here: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Iterator.3A.3A.7Bpairwise.2C.20windows.7D/near/224587771 Co-authored-by: Lukas Kalbertodt <lukas.kalbertodt@gmail.com>
2023-07-30Fix implementation of `Duration::checked_div`Jacob Pratt-0/+1
2023-07-21Auto merge of #112699 - bluebear94:mf/more-is-sorted-tests, r=cuviperbors-1/+58
Add more comprehensive tests for is_sorted and friends See #53485 and #55045.
2023-07-18remove the unstable `core::sync::atomic::ATOMIC_*_INIT` constantsKaDiWa-1/+1
2023-07-12Flip cfg's for bootstrap bumpMark Rousskov-1/+1
2023-07-03enable test_join test in MiriRalf Jung-1/+0
2023-06-26Auto merge of #111850 - the8472:external-step-by, r=scottmcmbors-0/+55
Specialize `StepBy<Range<{integer}>>` OLD iter::bench_range_step_by_fold_u16 700.00ns/iter +/- 10.00ns iter::bench_range_step_by_fold_usize 519.00ns/iter +/- 6.00ns iter::bench_range_step_by_loop_u32 555.00ns/iter +/- 7.00ns iter::bench_range_step_by_sum_reducible 37.00ns/iter +/- 0.00ns NEW iter::bench_range_step_by_fold_u16 49.00ns/iter +/- 0.00ns iter::bench_range_step_by_fold_usize 194.00ns/iter +/- 1.00ns iter::bench_range_step_by_loop_u32 98.00ns/iter +/- 0.00ns iter::bench_range_step_by_sum_reducible 1.00ns/iter +/- 0.00ns NEW + `-Ctarget-cpu=x86-64-v3` iter::bench_range_step_by_fold_u16 22.00ns/iter +/- 0.00ns iter::bench_range_step_by_fold_usize 80.00ns/iter +/- 1.00ns iter::bench_range_step_by_loop_u32 41.00ns/iter +/- 0.00ns iter::bench_range_step_by_sum_reducible 1.00ns/iter +/- 0.00ns I have only optimized for walltime of those methods, I haven't tested whether it eliminates bounds checks when indexing into slices via things like `(0..slice.len()).step_by(16)`.
2023-06-23Specialize StepBy<Range<{integer}>>The 8472-0/+55
For ranges < usize we determine the number of items StepBy would yield and then store that in the range.end instead of the actual end. This significantly simplifies calculation of the loop induction variable especially in cases where StepBy::step (an usize) could overflow the Range's item type
2023-06-19Implement slice::split_once and slice::rsplit_onceBenjamin Lee-0/+21
Feature gate is slice_split_once and tracking issue is #112811.
2023-06-19Rollup merge of #112606 - clarfonthey:ip-display, r=thomccMichael Goulet-4/+4
Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses ACP: rust-lang/libs-team#239
2023-06-16Add more comprehensive tests for is_sorted and friends+merlan #flirora-1/+58
See #53485 and #55045.