about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2025-05-06Rollup merge of #136183 - hkBst:patch-25, r=AmanieuGuillaume Gomez-230/+225
Update iterator.rs to use arrays by value Update examples to no longer avoid iterating arrays for #84513
2025-05-06Update iterator.rs to use arrays by valueMarijn Schouten-230/+225
Update examples to no longer avoid iterating arrays for #84513
2025-05-06Rollup merge of #140598 - ShE3py:iter-misc-docs, r=workingjubileeStuart Cook-0/+3
Steer docs to `utf8_chunks` and `Iterator::take` - Adds `limit` as an alias of `take` (as this is [what Java calls this operation](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#limit-long-)); - Says that [`Utf8Chunks`](https://doc.rust-lang.org/std/str/struct.Utf8Chunks.html) comes from [`[u8]::utf8_chunks`](https://doc.rust-lang.org/std/primitive.slice.html#method.utf8_chunks). ``@rustbot`` label +A-docs
2025-05-05Fix parameter order for `_by()` variants of `min` / `max`/ `minmax` in ↵Michael Rieder-3/+26
`std::cmp`
2025-05-05Rollup merge of #140644 - the8472:revert-copy-clone-adapters, r=Mark-SimulacrumTrevor Gross-163/+20
Revert "Avoid unused clones in Cloned<I> and Copied<I>" Per libs decision in https://github.com/rust-lang/rust/issues/140207#issuecomment-2842996190 this reverts commit ed5f31ab01d41a01b7206eafdf97b458dc41141a (#139745)
2025-05-04Rollup merge of #137280 - RalfJung:const_swap_nonoverlapping, r=lcnrTrevor Gross-2/+36
stabilize ptr::swap_nonoverlapping in const Closes https://github.com/rust-lang/rust/issues/133668 The blocking issue mentioned there is resolved by documentation. We may in the future actually support such code, but that is blocked on https://github.com/rust-lang/const-eval/issues/72 which is non-trivial to implement. Meanwhile, this completes stabilization of all `const fn` in `ptr`. :) Here's a version of the problematic example to play around with: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6c390452379fb593e109b8f8ee854d2a Should be FCP'd with both `@rust-lang/libs-api` and `@rust-lang/lang` since `swap_nonoverlapping` is documented to work as an "untyped" operation but due to the limitation mentioned above, that's not entirely true during const evaluation. I expect this limitation will only be hit in niche corner cases, so the benefits of having this function work most of the time outweigh the downsides of users running into this problem. (Note that unsafe code could already hit this limitation before this PR by doing cursed pointer casts, but having it hidden inside `swap_nonoverlapping` feels a bit different.)
2025-05-04Revert "Avoid unused clones in Cloned<I> and Copied<I>"The 8472-163/+20
This reverts commit ed5f31ab01d41a01b7206eafdf97b458dc41141a.
2025-05-02docs: alias `limit` to `Iterator::take`, cite `[u8]::utf8_chunks` in ↵Lieselotte-0/+3
`Utf8Chunks`
2025-05-02Rollup merge of #140550 - Amanieu:stabilize_select_unpredictable, ↵Matthias Krüger-3/+1
r=workingjubilee Stabilize `select_unpredictable` FCP completed in tracking issue #133962.
2025-05-01Rollup merge of #140544 - m-ou-se:format-args-const-cleanup, r=fee1-deadGuillaume Gomez-55/+69
Clean up "const" situation in format_args!(). This cleans up the "const" situation in the format_args!() expansion/lowering. Rather than marking the Argument::new_display etc. functions as non-const, this marks the Arguments::new_v1 functions as non-const. Example expansion/lowering of format_args!() in const: ```rust // Error: cannot call non-const formatting macro in constant functions const { fmt::Arguments::new_v1( // Now the error is produced here. &["Hello, ", "!\n"], &[ fmt::Argument::new_display(&world) // The error used to be produced here. ], ) } ```
2025-05-01Rollup merge of #140034 - RalfJung:simd_select_bitmask-padding, r=workingjubileeGuillaume Gomez-3/+1
simd_select_bitmask: the 'padding' bits in the mask are just ignored Fixes https://github.com/rust-lang/rust/issues/137942: we documented simd_select_bitmask to require the 'padding' bits in the mask (the mask can sometimes be longer than the vector; I am referring to these extra bits as 'padding' here) to be zero, mostly because nobody felt like doing the research for what should be done when they are non-zero. However, codegen is already perfectly happy just ignoring them, so in practice they can have any value. Some of the intrinsic wrappers in stdarch have trouble ensuring that they are zero. So let's just adjust the docs and Miri to permit non-zero 'padding' bits. Cc ````@Amanieu```` ````@workingjubilee````
2025-05-01Rollup merge of #139802 - Lee-Janggun:fix-allocate-hyperlink, r=workingjubileeGuillaume Gomez-2/+4
Fix some grammar errors and hyperlinks in doc for `trait Allocator` I was reading the allocator docs and noticed some weird sentences and missing hyperlink, so I fixed them and made this small PR. * "while until either" could also be changed to "for a while until either", but I just deleted "while". * fixed sentence with incorrect "at" and "has/have". * linked [*currently allocated*] similar to other methods. All other hyperlinks are fine.
2025-05-01Rollup merge of #139780 - ongardie:iterator-take-by_ref-example, ↵Guillaume Gomez-0/+18
r=workingjubilee docs: Add example to `Iterator::take` with `by_ref` If you want to logically split an iterator after `n` items, you might first discover `take`. Before this change, you'd find that `take` consumes the iterator, and you'd probably be stuck. The answer involves `by_ref`, but that's hard to discover, especially since `by_ref` is a bit abstract and `Iterator` has many methods. After this change, you'd see the example showing `take` along with `by_ref`, which allows you to continue using the rest of the iterator. `by_ref` had a good example involving `take` already, so this change just duplicates that existing example under `take`.
2025-05-01Rollup merge of #139186 - TDecking:float, r=workingjubileeGuillaume Gomez-47/+15
Refactor `diy_float` The refactor replaces bespoke algorithms with functions already inside the standard library, improving both codegen and readability.
2025-05-01Rollup merge of #138703 - pudongair:master, r=workingjubileeGuillaume Gomez-2/+2
chore: remove redundant words in comment remove redundant words in comment
2025-05-01Stabilize `select_unpredictable`Amanieu d'Antras-3/+1
FCP completed in tracking issue #133962.
2025-05-01Clean up "const" situation in format_args!().Mara Bos-21/+27
Rather than marking the Argument::new_display etc. functions as non-const, this marks the Arguments::new_v1 functions as non-const.
2025-05-01Move core::fmt::Arguments::new_v1* to rt.rs.Mara Bos-36/+44
2025-04-30docs: Specify that common sort functions sort in an ascending directionNatrix-5/+5
2025-04-30Stabilize `#![feature(non_null_from_ref)]`Mathis B-3/+4
2025-04-30Rollup merge of #139624 - m-ou-se:unconst-format-args, r=jhprattMatthias Krüger-1/+8
Don't allow flattened format_args in const. Fixes https://github.com/rust-lang/rust/issues/139136 Fixes https://github.com/rust-lang/rust/issues/139621 We allow `format_args!("a")` in const, but don't allow any format_args with arguments in const, such as `format_args!("{}", arg)`. However, we accidentally allow `format_args!("hello {}", "world")` in const, as it gets flattened to `format_args!("hello world")`. This also applies to panic in const. This wasn't supposed to happen. I added protection against this in the format args flattening code, ~~but I accidentally marked a function as const that shouldn't have been const~~ but this was removed in https://github.com/rust-lang/rust/pull/135139. This is a breaking change. The crater found no breakage, however. This breaks things like: ```rust const _: () = if false { panic!("a {}", "a") }; ``` and ```rust const F: std::fmt::Arguments<'static> = format_args!("a {}", "a"); ```
2025-04-30Rollup merge of #139192 - ↵Matthias Krüger-4/+6
lolbinarycat:docs-wrapping_offset-provenance-139008, r=RalfJung mention provenance in the pointer::wrapping_offset docs fixes https://github.com/rust-lang/rust/issues/139008
2025-04-29mention provenance in the pointer::wrapping_offset docsbinarycat-4/+6
fixes https://github.com/rust-lang/rust/issues/139008
2025-04-29stabilize ptr::swap_nonoverlapping in constRalf Jung-2/+36
2025-04-28Rollup merge of #140391 - DaniPopes:sub-ptr-rename, r=RalfJungChris Denton-12/+13
Rename sub_ptr to offset_from_unsigned in docs There are still a few mentions of `sub_ptr` in comments and doc comments, which were missed in https://github.com/rust-lang/rust/pull/137483.
2025-04-28Rollup merge of #139656 - scottmcm:stabilize-slice-as-chunks, r=dtolnayChris Denton-23/+106
Stabilize `slice_as_chunks` library feature ~~Draft as this needs #139163 to land first.~~ FCP: https://github.com/rust-lang/rust/issues/74985#issuecomment-2769963395 Methods being stabilized are: ```rust impl [T] { const fn as_chunks<const N: usize>(&self) -> (&[[T; N]], &[T]); const fn as_rchunks<const N: usize>(&self) -> (&[T], &[[T; N]]); const unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]]; const fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[T; N]], &mut [T]); const fn as_rchunks_mut<const N: usize>(&mut self) -> (&mut [T], &mut [[T; N]]); const unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]]; } ``` ~~(FCP's not done quite yet, but will in another day if I'm counting right.)~~ FCP Complete: https://github.com/rust-lang/rust/issues/74985#issuecomment-2797951535
2025-04-28Auto merge of #123948 - azhogin:azhogin/async-drop, r=oli-obkbors-324/+92
Async drop codegen Async drop implementation using templated coroutine for async drop glue generation. Scopes changes to generate `async_drop_in_place()` awaits, when async droppable objects are out-of-scope in async context. Implementation details: https://github.com/azhogin/posts/blob/main/async-drop-impl.md New fields in Drop terminator (drop & async_fut). Processing in codegen/miri must validate that those fields are empty (in full version async Drop terminator will be expanded at StateTransform pass or reverted to sync version). Changes in terminator visiting to consider possible new successor (drop field). ResumedAfterDrop messages for panic when coroutine is resumed after it is started to be async drop'ed. Lang item for generated coroutine for async function async_drop_in_place. `async fn async_drop_in_place<T>()::{{closure0}}`. Scopes processing for generate async drop preparations. Async drop is a hidden Yield, so potentially async drops require the same dropline preparation as for Yield terminators. Processing in StateTransform: async drops are expanded into yield-point. Generation of async drop of coroutine itself added. Shims for AsyncDropGlueCtorShim, AsyncDropGlue and FutureDropPoll. ```rust #[lang = "async_drop"] pub trait AsyncDrop { #[allow(async_fn_in_trait)] async fn drop(self: Pin<&mut Self>); } impl Drop for Foo { fn drop(&mut self) { println!("Foo::drop({})", self.my_resource_handle); } } impl AsyncDrop for Foo { async fn drop(self: Pin<&mut Self>) { println!("Foo::async drop({})", self.my_resource_handle); } } ``` First async drop glue implementation re-worked to use the same drop elaboration code as for sync drop. `async_drop_in_place` changed to be `async fn`. So both `async_drop_in_place` ctor and produced coroutine have their lang items (`AsyncDropInPlace`/`AsyncDropInPlacePoll`) and shim instances (`AsyncDropGlueCtorShim`/`AsyncDropGlue`). ``` pub async unsafe fn async_drop_in_place<T: ?Sized>(_to_drop: *mut T) { } ``` AsyncDropGlue shim generation uses `elaborate_drops::elaborate_drop` to produce drop ladder (in the similar way as for sync drop glue) and then `coroutine::StateTransform` to convert function into coroutine poll. AsyncDropGlue coroutine's layout can't be calculated for generic T, it requires known final dropee type to be generated (in StateTransform). So, `templated coroutine` was introduced here (`templated_coroutine_layout(...)` etc). Such approach overrides the first implementation using mixing language-level futures in https://github.com/rust-lang/rust/pull/121801.
2025-04-28Rename sub_ptr to offset_from_unsigned in docsDaniPopes-12/+13
2025-04-28AsyncDrop implementation using shim codegen of ↵Andrew Zhogin-324/+92
async_drop_in_place::{closure}, scoped async drop added.
2025-04-28Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, ↵bors-1/+11
r=jdonszelmann,traviscross Implement a lint for implicit autoref of raw pointer dereference - take 2 *[t-lang nomination comment](https://github.com/rust-lang/rust/pull/123239#issuecomment-2727551097)* This PR aims at implementing a lint for implicit autoref of raw pointer dereference, it is based on #103735 with suggestion and improvements from https://github.com/rust-lang/rust/pull/103735#issuecomment-1370420305. The goal is to catch cases like this, where the user probably doesn't realise it just created a reference. ```rust pub struct Test { data: [u8], } pub fn test_len(t: *const Test) -> usize { unsafe { (*t).data.len() } // this calls <[T]>::len(&self) } ``` Since #103735 already went 2 times through T-lang, where they T-lang ended-up asking for a more restricted version (which is what this PR does), I would prefer this PR to be reviewed first before re-nominating it for T-lang. ---- Compared to the PR it is as based on, this PR adds 3 restrictions on the outer most expression, which must either be: 1. A deref followed by any non-deref place projection (that intermediate deref will typically be auto-inserted) 2. A method call annotated with `#[rustc_no_implicit_refs]`. 3. A deref followed by a `addr_of!` or `addr_of_mut!`. See bottom of post for details. There are several points that are not 100% clear to me when implementing the modifications: - ~~"4. Any number of automatically inserted deref/derefmut calls." I as never able to trigger this. Am I missing something?~~ Fixed - Are "index" and "field" enough? ---- cc `@JakobDegen` `@WaffleLapkin` r? `@RalfJung` try-job: dist-various-1 try-job: dist-various-2
2025-04-28Auto merge of #136316 - GrigorenkoPV:generic_atomic, r=Mark-Simulacrumbors-0/+94
Create `Atomic<T>` type alias (rebase) Rebase of #130543. Additional changes: - Switch from `allow` to `expect` for `private_bounds` on `AtomicPrimitive` - Unhide `AtomicPrimitive::AtomicInner` from docs, because rustdoc shows the definition `pub type Atomic<T> = <T as AtomicPrimitive>::AtomicInner;` and generated links for it. - `NonZero` did not have this issue, because they kept the new alias private before the direction was changed. - Use `Atomic<_>` in more places, including inside `Once`'s `Futex`. This is possible thanks to https://github.com/rust-lang/rust-clippy/pull/14125 The rest will either get moved back to #130543 or #130543 will be closed in favor of this instead. --- * ACP: https://github.com/rust-lang/libs-team/issues/443#event-14293381061 * Tracking issue: #130539
2025-04-28Rollup merge of #140359 - DiuDiu777:str-fix, r=NoratriebChris Denton-2/+2
specify explicit safety guidance for from_utf8_unchecked The PR addresses missing safety guidelines in two APIs by adding explicit text to the cross-linked reference.
2025-04-27Rollup merge of #140297 - shepmaster:cstr-lossy, r=joboetMatthias Krüger-2/+3
Update example to use CStr::to_string_lossy
2025-04-27Rollup merge of #139090 - yotamofek:pr/peekable-next-if-docs, r=tgross35Matthias Krüger-3/+3
fix docs for `Peekable::next_if{_eq}` These seem like copy-paste errors (except `saves the value of` 👉 `retains` which just sounds better to me)
2025-04-27Rollup merge of #139031 - DaniPopes:str-trim-closure, r=tgross35Matthias Krüger-3/+3
Use char::is_whitespace directly in str::trim* Use the method directly instead of wrapping it in a closure.
2025-04-27Rollup merge of #137439 - clarfonthey:c-str-module, r=tgross35Matthias Krüger-1/+1
Stabilise `std::ffi::c_str` This finished FCP in #112134 but never actually got a stabilisation PR. Since the FCP in #120048 recently passed to add the `os_str` module, it would be nice to also merge this too, to ensure that both get added in the next version. Note: The added stability attributes which *somehow* were able to be omitted before (rustc bug?) were added based on the fact that they were added in 302551388b1942bb4216bb5a15d9d55cee3643a8, which ended up in 1.85.0. Closes: https://github.com/rust-lang/rust/issues/112134 r? libs-api
2025-04-27specify explicit safety guidance for from_utf8_uncheckedLemonJ-2/+2
2025-04-27Remove `#[doc(hidden)]` from `AtomicPrimitive::AtomicInner`Pavel Grigorenko-2/+2
2025-04-27name ATOMIC_INIT without unstable aliasChristopher Durham-3/+3
2025-04-27use generic Atomic type where possibleChristopher Durham-3/+3
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
2025-04-27add generic Atomic<T> type aliasChristopher Durham-0/+94
2025-04-26Update example to use `CStr::to_string_lossy`Jake Goulding-2/+3
2025-04-26moved simple test to coretests, introduced more fleshed out doctests for ↵Jonathan Gruner-4/+107
break_ok/continue_ok
2025-04-25Auto merge of #140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgrbors-2/+30
Rollup of 8 pull requests Successful merges: - #137683 (Add a tidy check for GCC submodule version) - #138968 (Update the index of Result to make the summary more comprehensive) - #139572 (docs(std): mention const blocks in const keyword doc page) - #140152 (Unify the format of rustc cli flags) - #140193 (fix ICE in `#[naked]` attribute validation) - #140205 (Tidying up UI tests [2/N]) - #140284 (remove expect() in `unnecessary_transmutes`) - #140290 (rustdoc: fix typo change from equivelent to equivalent) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-25Rollup merge of #138968 - Natural-selection1:update-Result-doc, r=AmanieuMatthias Krüger-2/+30
Update the index of Result to make the summary more comprehensive fix #138966 This PR and #138957 are twin PR r? `@Amanieu`
2025-04-25Rollup merge of #138957 - Natural-selection1:update-Option-doc, r=AmanieuMatthias Krüger-2/+27
Update the index of Option to make the summary more comprehensive fix: #138955 This PR and #138968 are twin PR By the way, this is my first time contributing to rust, and I'm not a native English speaker, so any suggestions—whether about the wording in the docs or the contribution process itself—would be greatly appreciated!
2025-04-25Rollup merge of #137653 - tgross35:deprecate-concat_idents, r=workingjubileeMatthias Krüger-0/+5
Deprecate the unstable `concat_idents!` `concat_idents` has been around unstably for a long time, but there is now a better (but still unstable) way to join identifiers using `${concat(...)}` syntax with `macro_metavar_expr_concat`. This resolves a lot of the problems with `concat_idents` and is on a better track toward stabilization, so there is no need to keep both versions around. `concat_idents!` still has a lot of use in the ecosystem so deprecate it before removing, as discussed in [1]. Link: https://github.com/rust-lang/rust/issues/124225 [1]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Removing.20.60concat_idents.60
2025-04-25Solved suggestionsHegui Dai-2/+2
2025-04-24Deprecate the unstable `concat_idents!`Trevor Gross-0/+5
`concat_idents` has been around unstably for a long time, but there is now a better (but still unstable) way to join identifiers using `${concat(...)}` syntax with `macro_metavar_expr_concat`. This resolves a lot of the problems with `concat_idents` and is on a better track toward stabilization, so there is no need to keep both versions around. `concat_idents!` still has a lot of use in the ecosystem so deprecate it before removing, as discussed in [1]. Link: https://github.com/rust-lang/rust/issues/124225 [1]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Removing.20.60concat_idents.60
2025-04-24implement continue_ok and break_ok for ControlFlowJonathan Gruner-0/+44