about summary refs log tree commit diff
path: root/library
AgeCommit message (Collapse)AuthorLines
2024-12-22Fix a bug in `abs_diff`Trevor Gross-2/+2
These were taken from `compiler-builtins` but the implementation has a bug near the integer limits. Fixed in `compiler-builtins` by using `core`'s implementation at [1], this is the corresponding fix for `libm`. [1]: https://github.com/rust-lang/compiler-builtins/pull/736
2024-12-22Fix a bug in `abs_diff`Trevor Gross-6/+2
These implementations of `abs_diff` were added in c2ff1b3119 ("Completely overhaul fuzz testing"), but the signed implementation is wrong when |x| + |y| exceeds the integer's limits (e.g. `(-128).abs_diff(1)` should be 128 but currently these return 127. Resolve this by just using `std`'s implementation since that is stable now. This isn't used anywhere critical, we probably just weren't hitting the edge case.
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-22Rollup merge of #130289 - intgr-forks:Permissions-readonly-vs-unix-root, ↵Matthias Krüger-6/+11
r=ChrisDenton docs: Permissions.readonly() also ignores root user special permissions The root user can write to files without any (write) permission bits set. But this is not taken into account by `std::fs::Permissions.readonly()`. The rustdoc for `readonly()` also mentions shortcomings later: > On Unix-based platforms this checks if any of the owner, group or others write permission bits are set. It does not check if the current user is in the file’s assigned group. It also does not check ACLs. But since this part already clarifies how it works -- it checks write permission bits -- I think it's not necessary to repeat the root user shortcomings here.
2024-12-22Adjust syntaxCaio-21/+280
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-22docs: Permissions.readonly() also ignores root user special permissionsMarti Raudsepp-6/+11
The root user can write to files without any (write) access bits set. But this is not taken into account by `std::fs::Permissions.readonly()`.
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-22Specify only that duplicates are discarded, not the order.Kevin Reid-8/+10
2024-12-22Auto merge of #131193 - EFanZh:asserts-vec-len, r=the8472bors-2/+20
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-22Remove tests against system muslTrevor Gross-501/+12
We now have tests against our custom-built musl as well as tests against MPFR. The tests against system musl covers less than those against custom-built musl, and are less portable; there isn't much benefit to keeping them around so just remove them.
2024-12-22Impl String::into_charstison-2/+185
Signed-off-by: tison <wander4096@gmail.com>
2024-12-22Stabilize `hash_extract_if`Pavel Grigorenko-16/+10
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-21Fix forgetting to save statx availability on successAlex Saveau-1/+5
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
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-21Document collection `From` and `FromIterator` impls that drop duplicate keys.Kevin Reid-1/+25
This behavior is worth documenting because there are other plausible alternatives, such as panicking when a duplicate is encountered, and it reminds the programmer to consider whether they should, for example, coalesce duplicate keys first.
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-15/+102
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-22cargo updategithub-actions-2/+2
compiler & tools dependencies: Locking 15 packages to latest compatible versions Updating clap_complete v4.5.39 -> v4.5.40 Updating env_filter v0.1.2 -> v0.1.3 Updating env_logger v0.11.5 -> v0.11.6 Updating expect-test v1.5.0 -> v1.5.1 Updating foldhash v0.1.3 -> v0.1.4 Updating miniz_oxide v0.8.1 -> v0.8.2 Updating object v0.36.5 -> v0.36.7 Updating serde_json v1.0.133 -> v1.0.134 Updating thiserror v2.0.7 -> v2.0.9 Updating thiserror-impl v2.0.7 -> v2.0.9 Updating tinyvec v1.8.0 -> v1.8.1 Updating wasm-encoder v0.221.2 -> v0.222.0 Removing wasmparser v0.218.0 Removing wasmparser v0.221.2 Adding wasmparser v0.222.0 Updating wast v221.0.2 -> v222.0.0 Updating wat v1.221.2 -> v1.222.0 note: pass `--verbose` to see 35 unchanged dependencies behind latest library dependencies: Locking 1 package to latest compatible version Updating object v0.36.5 -> v0.36.7 note: pass `--verbose` to see 6 unchanged dependencies behind latest rustbook dependencies: Locking 9 packages to latest compatible versions Updating cc v1.2.0 -> v1.2.5 Updating clap_complete v4.5.39 -> v4.5.40 Updating env_filter v0.1.2 -> v0.1.3 Updating env_logger v0.11.5 -> v0.11.6 Updating libc v0.2.168 -> v0.2.169 Updating miniz_oxide v0.8.1 -> v0.8.2 Updating serde_json v1.0.133 -> v1.0.134 Updating thiserror v2.0.7 -> v2.0.9 Updating thiserror-impl v2.0.7 -> v2.0.9
2024-12-21Eliminate redundant statx syscallsAlex Saveau-9/+64
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
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-21Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, ↵Matthias Krüger-4/+199
r=ChrisDenton Win: Use POSIX rename semantics for `std::fs::rename` if available Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming and renaming if the target file is has already been opened with `FILE_SHARE_DELETE`, in which case the file gets renamed on disk while the open file handle still refers to the old file, just like in POSIX. This resolves #123985, where atomic renaming proved difficult to impossible due to race conditions. If `FileRenameInfoEx` isn't available due to missing support from the underlying filesystem or missing OS support, the renaming is retried with `FileRenameInfo`, which matches the behavior of `MoveFileEx`. This PR also manually replicates parts of `MoveFileEx`'s internal logic, as reverse-engineered from the disassembly: If the source file is a reparse point and said reparse point is a mount point, the mount point itself gets renamed; otherwise the reparse point is resolved and the result renamed. Notes: - Currently, the `win7` target doesn't bother with `FileRenameInfoEx` at all; it's probably desirable to remove that special casing and try `FileRenameInfoEx` anyway if it doesn't exist, in case the binary is run on newer OS versions. Fixes #123985
2024-12-21Use `&raw` for `ptr` primitive docsYusuf Bham-5/+5
2024-12-21Unify fs::copy and io::copyAlex Saveau-19/+1
2024-12-21Windows: Use WriteFile to write to a UTF-8 consoleChris Denton-1/+26
2024-12-21Avoid short writes in LineWriterChris Denton-6/+21
Also update the tests to avoid testing implementation details.
2024-12-21Fix `_mm*_mask_cmp_ep*_mask` bug with `IMM3=7`sayantn-24/+24
2024-12-21Fix Wasm `f*_sqrt()` docdaxpedda-2/+2
2024-12-21Disable `armv7-unknown-linux-gnueabihf` `dox.sh` CI temporarilysayantn-1/+3
2024-12-21Make `assert_instr` strictersayantn-4/+9
2024-12-21Refactor `dox.sh`, add `loongarch64` and `nvptx64`sayantn-36/+23
2024-12-21Upgrade Intel SDEsayantn-6/+6
2024-12-21Add PowerPC (32-bit) to CIsayantn-0/+6
2024-12-21Remove `gba.json` as it was unusedsayantn-34/+0
2024-12-21Re-enable the disabled PPC tests, Upgrade CPUsayantn-8/+4
2024-12-21Enable `x86_64-pc-windows-msvc-dev`Sayantan Chakraborty-5/+0
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-50/+76
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