summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-03-31Partially revert 5b08c9f39754039ef9c6cbde157ac9eb8c252a58Oli Scherer-2/+8
2023-03-31Revert "Constify cmp_min_max_by"Oli Scherer-28/+6
This reverts commit 2e7a201d2e9e73477f1e69240711bfe09aefdc18.
2023-03-06Bump version placeholdersMark Rousskov-18/+18
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-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-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-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-23Add lint against `Iterator::map` receiving a callable that returns `()`Obei Sideg-0/+2
2023-02-22Require `literal`s for some `(u)int_impl!` parametersScott McMurray-36/+46
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.)
2023-02-22Rollup merge of #107736 - tgross35:atomic-as-ptr, r=m-ou-seMatthias Krüger-6/+6
Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893) Originally discussed in https://github.com/rust-lang/rust/issues/66893#issuecomment-1419198623 ~~This uses #107706 as a base to avoid a merge conflict once that gets rolled up (so disregard const changes in the diff until it does)~~ all merged & rebased `@rustbot` label +T-libs-api r? m-ou-se
2023-02-22Optimize break patternszhangyunhao-10/+14
2023-02-20Rollup merge of #108279 - Nilstrieb:int, r=scottmcmMatthias Krüger-78/+356
Use named arguments for `{,u}int_impls` macro This makes it way easier to understand. r? `@scottmcm`
2023-02-20Use named arguments for `int_impl` macroNilstrieb-39/+182
This makes it easier to understand.
2023-02-20Use named arguments for `uint_impl` macroNilstrieb-39/+174
This makes it easier to understand.
2023-02-20Rollup merge of #108124 - kornelski:cstr_c_char, r=thomccMatthias Krüger-0/+5
Document that CStr::as_ptr returns a type alias Rustdoc resolves type aliases too eagerly #15823 which makes the [std re-export](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.as_ptr) of `CStr::as_ptr` show `i8` instead of `c_char`. To work around this I've added info about `c_char` in the method's description. BTW, I've also added a comment to what-not-to-do example in case someone copypasted it without reading the surrounding text.
2023-02-19Rollup merge of #108130 - tshepang:just-one-example, r=workingjubileeDylan DPC-42/+0
"Basic usage" is redundant for there is just one example
2023-02-19Rollup merge of #106933 - schuelermine:fix/doc/102451, r=AmanieuDylan DPC-6/+14
Update documentation of select_nth_unstable and select_nth_unstable_by to state O(n^2) complexity See #102451
2023-02-18Update documentation of select_nth_unstable and select_nth_unstable_by and ↵Anselm Schüler-6/+14
select_nth_unstable_by_key to state O(n log n) worst case complexity Also remove erronious / in doc comment
2023-02-17Rollup merge of #104068 - yancyribbens:partial-cmp-doc-update, r=scottmcmMatthias Krüger-2/+20
rustdoc: Add PartialOrd trait to doc comment explanation The doc comments for [partial_cmp](https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/iterator.rs#L3478) is the exact same as the doc comment for [cmp](https://github.com/rust-lang/rust/blob/master/library/core/src/iter/traits/iterator.rs#L3413). This PR adds to the description `partial_cmp` to disambiguate the description from `cmp.`
2023-02-16rustdoc: Update the description to include PartialOrd elementsyancy-2/+20
2023-02-16"Basic usage" is redundant for there is just one exampleTshepang Mbambo-42/+0
2023-02-16Document that CStr::as_ptr returns a type aliasKornel-0/+5
Workaround for #15823
2023-02-16Rollup merge of #108084 - ink-feather-org:const_range, r=dtolnayDylan DPC-40/+63
Constify `RangeBounds`, `RangeX::contains` and `RangeX::is_empty` (where applicable). cc `@fee1-dead` `@rustbot` label +T-libs-api -T-libs Tracking issue: #108082
2023-02-15clarify correctness of `black_box`Callum Leslie-1/+2
2023-02-15Constify `RangeBounds`, `RangeX::contains` and `RangeX::is_empty`.onestacked-40/+63