about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-09-25Add 'must_use' attribute to 'char::len_utf8' and 'char::len_utf16';Gabriel Bjørnager Jensen-0/+4
2024-09-24Auto merge of #129587 - Voultapher:opt-for-size-variants-of-sort-impls, ↵bors-59/+202
r=cuviper Add `optimize_for_size` variants for stable and unstable sort as well as select_nth_unstable - Stable sort uses a simple merge-sort that re-uses the existing - rather gnarly - merge function. - Unstable sort jumps directly to the branchless heapsort fallback. - select_nth_unstable jumps directly to the median_of_medians fallback, which is augmented with a custom tiny smallsort and partition impl. Some code is duplicated but de-duplication would bring it's own problems. For example `swap_if_less` is critical for performance, if the sorting networks don't inline it perf drops drastically, however `#[inline(always)]` is also a poor fit, if the provided comparison function is huge, it gives the compiler an out to only instantiate `swap_if_less` once and call it. Another aspect that would suffer when making `swap_if_less` pub, is having to cfg out dozens of functions in in smallsort module. Part of https://github.com/rust-lang/rust/issues/125612 r​? `@Kobzol`
2024-09-24Auto merge of #130738 - bjoernager:const-make-ascii, r=jhprattbors-6/+20
Mark `make_ascii_uppercase` and `make_ascii_lowercase` in `[u8]` and `str` as const. Relevant tracking issue: #130698 This PR extends #130697 and #130713 to the similar methods in byte slices (`[u8]`) and string slices (`str`). For the `str` methods, this simply requires adding the `const` specifier to the function signatures. The `[u8]` methods, however, require (at least a temporary) reimplementation due to the use of iterators and `for` loops.
2024-09-24Mark and implement 'make_ascii_uppercase' and 'make_ascii_lowercase' in ↵Gabriel Bjørnager Jensen-6/+20
'[u8]' and 'str' as const;
2024-09-23Rollup merge of #130762 - RalfJung:const_intrinsic_copy, r=dtolnayMichael Goulet-20/+15
stabilize const_intrinsic_copy Fixes https://github.com/rust-lang/rust/issues/80697 This stabilizes ```rust mod ptr { pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize); pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize); } impl *const T { pub const unsafe fn copy_to(self, dest: *mut T, count: usize); pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize); } impl *mut T { pub const unsafe fn copy_to(self, dest: *mut T, count: usize); pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize); pub const unsafe fn copy_from(self, src: *const T, count: usize); pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize); } impl <T> NonNull<T> { pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize); pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize); pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize); } ``` In particular, this reverts https://github.com/rust-lang/rust/pull/117905, which reverted https://github.com/rust-lang/rust/pull/97276. The `NonNull` methods are not listed in the tracking issue, they were added to this feature gate in https://github.com/rust-lang/rust/pull/124498. The existing [FCP](https://github.com/rust-lang/rust/issues/80697#issuecomment-1022585839) does not cover them. They are however entirely identical to the `*mut` methods and already stable outside `const`. ``@rust-lang/libs-api`` please let me know if FCP will be required for the `NonNull` methods.
2024-09-23stabilize const_intrinsic_copyRalf Jung-20/+15
2024-09-23Add fast path for ascii to ascii in str::replaceLaiho-0/+33
2024-09-23random: add tracking issue, address other commentsjoboet-3/+3
2024-09-23std: implement the `random` featurejoboet-0/+64
Implements the ACP https://github.com/rust-lang/libs-team/issues/393.
2024-09-23Rollup merge of #130713 - bjoernager:const-char-make-ascii, r=NoratriebMatthias Krüger-4/+6
Mark `u8::make_ascii_uppercase` and `u8::make_ascii_lowercase` as const. Relevant tracking issue: #130698 This PR extends #130697 by also marking the `make_ascii_uppercase` and `make_ascii_lowercase` methods in `u8` as const. The `const_char_make_ascii` feature gate is additionally renamed to `const_make_ascii`.
2024-09-23Rollup merge of #130659 - bjoernager:const-char-encode-utf16, r=dtolnayMatthias Krüger-25/+36
Support `char::encode_utf16` in const scenarios. Relevant tracking issue: #130660 The method `char::encode_utf16` should be marked "const" to allow compile-time conversions. This PR additionally rewrites the `encode_utf16_raw` function for better readability whilst also reducing the amount of unsafe code. try-job: x86_64-msvc
2024-09-23Rollup merge of #129550 - kornelski:boxasstr, r=joshtriplett,dtolnayMatthias Krüger-0/+11
Add str.as_str() for easy Deref to string slices Working with `Box<str>` is cumbersome, because in places like `iter.filter()` it can end up being `&Box<str>` or even `&&Box<str>`, and such type doesn't always get auto-dereferenced as expected. Dereferencing such box to `&str` requires ugly syntax like `&**boxed_str` or `&***boxed_str`, with the exact amount of `*`s. `Box<str>` is [not easily comparable with other string types](https://github.com/rust-lang/rust/pull/129852) via `PartialEq`. `Box<str>` won't work for lookups in types like `HashSet<String>`, because `Borrow<String>` won't take types like `&Box<str>`. OTOH `set.contains(s.as_str())` works nicely regardless of levels of indirection. `String` has a simple solution for this: the `as_str()` method, and `Box<str>` should too.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-80/+87
2024-09-22Mark 'make_ascii_uppercase' and 'make_ascii_lowercase' in 'u8' as const; ↵Gabriel Bjørnager Jensen-4/+6
Rename 'const_char_make_ascii' feature gate to 'const_make_ascii';
2024-09-22Rollup merge of #130692 - RalfJung:result-flatten, r=NoratriebGuillaume Gomez-2/+8
make unstable Result::flatten a const fn This method is still unstable (tracked at https://github.com/rust-lang/rust/issues/70142), but there's no reason I can see for it not to be const -- after all, `Option::flatten` is const. So let's make the `Result` one `const` as well, under the same feature gate. Cc https://github.com/rust-lang/rust/issues/70142
2024-09-22Rollup merge of #130658 - EqualMa:patch-1, r=scottmcmGuillaume Gomez-1/+1
Fix docs of compare_bytes The docs of `compare_bytes`. The return value is positive if <del>`right`</del> `left` is greater
2024-09-22Auto merge of #130697 - bjoernager:const-char-make-ascii, r=dtolnaybors-2/+4
Mark `char::make_ascii_uppercase` and `char::make_ascii_lowercase` as const. Relevant tracking issue: #130698 The `make_ascii_uppercase` and `make_ascii_lowercase` methods in `char` should be marked "const." With the stabilisation of [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349/), this simply requires adding the `const` specifier to the function signatures.
2024-09-22Mark 'make_ascii_uppercase' and 'make_ascii_lowercase' in 'char' as const;Gabriel Bjørnager Jensen-2/+4
2024-09-22make unstable Result::flatten a const fnRalf Jung-2/+8
2024-09-21Mark and implement 'char::encode_utf16' as const; Rewrite 'encode_utf16_raw';Gabriel Bjørnager Jensen-25/+36
2024-09-21Fix docs of compare_bytesEqualMa-1/+1
2024-09-21ABI compatibility: mention Result guaranteeRalf Jung-0/+2
2024-09-21Reword ManuallyDrop+Box interactionTim (Theemathas) Chirananthavat-2/+3
2024-09-20Rollup merge of #130611 - bjoernager:const-char-encode-utf8, r=dtolnayGuillaume Gomez-2/+12
Address diagnostics regression for `const_char_encode_utf8`. Relevant tracking issue: #130512 This PR regains full diagnostics for non-const calls to `char::encode_utf8`.
2024-09-20Address diagnostics regression for 'const_char_encode_utf8';Gabriel Bjørnager Jensen-2/+12
2024-09-19Rollup merge of #130553 - GnomedDev:remove-clippy-paths, r=compiler-errorsMatthias Krüger-0/+10
[Clippy] Get rid of most `std` `match_def_path` usage, swap to diagnostic items. Part of https://github.com/rust-lang/rust-clippy/issues/5393. This was going to remove all `std` paths, but `SeekFrom` has issues being cleanly replaced with a diagnostic item as the paths are for variants, which currently cannot be diagnostic items. This also, as a last step, categories the paths to help with future path removals.
2024-09-19Rollup merge of #128001 - Krappa322:master, r=scottmcmMatthias Krüger-26/+53
Improve documentation for <integer>::from_str_radix Two improvements to the documentation: - Document `-` as a valid character for signed integer destinations - Make the documentation even more clear that extra whitespace and non-digit characters is invalid. Many other languages, e.g. c++, are very permissive in string to integer routines and simply try to consume as much as they can, ignoring the rest. This is trying to make the transition for developers who are used to the conversion semantics in these languages a bit easier.
2024-09-19Add str.as_str() for easy dereferencing of Box<str>Kornel-0/+11
2024-09-19[Clippy] Swap `manual_strip` to use diagnostic items instead of pathsGnomedDev-0/+3
2024-09-19[Clippy] Swap `waker_clone_wake` to use diagnostic item instead of pathGnomedDev-0/+1
2024-09-19[Clippy] Swap `filter_map_bool_then` to use diagnostic item instead of pathGnomedDev-0/+1
2024-09-19[Clippy] Swap `manual_while_let_some` to use diagnostic items instead of pathsGnomedDev-0/+2
2024-09-19[Clippy] Swap `float_equality_without_abs` to use diagnostic items instead ↵GnomedDev-0/+2
of paths
2024-09-19[Clippy] Swap `lines_filter_map_ok` to use a diagnostic item instead of pathGnomedDev-0/+1
2024-09-19Auto merge of #130547 - workingjubilee:rollup-tw30khz, r=workingjubileebors-3/+5
Rollup of 3 pull requests Successful merges: - #130531 (Check params for unsafety in THIR) - #130533 (Never patterns constitute a read for unsafety) - #130542 (Stabilize const `MaybeUninit::as_mut_ptr`) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-19Auto merge of #130511 - bjoernager:const-char-encode-utf8, r=dtolnaybors-18/+15
Support `char::encode_utf8` in const scenarios. This PR implements [`rust-lang/rfcs#3696`](https://github.com/rust-lang/rfcs/pull/3696/). This assumes [`const_slice_from_raw_parts_mut`](https://github.com/rust-lang/rust/issues/67456/).
2024-09-18run `x.py fmt`ultrabear-1/+4
2024-09-18remove feature attributes as const_maybe_uninit_as_mut_ptr is stabilizedultrabear-1/+0
2024-09-18stabilize `const_maybe_uninit_as_mut_ptr`ultrabear-2/+2
2024-09-18Mark and implement 'char::encode_utf8' as const.Gabriel Bjørnager Jensen-18/+15
2024-09-18Rollup merge of #130522 - GnomedDev:clippy-manual-retain-paths, ↵Jubilee-0/+5
r=compiler-errors [Clippy] Swap `manual_retain` to use diagnostic items instead of paths Part of https://github.com/rust-lang/rust-clippy/issues/5393, just a chore.
2024-09-18Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=AmanieuJubilee-5/+120
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut` Tracking issue for `lazy_get`: https://github.com/rust-lang/rust/issues/129333
2024-09-18library: Call it really_init_mut to avoid name collisionsJubilee Young-2/+2
2024-09-18library: Destabilize Lazy{Cell,Lock}::{force,deref}_mutJubilee Young-14/+4
2024-09-18[Clippy] Swap `manual_retain` to use diagnostic items instead of pathsGnomedDev-0/+5
2024-09-18Auto merge of #129491 - StackOverflowExcept1on:master, r=m-ou-sebors-8/+8
Pass `fmt::Arguments` by reference to `PanicInfo` and `PanicMessage` Resolves #129330 For some reason after #115974 and #126732 optimizations applied to panic handler became worse and compiler stopped removing panic locations if they are not used in the panic message. This PR fixes that and maybe we can merge it into beta before rust 1.81 is released. Note: optimization only works with `lto = "fat"`. r? libs-api
2024-09-18Auto merge of #129845 - scottmcm:redo-layout, r=Noratriebbors-56/+110
Take more advantage of the `isize::MAX` limit in `Layout` Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that #95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So take advantage of that to remove a bunch of checked math that's not actually needed. For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment. (And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
2024-09-17Take more advantage of the `isize::MAX` limit in `Layout`Scott McMurray-56/+110
Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that 95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So take advantage of that to remove a bunch of checked math that's not actually needed. For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment. (And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
2024-09-17Remove uneeded PartialOrd bound in cmp::Ord::clampArthur Carcano-1/+0
There is a Self: PartialOrd bound in Ord::clamp, but it is already required by the trait itself. Likely a left-over from the const trait deletion in 76dbe2910465072f85e74d6f7115ec9e6803e8bf. Reported-by: @noeensarguet
2024-09-17Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`Chayim Refael Friedman-6/+131
In the implementation of `force_mut`, I chose performance over safety. For `LazyLock` this isn't really a choice; the code has to be unsafe. But for `LazyCell`, we can have a full-safe implementation, but it will be a bit less performant, so I went with the unsafe approach.