about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-12-26Impl FromIterator for tuples with arity 1-12Sebastian Hahn-33/+35
2024-12-26Fix formattingSebastian Hahn-19/+19
2024-12-26docs: update code example for Iterator#rpositionwtlin1228-0/+1
2024-12-25stabilize const_alloc_layoutRalf Jung-10/+5
2024-12-25rename typed_swap → typed_swap_nonoverlappingRalf Jung-3/+18
2024-12-25stabilize const_swapRalf Jung-8/+7
2024-12-24chore: fix typosoliveredget-3/+3
2024-12-24Rollup merge of #134689 - RalfJung:ptr-swap-test, r=oli-obkStuart Cook-38/+49
core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets Ensure that the pointer gets swapped correctly even if it is not stored at an aligned offset. This rules out implementations that copy things in a `usize` loop -- so our implementation needs to be adjusted to avoid such a loop when running in const context. Part of https://github.com/rust-lang/rust/issues/133668
2024-12-24Rollup merge of #134662 - ionicmc-rs:any-safety-docs, r=AmanieuStuart Cook-2/+12
Fix safety docs for `dyn Any + Send {+ Sync}` Fixes the `# Safety` docs for `dyn Any + Send`'s `downcast_{mut/ref}_unchecked` to show the direct instructions , where previously the would tell the user to find the docs on `dyn Any` themselves. This also adds them for `downcast_{mut/ref}_unchecked` on `dyn Any + Send + Sync`
2024-12-23core: fix const ptr::swap_nonoverlapping when there are pointers at odd ↵Ralf Jung-38/+49
offsets in the type
2024-12-23Rollup merge of #134672 - Zalathar:revert-coverage-attr, r=wesleywiserTrevor Gross-6/+4
Revert stabilization of the `#[coverage(..)]` attribute Due to a process mixup, the PR to stabilize the `#[coverage(..)]` attribute (#130766) was merged while there are still outstanding concerns. The default action in that situation is to revert, and the feature is not sufficiently urgent or uncontroversial to justify special treatment, so this PR reverts that stabilization. --- - A key point that came up in offline discussions is that unlike most user-facing features, this one never had a proper RFC, so parts of the normal stabilization process that implicitly rely on an RFC break down in this case. - As the implementor and de-facto owner of the feature in its current form, I would like to think that I made good choices in designing and implementing it, but I don't feel comfortable proceeding to stabilization without further scrutiny. - There hasn't been a clear opportunity for T-compiler to weigh in or express concerns prior to stabilization. - The stabilization PR cites a T-lang FCP that occurred in the tracking issue, but due to the messy design and implementation history (and lack of a clear RFC), it's unclear what that FCP approval actually represents in this case. - At the very least, we should not proceed without a clear statement from T-lang or the relevant members about the team's stance on this feature, especially in light of the other concerns listed here. - The existing user-facing documentation doesn't clearly reflect which parts of the feature are stable commitments, and which parts are subject to change. And there doesn't appear to be a clear consensus anywhere about where that line is actually drawn, or whether the chosen boundary is acceptable to the relevant teams and individuals. - For example, the [stabilization report comment](https://github.com/rust-lang/rust/issues/84605#issuecomment-2166514660) mentions that some aspects are subject to change, but that text isn't consistent with my earlier comments, and there doesn't appear to have been any explicit discussion or approval process. - [The current reference text](https://github.com/rust-lang/reference/blob/4dfaa4f/src/attributes/coverage-instrumentation.md) doesn't mention this distinction at all, and instead simply describes the current implementation behaviour. - When the implementation was changed to its current form, the associated user-facing error messages were not updated, so they still refer to the attribute only being allowed on functions and closures. - On its own, this might have been reasonable to fix-forward in the absence of other concerns, but the fact that it never came up earlier highlights the breakdown in process that has occurred here. --- Apologies to everyone who was excited for this stabilization to land, but unfortunately it simply isn't ready yet.
2024-12-23Revert "Auto merge of #130766 - clarfonthey:stable-coverage-attribute, ↵Zalathar-6/+4
r=wesleywiser" This reverts commit 1d35638dc38dbfbf1cc2a9823135dfcf3c650169, reversing changes made to f23a80a4c2fbca593b64e70f5970368824b4c5e9.
2024-12-23Auto merge of #134666 - matthiaskrgr:rollup-whe0chp, r=matthiaskrgrbors-1/+35
Rollup of 6 pull requests Successful merges: - #130289 (docs: Permissions.readonly() also ignores root user special permissions) - #134583 (docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to safe code) - #134611 (Align `{i686,x86_64}-win7-windows-msvc` to their parent targets) - #134629 (compiletest: Allow using a specific debugger when running debuginfo tests) - #134642 (Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and `SyncUnsafeCell`.) - #134660 (Fix spacing of markdown code block fences in compiler rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-22Rollup merge of #134642 - kpreid:pointerlike-cell, r=compiler-errorsMatthias Krüger-1/+15
Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and `SyncUnsafeCell`. * Implementing `PointerLike` for `UnsafeCell` enables the possibility of interior mutable `dyn*` values. Since this means potentially exercising new codegen behavior, I added a test for it in `tests/ui/dyn-star/cell.rs`. Please let me know if there are further sorts of tests that should be written, or other care that should be taken with this change. It is unfortunately not possible without compiler changes to implement `PointerLike` for `Atomic*` types, since they are not `repr(transparent)` (and, in theory if not in practice, `AtomicUsize`'s alignment may be greater than that of an ordinary pointer or `usize`). * Implementing `PointerLike` for `NonNull` is useful for pointer types which wrap `NonNull`. * Implementing `PointerLike` for `isize` is just for completeness; I have no use cases in mind, but I cannot think of any reason not to do this. * Tracking issue: #102425 `@rustbot` label +F-dyn_star (there is no label or tracking issue for F-pointer_like_trait)
2024-12-22Rollup merge of #134583 - Enselic:maybe-uninit-transmute, r=workingjubileeMatthias Krüger-0/+20
docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to safe code Closes #66699 On my system (Edit: And also in the [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=90529e2a9900599cb759e4bfaa5b5efe)) the example program terminates with an unpredictable exit code: ```console $ cargo +nightly build && target/debug/bin ; echo $? 255 $ cargo +nightly build && target/debug/bin ; echo $? 253 ``` And miri considers the code to have undefined behavior: ```console $ cargo +nightly miri run error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory --> src/main.rs:12:24 | 12 | std::process::exit(*code); // UB! Accessing uninitialized memory | ^^^^^ using uninitialized data, but this operation requires initialized memory | error: aborting due to 1 previous error ```
2024-12-22Adjust syntaxCaio-0/+52
2024-12-22Fixes safety docs for `dyn Any + Send {+ Sync}`Mostafa Khaled-2/+12
2024-12-22Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and ↵Kevin Reid-1/+15
`SyncUnsafeCell`. Implementing `PointerLike` for `UnsafeCell` enables the possibility of interior mutable `dyn*` values. Since this means potentially exercising new codegen behavior, I added a test for it in `tests/ui/dyn-star/cell.rs`. Also updated UI tests to account for the `isize` implementation changing error messages.
2024-12-22Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasperbors-2/+1
Delete `Rvalue::Len` 🎉 Everything's moved to `PtrMetadata`, so we can get rid of the `Len` variant now. ~~Depends on #134326, so draft until that lands~~ Ready! r? mir
2024-12-22Improve prose around `as_slice` example of IterMutMarijn Schouten-22/+20
I've removed the cryptic message about not being able to call `&mut self` methods while retaining a shared borrow of the iterator, such as `as_slice` produces. This is just normal borrowing rules and does not seem especially relevant here. I can whip up a replacement if someone thinks it has value.
2024-12-22Auto merge of #131193 - EFanZh:asserts-vec-len, r=the8472bors-0/+11
Asserts the maximum value that can be returned from `Vec::len` Currently, casting `Vec<i32>` to `Vec<u32>` takes O(1) time: ```rust // See <https://godbolt.org/z/hxq3hnYKG> for assembly output. pub fn cast(vec: Vec<i32>) -> Vec<u32> { vec.into_iter().map(|e| e as _).collect() } ``` But the generated assembly is not the same as the identity function, which prevents us from casting `Vec<Vec<i32>>` to `Vec<Vec<u32>>` within O(1) time: ```rust // See <https://godbolt.org/z/7n48bxd9f> for assembly output. pub fn cast(vec: Vec<Vec<i32>>) -> Vec<Vec<u32>> { vec.into_iter() .map(|e| e.into_iter().map(|e| e as _).collect()) .collect() } ``` This change tries to fix the problem. You can see the comparison here: <https://godbolt.org/z/jdManrKvx>.
2024-12-22Delete `Rvalue::Len`Scott McMurray-2/+1
Everything's moved to `PtrMetadata` instead.
2024-12-22docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to ↵Martin Nordholts-0/+20
safe code In the playground the example program terminates with an unpredictable exit code. The undefined behavior is also detected by miri: error: Undefined Behavior: using uninitialized data
2024-12-22Rollup merge of #134602 - kpreid:pointerlike-doc, r=tgross35Matthias Krüger-2/+8
Document `PointerLike` implementation restrictions. Since <https://github.com/rust-lang/rust/pull/133226>, it is no longer automatically implemented, but must be manually implemented, with special restrictions. The documentation now (roughly) explains those special restrictions. cc `@compiler-errors` (author of the previous PR)
2024-12-22Auto merge of #134640 - matthiaskrgr:rollup-xlstm3o, r=matthiaskrgrbors-5/+5
Rollup of 6 pull requests Successful merges: - #134364 (Use E0665 for missing `#[default]` on enum and update doc) - #134601 (Support pretty-printing `dyn*` trait objects) - #134603 (Explain why a type is not eligible for `impl PointerLike`.) - #134618 (coroutine_clone: add comments) - #134630 (Use `&raw` for `ptr` primitive docs) - #134637 (Flatten effects directory now that it doesn't really test anything specific) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-22Rollup merge of #134630 - fifty-six:master, r=workingjubileeMatthias Krüger-5/+5
Use `&raw` for `ptr` primitive docs Fixes the first item in #133024
2024-12-22Auto merge of #130733 - okaneco:is_ascii, r=scottmcmbors-12/+58
Optimize `is_ascii` for `str` and `[u8]` further Replace the existing optimized function with one that enables auto-vectorization. This is especially beneficial on x86-64 as `pmovmskb` can be emitted with careful structuring of the code. The instruction can detect non-ASCII characters one vector register width at a time instead of the current `usize` at a time check. The resulting implementation is completely safe. `case00_libcore` is the current implementation, `case04_while_loop` is this PR. ``` benchmarks: ascii::is_ascii_slice::long::case00_libcore 22.25/iter +/- 1.09 ascii::is_ascii_slice::long::case04_while_loop 6.78/iter +/- 0.92 ascii::is_ascii_slice::medium::case00_libcore 2.81/iter +/- 0.39 ascii::is_ascii_slice::medium::case04_while_loop 1.56/iter +/- 0.78 ascii::is_ascii_slice::short::case00_libcore 5.55/iter +/- 0.85 ascii::is_ascii_slice::short::case04_while_loop 3.75/iter +/- 0.22 ascii::is_ascii_slice::unaligned_both_long::case00_libcore 26.59/iter +/- 0.66 ascii::is_ascii_slice::unaligned_both_long::case04_while_loop 5.78/iter +/- 0.16 ascii::is_ascii_slice::unaligned_both_medium::case00_libcore 2.97/iter +/- 0.32 ascii::is_ascii_slice::unaligned_both_medium::case04_while_loop 2.41/iter +/- 0.10 ascii::is_ascii_slice::unaligned_head_long::case00_libcore 23.71/iter +/- 0.79 ascii::is_ascii_slice::unaligned_head_long::case04_while_loop 7.83/iter +/- 1.31 ascii::is_ascii_slice::unaligned_head_medium::case00_libcore 3.69/iter +/- 0.54 ascii::is_ascii_slice::unaligned_head_medium::case04_while_loop 7.05/iter +/- 0.32 ascii::is_ascii_slice::unaligned_tail_long::case00_libcore 24.44/iter +/- 1.41 ascii::is_ascii_slice::unaligned_tail_long::case04_while_loop 5.12/iter +/- 0.18 ascii::is_ascii_slice::unaligned_tail_medium::case00_libcore 3.24/iter +/- 0.40 ascii::is_ascii_slice::unaligned_tail_medium::case04_while_loop 2.86/iter +/- 0.14 ``` `unaligned_head_medium` is the main regression in the benchmarks. It is a 32 byte string being sliced `bytes[1..]`. The first commit can be used to run the benchmarks against the current core implementation. Previous implementation was done in #74066 --- Two potential drawbacks of this implementation are that it increases instruction count and may regress other platforms/architectures. The benches here may also be too artificial to glean much insight from. https://rust.godbolt.org/z/G9znGfY36
2024-12-21Rollup merge of #134325 - theemathas:is_null-docs, r=RalfJungMatthias Krüger-14/+89
Correctly document CTFE behavior of is_null and methods that call is_null. The "panic in const if CTFE doesn't know the answer" behavior was discussed to be the desired behavior in #74939, and is currently how the function actually behaves. I intentionally wrote this documentation to allow for the possibility that a panic might not occur even if the pointer is out of bounds, because of #133700 and other potential changes in the future. This is beta-nominated since `const fn is_null` stabilization is in beta already but the docs there are wrong, and it seems better to have the docs be correct at the time of stabilization.
2024-12-21Use `&raw` for `ptr` primitive docsYusuf Bham-5/+5
2024-12-21Document CTFE behavior of methods that call is_nullTim (Theemathas) Chirananthavat-0/+69
2024-12-21Correctly document is_null CTFE behavior.Tim (Theemathas) Chirananthavat-16/+22
The "panic in const if CTFE doesn't know the answer" behavior was discussed to be the desired behavior in #74939, and is currently how the function actually behaves. I intentionally wrote this documentation to allow for the possibility that a panic might not occur even if the pointer is out of bounds, because of #133700 and other potential changes in the future.
2024-12-21ptr::copy: fix docs for the overlapping caseRalf Jung-5/+3
2024-12-21Rollup merge of #134593 - kornelski:less-unwrap, r=jhprattJacob Pratt-24/+45
Less unwrap() in documentation I think the common use of `.unwrap()` in examples makes it overrepresented, looking like a more typical way of error handling than it really is in real programs. Therefore, this PR changes a bunch of examples to use different error handling methods, primarily the `?` operator. Additionally, `unwrap()` docs warn that it might abort the program.
2024-12-21Rollup merge of #134579 - hkBst:patch-6, r=jhprattJacob Pratt-20/+13
Improve prose around into_slice example of IterMut Having a part without modification and one with seems redundant, since `into_slice` is only called for the part without. I have brought the modification into the remaining part, although it perhaps does not add much (or only distracts?).
2024-12-21Rollup merge of #134577 - hkBst:patch-5, r=jhprattJacob Pratt-5/+11
Improve prose around `as_slice` example of Iter
2024-12-21Rollup merge of #134576 - hkBst:patch-4, r=jhprattJacob Pratt-6/+12
Improve prose around basic examples of Iter and IterMut
2024-12-20Document `PointerLike` implementation restrictions.Kevin Reid-2/+8
2024-12-21Less unwrap() in documentationKornel-24/+45
2024-12-20Rollup merge of #134573 - lukas-code:unimpl-dyn-pointerlike, r=compiler-errorsMatthias Krüger-11/+30
unimplement `PointerLike` for trait objects Values of type `dyn* PointerLike` or `dyn PointerLike` are not pointer-like so these types should not implement `PointerLike`. After https://github.com/rust-lang/rust/pull/133226, `PointerLike` allows user implementations, so we can't just mark it with `#[rustc_deny_explicit_impl(implement_via_object = false)]`. Instead, this PR splits the `#[rustc_deny_explicit_impl(implement_via_object = ...)]` attribute into two separate attributes `#[rustc_deny_explicit_impl]` and `#[rustc_do_not_implement_via_object]` so that we opt out of the automatic `impl PointerLike for dyn PointerLike` and still allow user implementations. For traits that are marked with `#[do_not_implement_via_object]` but not `#[rustc_deny_explicit_impl]` I've also made it possible to add a manual `impl Trait for dyn Trait`. There is no immediate need for this, but it was one line to implement and seems nice to have. fixes https://github.com/rust-lang/rust/issues/134545 fixes https://github.com/rust-lang/rust/issues/134543 r? `@compiler-errors`
2024-12-20Improve prose around into_slice example of IterMutMarijn Schouten-20/+13
2024-12-20Improve prose around `as_slice` example of IterMarijn Schouten-5/+11
2024-12-20Improve prose around basic examples of Iter and IterMutMarijn Schouten-6/+12
2024-12-20remove reference to dangling from slice::IterMarijn Schouten-1/+1
This aligns the comment with reality and with IterMut. Also dangling does not seem to take any arguments.
2024-12-20fix `PointerLike` docsLukas Markeffsky-2/+2
2024-12-20unimplement `PointerLike` for trait objectsLukas Markeffsky-0/+1
2024-12-20split up `#[rustc_deny_explicit_impl]` attributeLukas Markeffsky-9/+27
This commit splits the `#[rustc_deny_explicit_impl(implement_via_object = ...)]` attribute into two attributes `#[rustc_deny_explicit_impl]` and `#[rustc_do_not_implement_via_object]`. This allows us to have special traits that can have user-defined impls but do not have the automatic trait impl for trait objects (`impl Trait for dyn Trait`).
2024-12-20Rollup merge of #134518 - hltj:typo-fix, r=tgross35Jacob Pratt-3/+3
fix typos in the example code in the doc comments of `Ipv4Addr::from_bits()`, `Ipv6Addr::from_bits()` & `Ipv6Addr::to_bits()`
2024-12-20Rollup merge of #132830 - wr7:substr_range_documentation, r=tgross35Jacob Pratt-7/+8
Rename `elem_offset` to `element_offset` Tracking issue: #126769 Renames `slice::elem_offset` to `slice::element_offset` and improves the documentation of it and its related methods. The current documentation can be misinterpreted (as explained [here](https://github.com/rust-lang/rust/issues/126769#issuecomment-2453363897)).
2024-12-20fix typos in the example code in the doc comments of ↵hltj-3/+3
`Ipv4Addr::from_bits()`, `Ipv6Addr::from_bits()` & `Ipv6Addr::to_bits()`
2024-12-18Rollup merge of #134490 - hong9lol:typo, r=jhprattJacob Pratt-1/+1
Fix typo in ptr/mod.rs - Type: Document - Description: I found a typo and want to fix it.