about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-01-20fix: Apply suggestions from code reviewtvallotton-3/+2
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2024-01-20doc: update thread safety explanation for RawWakerVTable and RawWaker.Tomás Vallotton-19/+43
2024-01-20chore: add and !Sync impls for LocalWaker as a stability guarantee.Tomás Vallotton-0/+5
2024-01-20fix: change issue number of waker_getters from #87021 to #96992.Tomás Vallotton-1/+1
2024-01-20chore: fix ci failuresTomás Vallotton-3/+3
2024-01-20feat: impl AsRef<LocalWaker> for Waker.Tomás Vallotton-0/+8
2024-01-20chore: add tracking issue number to local waker featureTomás Vallotton-14/+14
2024-01-20fix: make LocalWake available in targets that don't support atomics by ↵Tomás Vallotton-2/+2
removing a #[cfg(target_has_atomic = ptr)]
2024-01-20feat: add try_waker and From<&mut Context> for ContextBuilder to allow the ↵Tomás Vallotton-12/+67
extention of contexts by futures
2024-01-20refactor: remove in favor of and to make the API infallible.Tomás Vallotton-52/+29
2024-01-20perf: move null check from local_wake() to build()Tomás Vallotton-9/+16
2024-01-20feat: add LocalWaker type, ContextBuilder type, and LocalWake trait.Tomás Vallotton-24/+339
2024-01-20Rollup merge of #118799 - GKFX:stabilize-simple-offsetof, r=wesleywiserMatthias Krüger-9/+7
Stabilize single-field offset_of This PR stabilizes offset_of for a single field. There has been some further discussion at https://github.com/rust-lang/rust/issues/106655 about whether this is advisable; I'm opening the PR anyway so that the code is available.
2024-01-20Rollup merge of #113142 - the8472:opt-cstr-display, r=Mark-SimulacrumMatthias Krüger-1/+67
optimize EscapeAscii's Display and CStr's Debug ``` old: ascii::bench_ascii_escape_display_mixed 17.97µs/iter +/- 204.00ns ascii::bench_ascii_escape_display_no_escape 545.00ns/iter +/- 6.00ns new: ascii::bench_ascii_escape_display_mixed 4.99µs/iter +/- 56.00ns ascii::bench_ascii_escape_display_no_escape 91.00ns/iter +/- 1.00ns ```
2024-01-20Rollup merge of #103730 - SOF3:nonzero-from-mut, r=Mark-Simulacrum,dtolnayMatthias Krüger-0/+33
Added NonZeroXxx::from_mut(_unchecked)? ACP: rust-lang/libs-team#129 Tracking issue: #106290
2024-01-19Tweak the threshold for chunked swappingAngelicosPhosphoros-1/+1
Thanks to 98892 for the tests I brought in here, as it demonstrated that 3×usize is currently suboptimal.
2024-01-19Assign tracking issue number for feature(nonzero_from_mut)SOFe-2/+2
2024-01-19Added assert_unsafe_precondition! check for NonZeroXxx::from_mut_uncheckedSOFe-13/+20
2024-01-19Added NonZeroXxx::from_mut(_unchecked)?SOFe-0/+26
2024-01-19Consolidate logic around resolving built-in coroutine trait implsMichael Goulet-0/+1
2024-01-19Stabilize simple offset_ofGeorge Bateman-9/+7
2024-01-19Clarify Panicking Behavior in Integer Division DocsNicholas Thompson-19/+8
2024-01-19Make `saturating_div` Docs Consistent with OthersNicholas Thompson-10/+8
2024-01-19Adjust Attributes of Integer Division MethodsNicholas Thompson-7/+18
2024-01-19Add new intrinsic `is_constant` and optimize `pow`Catherine Flores-34/+138
Fix overflow check Make MIRI choose the path randomly and rename the intrinsic Add back test Add miri test and make it operate on `ptr` Define `llvm.is.constant` for primitives Update MIRI comment and fix test in stage2 Add const eval test Clarify that both branches must have the same side effects guaranteed non guarantee use immediate type instead Co-Authored-By: Ralf Jung <post@ralfj.de>
2024-01-19Rollup merge of #119984 - kpreid:waker-noop, r=dtolnayMatthias Krüger-5/+12
Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`. The advantage of this is that it does not need to be assigned to a variable to be used in a `Context` creation, which is the most common thing to want to do with a noop waker. It also avoids unnecessarily executing the dynamically dispatched drop function when the noop waker is dropped. If an owned noop waker is desired, it can be created by cloning, but the reverse is harder to do since it requires declaring a constant. Alternatively, both versions could be provided, like `futures::task::noop_waker()` and `futures::task::noop_waker_ref()`, but that seems to me to be API clutter for a very small benefit, whereas having the `&'static` reference available is a large reduction in boilerplate. [Previous discussion on the tracking issue starting here](https://github.com/rust-lang/rust/issues/98286#issuecomment-1862159766)
2024-01-19Rollup merge of #117561 - tgross35:split-array, r=scottmcmMatthias Krüger-222/+76
Stabilize `slice_first_last_chunk` This PR does a few different things based around stabilizing `slice_first_last_chunk`. They are split up so this PR can be by-commit reviewed, I can move parts to a separate PR if desired. This feature provides a very elegant API to extract arrays from either end of a slice, such as for parsing integers from binary data. ## Stabilize `slice_first_last_chunk` ACP: https://github.com/rust-lang/libs-team/issues/69 Implementation: https://github.com/rust-lang/rust/issues/90091 Tracking issue: https://github.com/rust-lang/rust/issues/111774 This stabilizes the functionality from https://github.com/rust-lang/rust/issues/111774: ```rust impl [T] { pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>; pub fn split_first_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>; pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T], &[T; N])>; pub fn split_last_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T], &mut [T; N])>; } ``` Const stabilization is included for all non-mut methods, which are blocked on `const_mut_refs`. This change includes marking the trivial function `slice_split_at_unchecked` const-stable for internal use (but not fully stable). ## Remove `split_array` slice methods Tracking issue: https://github.com/rust-lang/rust/issues/90091 Implementation: https://github.com/rust-lang/rust/pull/83233#pullrequestreview-780315524 This PR also removes the following unstable methods from the `split_array` feature, https://github.com/rust-lang/rust/issues/90091: ```rust impl<T> [T] { pub fn split_array_ref<const N: usize>(&self) -> (&[T; N], &[T]); pub fn split_array_mut<const N: usize>(&mut self) -> (&mut [T; N], &mut [T]); pub fn rsplit_array_ref<const N: usize>(&self) -> (&[T], &[T; N]); pub fn rsplit_array_mut<const N: usize>(&mut self) -> (&mut [T], &mut [T; N]); } ``` This is done because discussion at #90091 and its implementation PR indicate a strong preference for nonpanicking APIs that return `Option`. The only difference between functions under the `split_array` and `slice_first_last_chunk` features is `Option` vs. panic, so remove the duplicates as part of this stabilization. This does not affect the array methods from `split_array`. We will want to revisit these once `generic_const_exprs` is further along. ## Reverse order of return tuple for `split_last_chunk{,_mut}` An unresolved question for #111774 is whether to return `(preceding_slice, last_chunk)` (`(&[T], &[T; N])`) or the reverse (`(&[T; N], &[T])`), from `split_last_chunk` and `split_last_chunk_mut`. It is currently implemented as `(last_chunk, preceding_slice)` which matches `split_last -> (&T, &[T])`. The first commit changes these to `(&[T], &[T; N])` for these reasons: - More consistent with other splitting methods that return multiple values: `str::rsplit_once`, `slice::split_at{,_mut}`, `slice::align_to` all return tuples with the items in order - More intuitive (arguably opinion, but it is consistent with other language elements like pattern matching `let [a, b, rest @ ..] ...` - If we ever added a varidic way to obtain multiple chunks, it would likely return something in order: `.split_many_last::<(2, 4)>() -> (&[T], &[T; 2], &[T; 4])` - It is the ordering used in the `rsplit_array` methods I think the inconsistency with `split_last` could be acceptable in this case, since for `split_last` the scalar `&T` doesn't have any internal order to maintain with the other items. ## Unresolved questions Do we want to reserve the same names on `[u8; N]` to avoid inference confusion? https://github.com/rust-lang/rust/pull/117561#issuecomment-1793388647 --- `slice_first_last_chunk` has only been around since early 2023, but `split_array` has been around since 2021. `@rustbot` label -T-libs +T-libs-api -T-libs +needs-fcp cc `@rust-lang/wg-const-eval,` `@scottmcm` who raised this topic, `@clarfonthey` implementer of `slice_first_last_chunk` `@jethrogb` implementer of `split_array` Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Stabilizing.20array-from-slice.20*something*.3F Fixes: #111774
2024-01-19Rollup merge of #119907 - asquared31415:fn_trait_docs, r=NilstriebMatthias Krüger-8/+2
Update `fn()` trait implementation docs Fixes #119903 This was FCP'd and approved for the 1.70.0 release, this is just a docs update to match that change.
2024-01-19Rollup merge of #119138 - ↵Matthias Krüger-4/+9
AngelicosPhosphoros:use_proper_atomics_in_spinlock_example, r=Nilstrieb Docs: Use non-SeqCst in module example of atomics I done this for this reasons: 1. The example now shows that there is more Orderings than just SeqCst. 2. People who would copy from example would now have more suitable orderings for the job. 3. SeqCst is both much harder to reason about and not needed in most situations. IMHO, we should encourage people to think and use memory orderings that is suitable to task instead of blindly defaulting to SeqCst. r? `@m-ou-se`
2024-01-19Rollup merge of #118665 - dtolnay:signedness, r=NilstriebMatthias Krüger-1265/+1211
Consolidate all associated items on the NonZero integer types into a single impl block per type **Before:** ```rust #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] pub struct NonZeroI8(i8); impl NonZeroI8 { pub const fn new(n: i8) -> Option<Self> ... pub const fn get(self) -> i8 ... } impl NonZeroI8 { pub const fn leading_zeros(self) -> u32 ... pub const fn trailing_zeros(self) -> u32 ... } impl NonZeroI8 { pub const fn abs(self) -> NonZeroI8 ... } ... ``` **After:** ```rust #[repr(transparent)] #[rustc_layout_scalar_valid_range_start(1)] pub struct NonZeroI8(i8); impl NonZeroI8 { pub const fn new(n: i8) -> Option<Self> ... pub const fn get(self) -> i8 ... pub const fn leading_zeros(self) -> u32 ... pub const fn trailing_zeros(self) -> u32 ... pub const fn abs(self) -> NonZeroI8 ... ... } ``` Having 6-7 different impl blocks per type is not such a problem in today's implementation, but becomes awful upon the switch to a generic `NonZero<T>` type (context: https://github.com/rust-lang/rust/issues/82363#issuecomment-921513910). In the implementation from https://github.com/rust-lang/rust/pull/100428, there end up being **67** impl blocks on that type. <img src="https://github.com/rust-lang/rust/assets/1940490/5b68bd6f-8a36-4922-baa3-348e30dbfcc1" width="200"><img src="https://github.com/rust-lang/rust/assets/1940490/2cfec71e-c2cd-4361-a542-487f13f435d9" width="200"><img src="https://github.com/rust-lang/rust/assets/1940490/2fe00337-7307-405d-9036-6fe1e58b2627" width="200"> Without the refactor to a single impl block first, introducing `NonZero<T>` would be a usability regression compared to today's separate pages per type. With all those blocks expanded, Ctrl+F is obnoxious because you need to skip 12&times; past every match you don't care about. With all the blocks collapsed, Ctrl+F is useless. Getting to a state in which exactly one type's (e.g. `NonZero<u32>`) impl blocks are expanded while the rest are collapsed is annoying. After this refactor to a single impl block, we can move forward with making `NonZero<T>` a generic struct whose docs all go on the same rustdoc page. The rustdoc will have 12 impl blocks, one per choice of `T` supported by the standard library. The reader can expand a single one of those impl blocks e.g. `NonZero<u32>` to understand the entire API of that type. Note that moving the API into a generic `impl<T> NonZero<T> { ... }` is not going to be an option until after `NonZero<T>` has been stabilized, which may be months or years after its introduction. During the period while generic `NonZero` is unstable, it will be extra important to offer good documentation on all methods demonstrating the API being used through the stable aliases such as `NonZeroI8`. This PR follows a `key = $value` syntax for the macros which is similar to the macros we already use for producing a single large impl block on the integer primitives. https://github.com/rust-lang/rust/blob/1dd4db50620fb38a6382c22456a96ed7cddeff83/library/core/src/num/mod.rs#L288-L309 Best reviewed one commit at a time.
2024-01-17Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.Kevin Reid-5/+12
The advantage of this is that it does not need to be assigned to a variable to be used in a `Context` creation, which is the most common thing to want to do with a noop waker. If an owned noop waker is desired, it can be created by cloning, but the reverse is harder. Alternatively, both versions could be provided, like `futures::task::noop_waker()` and `futures::task::noop_waker_ref()`, but that seems to me to be API clutter for a very small benefit, whereas having the `&'static` reference available is a large benefit. Previous discussion on the tracking issue starting here: https://github.com/rust-lang/rust/issues/98286#issuecomment-1862159766
2024-01-16Un-hide `iter::repeat_n`Scott McMurray-2/+0
2024-01-16Suggest less bug-prone construction of Duration in docsBen Wiederhake-0/+5
2024-01-16Rename `pointer` field on `Pin`LegionMammal978-20/+26
The internal, unstable field of `Pin` can conflict with fields from the inner type accessed via the `Deref` impl. Rename it from `pointer` to `__pointer`, to make it less likely to conflict with anything else.
2024-01-16Auto merge of #120025 - matthiaskrgr:rollup-e9ai06k, r=matthiaskrgrbors-15/+80
Rollup of 8 pull requests Successful merges: - #118361 (stabilise bound_map) - #119816 (Define hidden types in confirmation) - #119900 (Inline `check_closure`, simplify `deduce_sig_from_projection`) - #119969 (Simplify `closure_env_ty` and `closure_env_param`) - #119990 (Add private `NonZero<T>` type alias.) - #119998 (Update books) - #120002 (Lint `overlapping_ranges_endpoints` directly instead of collecting into a Vec) - #120018 (Don't allow `.html` files in `tests/mir-opt/`) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-16Rollup merge of #119990 - reitermarkus:nonzero-type-alias, r=dtolnayMatthias Krüger-12/+79
Add private `NonZero<T>` type alias. According to step 2 suggested in https://github.com/rust-lang/rust/pull/100428#pullrequestreview-1767139731. This adds a private type alias for `NonZero<T>` so that some parts of the code can already start using `NonZero<T>` syntax. Using `NonZero<T>` for `convert` and other parts which implement `From` doesn't work while it is a type alias, since this results in conflicting implementations.
2024-01-16Rollup merge of #118361 - Dylan-DPC:80626/stab/bound-map, r=AmanieuMatthias Krüger-3/+1
stabilise bound_map Closes https://github.com/rust-lang/rust/issues/86026
2024-01-16Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkinbors-2/+10
Split out `option::unwrap_failed` like we have `result::unwrap_failed` ...and like `option::expect_failed`
2024-01-15Revert unrelated changes from PR 119990David Tolnay-3/+3
2024-01-15Add private `NonZero<T>` type alias.Markus Reiter-15/+82
2024-01-15Auto merge of #119878 - scottmcm:inline-always-unwrap, r=workingjubileebors-1/+1
Tune the inlinability of `unwrap` Fixes #115463 cc `@thomcc` This tweaks `unwrap` on ~~`Option` &~~ `Result` to be two parts: - `#[inline(always)]` for checking the discriminant - `#[cold]` for actually panicking The idea here is that checking the discriminant on a `Result` ~~or `Option`~~ should always be trivial enough to be worth inlining, even in `opt-level=z`, especially compared to passing it to a function. As seen in the issue and codegen test, this will hopefully help particularly for things like `.try_into().unwrap()`s that are actually infallible, but in a way that's only visible with the inlining. EDIT: I've restricted this to `Result` to avoid combining effects
2024-01-14Unbreak tidy's feature parserDavid Tolnay-52/+31
tidy error: /git/rust/library/core/src/num/nonzero.rs:67: malformed stability attribute: missing `feature` key tidy error: /git/rust/library/core/src/num/nonzero.rs:82: malformed stability attribute: missing `feature` key tidy error: /git/rust/library/core/src/num/nonzero.rs:98: malformed stability attribute: missing the `since` key tidy error: /git/rust/library/core/src/num/nonzero.rs:112: malformed stability attribute: missing `feature` key tidy error: /git/rust/library/core/src/num/nonzero.rs:450: malformed stability attribute: missing `feature` key some tidy checks failed
2024-01-14Move BITS into omnibus impl blockDavid Tolnay-37/+14
2024-01-14Move signed MIN and MAX into signedness_dependent_methodsDavid Tolnay-52/+35
2024-01-14Move unsigned MIN and MAX into signedness_dependent_methodsDavid Tolnay-43/+26
2024-01-14Move is_power_of_two into unsigned part of signedness_dependent_methodsDavid Tolnay-40/+28
2024-01-14Move nonzero_unsigned_signed_operations methods into the omnibus impl blockDavid Tolnay-225/+201
2024-01-14Work around rustfmt doc attribute indentation bugDavid Tolnay-0/+1
2024-01-14Unindent nonzero_integer_signedness_dependent_methods macro bodyDavid Tolnay-589/+589
2024-01-14Move signedness dependent methods into the omnibus impl blockDavid Tolnay-35/+30