about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-02-09Change wordingVenus Xeon-Blonde-7/+6
2024-02-09Auto merge of #120852 - matthiaskrgr:rollup-01pr8gj, r=matthiaskrgrbors-7/+16
Rollup of 11 pull requests Successful merges: - #120351 (Implement SystemTime for UEFI) - #120354 (improve normalization of `Pointee::Metadata`) - #120776 (Move path implementations into `sys`) - #120790 (better error message on download CI LLVM failure) - #120806 (Clippy subtree update) - #120815 (Improve `Option::inspect` docs) - #120822 (Emit more specific diagnostics when enums fail to cast with `as`) - #120827 (Print image input file and checksum in CI only) - #120836 (hide impls if trait bound is proven from env) - #120844 (Build DebugInfo for async closures) - #120851 (Remove duplicate release note) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-09Rollup merge of #120815 - camsteffen:inspect-docs, r=m-ou-seMatthias Krüger-7/+16
Improve `Option::inspect` docs * Refer to the function as "a function" instead of "the provided closure" since it is not necessarily a closure. * State that the original Option/Result is returned. * Adjust the example for `Option::inspect` to use chaining.
2024-02-09Auto merge of #120676 - Mark-Simulacrum:bootstrap-bump, r=clubby789bors-170/+42
Bump bootstrap compiler to just-built 1.77 beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-02-09Bump Unicode to version 15.1.0, regenerate tablesMarcondiro-6/+6
2024-02-09Improve Option::inspect docsCameron Steffen-7/+16
2024-02-09Auto merge of #120843 - matthiaskrgr:rollup-med37z5, r=matthiaskrgrbors-10/+13
Rollup of 8 pull requests Successful merges: - #113671 (Make privacy visitor use types more (instead of HIR)) - #120308 (core/time: avoid divisions in Duration::new) - #120693 (Invert diagnostic lints.) - #120704 (A drive-by rewrite of `give_region_a_name()`) - #120809 (Use `transmute_unchecked` in `NonZero::new`.) - #120817 (Fix more `ty::Error` ICEs in MIR passes) - #120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.) - #120831 (Startup objects disappearing from sysroot) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-09Rollup merge of #120809 - reitermarkus:generic-nonzero-constructors, r=NilstriebMatthias Krüger-3/+1
Use `transmute_unchecked` in `NonZero::new`. Tracking issue: https://github.com/rust-lang/rust/issues/120257 See https://github.com/rust-lang/rust/pull/120521#discussion_r1482615129.
2024-02-09Rollup merge of #120308 - utkarshgupta137:duration-opt, r=m-ou-seMatthias Krüger-7/+12
core/time: avoid divisions in Duration::new In our (decently large) code base, we use `SystemTime::UNIX_EPOCH.elapsed()` in a lot of places & often in a loop or in the hot path. On [Unix](https://github.com/rust-lang/rust/blob/1.75.0/library/std/src/sys/unix/time.rs#L153-L162) at least, it seems we do calculations before hand to ensure that nanos is within the valid range, yet `Duration::new()` still checks it again, using 2 divisions. It seems like adding a branch can make this function 33% faster on ARM64 in the cases where nanos is already in the valid range & seems to have no effect in the other case. Benchmarks: M1 Pro (14-inch base model): ``` duration/current/checked time: [1.5945 ns 1.6167 ns 1.6407 ns] Found 5 outliers among 100 measurements (5.00%) 2 (2.00%) high mild 3 (3.00%) high severe duration/current/unchecked time: [1.5941 ns 1.6051 ns 1.6179 ns] Found 2 outliers among 100 measurements (2.00%) 1 (1.00%) high mild 1 (1.00%) high severe duration/branched/checked time: [1.1997 ns 1.2048 ns 1.2104 ns] Found 8 outliers among 100 measurements (8.00%) 4 (4.00%) high mild 4 (4.00%) high severe duration/branched/unchecked time: [1.5881 ns 1.5957 ns 1.6039 ns] Found 6 outliers among 100 measurements (6.00%) 3 (3.00%) high mild 3 (3.00%) high severe ``` EC2 c7gd.16xlarge (Graviton 3): ``` duration/current/checked time: [2.7996 ns 2.8000 ns 2.8003 ns] Found 5 outliers among 100 measurements (5.00%) 2 (2.00%) low severe 3 (3.00%) low mild duration/current/unchecked time: [2.9922 ns 2.9925 ns 2.9928 ns] Found 7 outliers among 100 measurements (7.00%) 4 (4.00%) low severe 1 (1.00%) low mild 2 (2.00%) high mild duration/branched/checked time: [2.0830 ns 2.0843 ns 2.0857 ns] Found 3 outliers among 100 measurements (3.00%) 1 (1.00%) low severe 1 (1.00%) low mild 1 (1.00%) high mild duration/branched/unchecked time: [2.9879 ns 2.9886 ns 2.9893 ns] Found 5 outliers among 100 measurements (5.00%) 3 (3.00%) low severe 2 (2.00%) low mild ``` EC2 r7iz.16xlarge (Intel Xeon Scalable-based (Sapphire Rapids)): ``` duration/current/checked time: [980.60 ps 980.79 ps 980.99 ps] Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) low severe 2 (2.00%) low mild 3 (3.00%) high mild 1 (1.00%) high severe duration/current/unchecked time: [979.53 ps 979.74 ps 979.96 ps] Found 6 outliers among 100 measurements (6.00%) 2 (2.00%) low severe 1 (1.00%) low mild 2 (2.00%) high mild 1 (1.00%) high severe duration/branched/checked time: [938.72 ps 938.96 ps 939.22 ps] Found 4 outliers among 100 measurements (4.00%) 1 (1.00%) low mild 1 (1.00%) high mild 2 (2.00%) high severe duration/branched/unchecked time: [1.0103 ns 1.0110 ns 1.0118 ns] Found 10 outliers among 100 measurements (10.00%) 2 (2.00%) low mild 7 (7.00%) high mild 1 (1.00%) high severe ``` Bench code (ran using stable 1.75.0 & criterion latest 0.5.1): I couldn't find any benches for `Duration` in this repo, so I just copied the relevant types & recreated it. ```rust use criterion::{black_box, criterion_group, criterion_main, Criterion}; pub fn duration_bench(c: &mut Criterion) { const NANOS_PER_SEC: u32 = 1_000_000_000; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] struct Nanoseconds(u32); impl Default for Nanoseconds { #[inline] fn default() -> Self { // SAFETY: 0 is within the valid range unsafe { Nanoseconds(0) } } } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct Duration { secs: u64, nanos: Nanoseconds, // Always 0 <= nanos < NANOS_PER_SEC } impl Duration { #[inline] pub const fn new_current(secs: u64, nanos: u32) -> Duration { let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) { Some(secs) => secs, None => panic!("overflow in Duration::new"), }; let nanos = nanos % NANOS_PER_SEC; // SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range Duration { secs, nanos: unsafe { Nanoseconds(nanos) } } } #[inline] pub const fn new_branched(secs: u64, nanos: u32) -> Duration { if nanos < NANOS_PER_SEC { // SAFETY: nanos < NANOS_PER_SEC, therefore nanos is within the valid range Duration { secs, nanos: unsafe { Nanoseconds(nanos) } } } else { let secs = match secs.checked_add((nanos / NANOS_PER_SEC) as u64) { Some(secs) => secs, None => panic!("overflow in Duration::new"), }; let nanos = nanos % NANOS_PER_SEC; // SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range Duration { secs, nanos: unsafe { Nanoseconds(nanos) } } } } } let mut group = c.benchmark_group("duration/current"); group.bench_function("checked", |b| { b.iter(|| black_box(Duration::new_current(black_box(1_000_000_000), black_box(1_000_000)))); }); group.bench_function("unchecked", |b| { b.iter(|| { black_box(Duration::new_current(black_box(1_000_000_000), black_box(2_000_000_000))) }); }); drop(group); let mut group = c.benchmark_group("duration/branched"); group.bench_function("checked", |b| { b.iter(|| { black_box(Duration::new_branched(black_box(1_000_000_000), black_box(1_000_000))) }); }); group.bench_function("unchecked", |b| { b.iter(|| { black_box(Duration::new_branched(black_box(1_000_000_000), black_box(2_000_000_000))) }); }); } criterion_group!(duration_benches, duration_bench); criterion_main!(duration_benches); ```
2024-02-08Clarify that atomic and regular integers can differ in alignmentLegionMammal978-1/+10
The documentation for atomic integers says that they have the "same in-memory representation" as their underlying integers. This might be misconstrued as implying that they have the same layout. Therefore, clarify that atomic integers' alignment is equal to their size.
2024-02-08Add and use Unique::as_non_null_ptrBen Kimock-4/+9
2024-02-08Make `NonZero::get` generic.Markus Reiter-20/+21
2024-02-08Use `transmute_unchecked` in `NonZero::new`.Markus Reiter-3/+1
2024-02-08Reduce use of NonNull::new_unchecked in library/Ben Kimock-14/+13
2024-02-08Remove a now-obviated debug_assert!Ben Kimock-1/+0
2024-02-08Rewrite assert_unsafe_precondition around the new intrinsicBen Kimock-59/+147
2024-02-08Add a new debug_assertions intrinsicBen Kimock-0/+11
2024-02-08Step all bootstrap cfgs forwardMark Rousskov-138/+10
This also takes care of other bootstrap-related changes.
2024-02-08Bump version placeholdersMark Rousskov-34/+34
2024-02-08Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebankbors-36/+0
Stop bailing out from compilation just because there were incoherent traits fixes #120343 but also has a lot of "type annotations needed" fallout. Some are fixed in the second commit.
2024-02-07Fix whitespace issues that tidy caughtVenus Xeon-Blonde-4/+4
2024-02-07Add documentation on `str::starts_with`Venus Xeon-Blonde-0/+14
Add documentation about a current footgun of `str::starts_with`
2024-02-08Auto merge of #120521 - reitermarkus:generic-nonzero-constructors, r=dtolnaybors-87/+99
Make `NonZero` constructors generic. This makes `NonZero` constructors generic, so that `NonZero::new` can be used without turbofish syntax. Tracking issue: https://github.com/rust-lang/rust/issues/120257 ~~I cannot figure out how to make this work with `const` traits. Not sure if I'm using it wrong or whether there's a bug:~~ ```rust 101 | if n == T::ZERO { | ^^^^^^^^^^^^ expected `host`, found `true` | = note: expected constant `host` found constant `true` ``` r? `@dtolnay`
2024-02-08Auto merge of #120381 - fee1-dead-contrib:reconstify-add, r=compiler-errorsbors-1/+3
Reconstify `Add` r? project-const-traits I'm not happy with the ui test changes (or failures because I did not bless them and include the diffs in this PR). There is at least some bugs I need to look and try fix: 1. A third duplicated diagnostic when a consumer crate that does not have `effects` enabled has a trait selection error for an upstream const_trait trait. See tests/ui/ufcs/ufcs-qpath-self-mismatch.rs. 2. For some reason, making `Add` a const trait would stop us from suggesting `T: Add` when we try to add two `T`s without that bound. See tests/ui/suggestions/issue-97677.rs
2024-02-07Make `io::BorrowedCursor::advance` safeBenoît du Garreau-13/+25
This also keeps the old `advance` method under `advance_unchecked` name. This makes pattern like `std::io::default_read_buf` safe to write.
2024-02-07Replace `transmute_copy` with `ptr::read`.Markus Reiter-1/+2
2024-02-07Don't use `assert_unsafe_precondition` twice.Markus Reiter-12/+10
2024-02-07Make `NonZero` constructors generic.Markus Reiter-71/+84
2024-02-07Simplify `impl_zeroable_primitive` macro.Markus Reiter-13/+13
2024-02-07Update testsr0cky-0/+1
2024-02-06Auto merge of #117905 - RalfJung:no-const-mut, r=lcnrbors-12/+17
revert stabilization of const_intrinsic_copy `@rust-lang/wg-const-eval` I don't know what we were thinking when we approved https://github.com/rust-lang/rust/pull/97276... const-eval isn't supposed to be able to mutate anything yet! It's also near impossible to actually call `copy` in const on stable since `&mut` expressions are generally unstable. However, there's one exception... ```rust static mut INT: i32 = unsafe { let val = &mut [1]; // `&mut` on arrays is allowed in `static mut` (val as *mut [i32; 1]).copy_from(&[42], 1); val[0] }; fn main() { unsafe { dbg!(INT); } } ``` Inside `static mut`, we accept some `&mut` since ~forever, to make `static mut FOO: &mut [T] = &mut [...];` work. We reject any attempt to actually write to that mutable reference though... except for the `copy` functions. I think we should revert stabilizing these functions that take `*mut`, and then re-stabilize them together with `ptr.write` once mutable references are stable. (This will likely fail on PowerPC until https://github.com/rust-lang/stdarch/pull/1497 lands. But we'll need a crater run first anyway.)
2024-02-06Harmonize blanket implementations for AsyncFn* traitsMichael Goulet-14/+37
2024-02-06Bless tests, add commentsMichael Goulet-2/+19
2024-02-06Teach typeck/borrowck/solvers how to deal with async closuresMichael Goulet-0/+8
2024-02-05revert stabilization of const_intrinsic_copyRalf Jung-12/+17
2024-02-05Auto merge of #117372 - Amanieu:stdarch_update, r=Mark-Simulacrumbors-4/+0
Update stdarch submodule Splits up #27731 into multiple tracking issues. Closes #27731
2024-02-05Remove some invalid cfg(doc) codeOli Scherer-36/+0
2024-02-05Rollup merge of #120384 - wackbyte:array-equality-generics, r=Mark-SimulacrumMatthias Krüger-36/+36
Use `<T, U>` for array/slice equality `impl`s Makes the trait implementation documentation for arrays and slices appear more consistent. [Example](https://doc.rust-lang.org/1.75.0/std/primitive.array.html): mixed `A`, `B`, and `U`. ![List of PartialEq implementations for arrays](https://github.com/wackbyte/rust/assets/29505620/823c010e-ee57-4de1-885b-a1cd6dcaf85f) This change makes them all `U`.
2024-02-05Rollup merge of #118960 - tvallotton:local_waker, r=Mark-SimulacrumMatthias Krüger-37/+353
Add LocalWaker and ContextBuilder types to core, and LocalWake trait to alloc. Implementation for #118959.
2024-02-05Rollup merge of #115386 - RalfJung:partial-eq-chain, r=dtolnayMatthias Krüger-8/+52
PartialEq, PartialOrd: update and synchronize handling of transitive chains It was brought up in https://internals.rust-lang.org/t/total-equality-relations-as-std-eq-rhs/19232 that we currently have a gap in our `PartialEq` rules, which this PR aims to close: > For example, with PartialEq's conditions you may have a = b = c = d ≠ a (where a and c are of type A, b and d are of type B). The second commit fixes https://github.com/rust-lang/rust/issues/87067 by updating PartialOrd to handle the requirements the same way PartialEq does.
2024-02-05Rollup merge of #119481 - romanows:fix-doc-select-nth-unstable, ↵Matthias Krüger-7/+7
r=Mark-Simulacrum Clarify ambiguity in select_nth_unstable docs Original docs for `select_nth_unstable` family of functions were ambiguous as to whether "the element at `index`" was the element at `index` before the function reordered the elements or after the function reordered the elements. The most helpful change in this PR is to change the given examples to make this absolutely clear. Before, "the element at `index`" was the same value before and after the reordering, so it didn't help disambiguate the meaning. I've changed the example for `select_nth_unstable` and `select_nth_unstable_by` so that "the element at `index`" is different before and after the reordering, which clears up the ambiguity. The function `select_nth_unstable_by_key` already had an example that was unambiguous. In an attempt to clear up the ambiguity from the get-go, I've added a bit of redundancy to the text. Now the docs refer to "the element at `index` *after the reordering*".
2024-02-04Reconstify `Add`Deadbeef-1/+3
2024-02-03Docs for std::ptr::slice_from_raw_partsKornel-2/+26
2024-02-02fix typoRalf Jung-2/+2
Co-authored-by: teor <teor@riseup.net>
2024-02-01Revert unsound libcore changes of #119911Oli Scherer-385/+149
2024-01-30Rollup merge of #120295 - reitermarkus:remove-ffi-nonzero, r=dtolnayGuillaume Gomez-50/+14
Remove `raw_os_nonzero` feature. This feature is superseded by a generic `NonZero` type: https://github.com/rust-lang/rust/issues/120257 Closes https://github.com/rust-lang/rust/issues/82363.
2024-01-30Rollup merge of #120424 - RalfJung:raw-ptr-meta, r=NilstriebGuillaume Gomez-14/+14
raw pointer metadata API: data address -> data pointer A pointer consists of [more than just an address](https://github.com/rust-lang/rfcs/pull/3559), so let's not equate "pointer" and "address" in these docs.
2024-01-30Update feature names for new stdarchAmanieu d'Antras-4/+0
2024-01-29Remove `raw_os_nonzero` feature.Markus Reiter-50/+14
2024-01-29Rollup merge of #116677 - joshlf:patch-11, r=RalfJungDylan DPC-0/+24
References refer to allocated objects Partially addresses https://github.com/rust-lang/unsafe-code-guidelines/issues/465