about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-03-08Remove `identity_future` indirectionArpad Borsos-5/+1
This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm. Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]` annotation.
2023-03-08may not => cannotMichael Goulet-1/+1
2023-03-07black_box hint - Adjust for improved readabilitypat-nel87-6/+3
2023-03-07Remove DropAndReplace terminatorGiacomo Pasini-2/+1
PR 107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-07Auto merge of #108763 - scottmcm:indexing-nuw-lengths, r=cuviperbors-3/+6
Use `nuw` when calculating slice lengths from `Range`s An `assume` would definitely not be worth it, but since the flag is almost free we might as well tell LLVM this, especially on `_unchecked` calls where there's no obvious way for it to deduce it. (Today neither safe nor unsafe indexing gets it: <https://rust.godbolt.org/z/G1jYT548s>)
2023-03-07Auto merge of #95317 - Jules-Bertholet:round_ties_to_even, ↵bors-0/+19
r=pnkfelix,m-ou-se,scottmcm Add `round_ties_even` to `f32` and `f64` Tracking issue: #96710 Redux of #82273. See also #55107 Adds a new method, `round_ties_even`, to `f32` and `f64`, that rounds the float to the nearest integer , rounding halfway cases to the number with an even least significant bit. Uses the `roundeven` LLVM intrinsic to do this. Of the five IEEE 754 rounding modes, this is the only one that doesn't already have a round-to-integer function exposed by Rust (others are `round`, `floor`, `ceil`, and `trunc`). Ties-to-even is also the rounding mode used for int-to-float and float-to-float `as` casts, as well as float arithmentic operations. So not having an explicit rounding method for it seems like an oversight. Bikeshed: this PR currently uses `round_ties_even` for the name of the method. But maybe `round_ties_to_even` is better, or `round_even`, or `round_to_even`?
2023-03-06Use Edition 2021 :pat in matches macroKonrad Borowski-2/+2
This makes the macro syntax used in documentation more readable.
2023-03-05Use `nuw` when calculating slice lengths from `Range`sScott McMurray-3/+6
An `assume` would definitely not be worth it, but since the flag is almost free we might as well tell LLVM this, especially on `_unchecked` calls where there's no obvious way for it to deduce it. (Today neither safe nor unsafe indexing gets it: <https://rust.godbolt.org/z/G1jYT548s>)
2023-03-05Auto merge of #108157 - scottmcm:tuple-gt-via-partialcmp, r=dtolnaybors-13/+35
Use `partial_cmp` to implement tuple `lt`/`le`/`ge`/`gt` In today's implementation, `(A, B)::gt` contains calls to *both* `A::eq` *and* `A::gt`. That's fine for primitives, but for things like `String`s it's kinda weird -- `(String, usize)::gt` has a call to both `bcmp` and `memcmp` (<https://rust.godbolt.org/z/7jbbPMesf>) because when `bcmp` says the `String`s aren't equal, it turns around and calls `memcmp` to find out which one's bigger. This PR changes the implementation to instead implement `(A, …, C, Z)::gt` using `A::partial_cmp`, `…::partial_cmp`, `C::partial_cmp`, and `Z::gt`. (And analogously for `lt`, `le`, and `ge`.) That way expensive comparisons don't need to be repeated. Technically this is an observable change on stable, so I've marked it `needs-fcp` + `T-libs-api` and will r? rust-lang/libs-api I'm hoping that this will be non-controversial, however, since it's very similar to the observable changes that were made to the derives (#81384 #98655) -- like those, this only changes behaviour if a type overrode behaviour in a way inconsistent with the rules for the various traits involved. (The first commit here is #108156, adding the codegen test, which I used to make sure this doesn't regress behaviour for primitives.) Zulip conversation about this change: <https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60.3E.60.20on.20Tuples/near/328392927>.
2023-03-05Auto merge of #105117 - pitaj:debug_asserts, r=the8472bors-35/+50
Add more debug assertions to unsafe functions related to #51713
2023-03-04Comment for why char boundaries aren't checkedPeter Jaszkowiak-0/+6
2023-03-04Rollup merge of #108660 - xfix:remove-ne-method-from-str, r=thomccDylan DPC-4/+0
Remove ne implementations from strings As far as I can tell, there isn't really a reason for those.
2023-03-04Update comment.Tobias Decking-1/+1
2023-03-04typoTobias Decking-1/+1
2023-03-04Add inlining annotationsTobias Decking-1/+18
2023-03-03Rollup merge of #108688 - est31:backticks_matchmaking_library, r=jyn514Matthias Krüger-7/+7
Match unmatched backticks in library/ Found with GNU grep: ``` grep -rEn '^(([^`]*`){2})*[^`]*`[^`]*$' library/ | rg -v '\s*[//]?.{1,2}```' ``` split out from #108685 as per advice.
2023-03-03Rollup merge of #108540 - WaffleLapkin:atomic_thingy_from_thingy_pointer, ↵Matthias Krüger-0/+135
r=m-ou-se Add `Atomic*::from_ptr` This PR adds functions in the following form to all atomic types: ```rust impl AtomicT { pub const unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a AtomicT; } ``` r? `@m-ou-se` (we've talked about it before) I'm not sure about docs & safety requirements, I'd appreciate some feedback on them.
2023-03-03Match unmatched backticks in library/est31-7/+7
2023-03-02Remove manual implementation of str::neKonrad Borowski-4/+0
2023-03-02Revert "Stabilize `#![feature(target_feature_11)]`"Léo Lanteri Thauvin-0/+1
This reverts commit b379d216eefaba083a0627b1724d73f99d4bdf5c.
2023-03-02Fill-in tracking issue for `feature("atomic_from_ptr")`Maybe Waffle-6/+6
2023-03-02Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubileebors-0/+1
Add support for QNX Neutrino to standard library This change: - adds standard library support for QNX Neutrino (7.1). - upgrades `libc` to version `0.2.139` which supports QNX Neutrino `@gh-tr` ⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️ Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-03-01Fix docs for `alloc::realloc`overlookmotel-1/+2
Fixes #108546
2023-03-01Auto merge of #108483 - scottmcm:unify-bytewise-eq-traits, r=the8472bors-92/+98
Merge two different equality specialization traits in `core` Arrays and slices each had their own version of this, without a matching set of `impl`s. Merge them into one (still-`pub(crate)`) `cmp::BytewiseEq` trait, so we can stop doing all these things twice. And that means that the `[T]::eq` → `memcmp` specialization picks up a bunch of types where that previously only worked for arrays, so examples like <https://rust.godbolt.org/z/KjsG8MGGT> will use it now instead of emitting loops. r? the8472
2023-03-01Merge two different equality specialization traits in `core`Scott McMurray-92/+98
2023-03-01Auto merge of #105871 - llogiq:option-as-slice, r=scottmcmbors-0/+120
Add `Option::as_`(`mut_`)`slice` This adds the following functions: * `Option<T>::as_slice(&self) -> &[T]` * `Option<T>::as_mut_slice(&mut self) -> &[T]` The `as_slice` and `as_mut_slice_mut` functions benefit from an optimization that makes them completely branch-free. ~~Unfortunately, this optimization is not available on by-value Options, therefore the `into_slice` implementations use the plain `match` + `slice::from_ref` approach.~~ Note that the optimization's soundness hinges on the fact that either the niche optimization makes the offset of the `Some(_)` contents zero or the mempory layout of `Option<T>` is equal to that of `Option<MaybeUninit<T>>`. The idea has been discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Option.3A.3Aas_slice). Notably the idea for the `as_slice_mut` and `into_slice´ methods came from `@cuviper` and `@Sp00ph` hardened the optimization against niche-optimized Options. The [rust playground](https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=74f8e4239a19f454c183aaf7b4a969e0) shows that the generated assembly of the optimized method is basically only a copy while the naive method generates code containing a `test dx, dx` on x86_64. --- EDIT from reviewer: ACP is https://github.com/rust-lang/libs-team/issues/150
2023-03-01Rollup merge of #108531 - Coca162:rustdoc-repeat-const-array, r=thomccMatthias Krüger-2/+4
rustdoc: Show that repeated expression arrays can be made with constant values The [rust reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) currently says that repeated values for arrays can be constant or `Copy` > repeat operand is [Copy](https://doc.rust-lang.org/reference/special-types-and-traits.html#copy) or that it must be a [path](https://doc.rust-lang.org/reference/expressions/path-expr.html) to a constant item This updates the rust documentation on primitive arrays to reflect what the rust reference says (and also compiler suggestions if you do not use a `const` item)
2023-03-01Add `Option::as_slice`(`_mut`)Andre Bogus-0/+120
This adds the following functions: * `Option<T>::as_slice(&self) -> &[T]` * `Option<T>::as_slice_mut(&mut self) -> &[T]` The `as_slice` and `as_slice_mut` functions benefit from an optimization that makes them completely branch-free. Note that the optimization's soundness hinges on the fact that either the niche optimization makes the offset of the `Some(_)` contents zero or the mempory layout of `Option<T>` is equal to that of `Option<MaybeUninit<T>>`.
2023-02-28relax bounds on iterator adapter Default implsThe 8472-25/+6
2023-02-28rewrite iterator `Default` tests as doctestsThe 8472-0/+66
2023-02-28Implement Default for some alloc/core iteratorsThe 8472-0/+78
This way one can `mem::take()` them out of structs or #[derive(Default)] on structs containing them. These changes will be insta-stable.
2023-02-28Add QNX Neutrino support to libstdFlorian Bartels-0/+1
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-28Auto merge of #107987 - EFanZh:inline-poll-methods, r=Mark-Simulacrumbors-0/+5
Inline `Poll` methods With `opt-level="z"`, the `Poll::map*` methods are sometimes not inlined (see <https://godbolt.org/z/ca5ajKTEK>). This PR adds `#[inline]` to these methods. I have a project that can benefit from this change, but do we want to enable this behavior universally? Fixes #101080.
2023-02-28Auto merge of #106774 - Nugine:master, r=Amanieubors-1/+1
Stabilize cmpxchg16b_target_feature Tracking issue for target features + #44839 stdarch issue + https://github.com/rust-lang/stdarch/issues/827 stdarch PR + https://github.com/rust-lang/stdarch/pull/1358 reference PR + https://github.com/rust-lang/reference/pull/1331 It's my first time contributing to rust-lang/rust. Please tell me if I missed something.
2023-02-28Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebankbors-1/+0
Stabilize `#![feature(target_feature_11)]` ## Stabilization report ### Summary Allows for safe functions to be marked with `#[target_feature]` attributes. Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits. However, calling them from other `#[target_feature]` functions with a superset of features is safe. ```rust // Demonstration function #[target_feature(enable = "avx2")] fn avx2() {} fn foo() { // Calling `avx2` here is unsafe, as we must ensure // that AVX is available first. unsafe { avx2(); } } #[target_feature(enable = "avx2")] fn bar() { // Calling `avx2` here is safe. avx2(); } ``` ### Test cases Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](https://github.com/rust-lang/rust/tree/b67ba9ba208ac918228a18321fc3a11a99b1c62b/src/test/ui/rfcs/rfc-2396-target_feature-11/). ### Edge cases - https://github.com/rust-lang/rust/issues/73631 Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits. ```rust #[target_feature(enable = "avx2")] fn qux() { let my_closure = || avx2(); // this call to `avx2` is safe let f: fn() = my_closure; } ``` This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives. ### Documentation - Reference: https://github.com/rust-lang/reference/pull/1181 --- cc tracking issue #69098 r? `@ghost`
2023-02-27Add `Atomic*::from_ptr`Maybe Waffle-0/+135
2023-02-27Rollup merge of #104265 - faern:move-ipaddr-to-core, r=joshtriplettMatthias Krüger-0/+3300
Move IpAddr, SocketAddr and V4+V6 related types to `core` Implements RFC https://github.com/rust-lang/rfcs/pull/2832. The RFC has completed FCP with disposition merge, but is not yet merged. Moves IP types to `core` as specified in the RFC. The full list of moved types is: `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError`. Doing this move was one of the main driving arguments behind #78802.
2023-02-27Clarify that Copy is a trait in array docsCoca162-1/+1
2023-02-27Update docs to show [expr; N] can repeat const exprCoca162-2/+4
2023-02-26Add tracking issueJosh Triplett-1/+1
2023-02-26Move IpAddr and SocketAddr to coreLinus Färnstrand-0/+3300
2023-02-26Rollup merge of #108484 - ↵Matthias Krüger-1/+1
Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot Remove `from` lang item It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item.
2023-02-26Rollup merge of #108299 - scottmcm:literal-bits, r=NilstriebMatthias Krüger-36/+46
Require `literal`s for some `(u)int_impl!` parameters The point of these is to be seen *lexically* in the docs, so they should always be passed as the correct literal, not as an expression. (Otherwise we could just compute `Min`/`Max` from `BITS`, for example.) r? Nilstrieb
2023-02-26Remove `from_fn` lang itemNilstrieb-1/+1
It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item.
2023-02-26Rollup merge of #107890 - obeis:mapping-to-unit, r=cjgillotMatthias Krüger-0/+2
Lint against `Iterator::map` receiving a callable that returns `()` Close #106991
2023-02-25Auto merge of #107638 - zhangyunhao116:pdqsort-rand, r=cuviperbors-10/+14
Optimize break patterns Use `wyrand` instead of calling `XORSHIFT` 2 times in break patterns for the 64-bit platform. The new PRNG is 2x faster than the previous one. Bench result(via https://gist.github.com/zhangyunhao116/11ef41a150f5c23bb47d86255fbeba89): ``` old time: [1.3258 ns 1.3262 ns 1.3266 ns] change: [+0.5901% +0.6731% +0.7791%] (p = 0.00 < 0.05) Change within noise threshold. Found 13 outliers among 100 measurements (13.00%) 7 (7.00%) high mild 6 (6.00%) high severe new time: [657.65 ps 657.89 ps 658.18 ps] change: [-1.6910% -1.6110% -1.5256%] (p = 0.00 < 0.05) Performance has improved. Found 6 outliers among 100 measurements (6.00%) 2 (2.00%) high mild 4 (4.00%) high severe ```
2023-02-24Rollup merge of #106541 - fee1-dead-contrib:no-const-check-no, r=thomccDylan DPC-0/+77
implement const iterator using `rustc_do_not_const_check` Previous experiment: #102225. Explanation: rather than making all default methods work under `const` all at once, this uses `rustc_do_not_const_check` as a workaround to "trick" the compiler to not run any checks on those other default methods. Any const implementations are only required to implement the `next` method. Any actual calls to the trait methods other than `next` will either error in compile time (at CTFE runs), or run the methods correctly if they do not have any non-const operations. This is extremely easy to maintain, remove, or improve.
2023-02-23Stabilize atomic_as_ptrTrevor Gross-6/+7
2023-02-23black_box doc corrections - Issue #107957pat-nel87-3/+3
2023-02-23Add lint against `Iterator::map` receiving a callable that returns `()`Obei Sideg-0/+2