Commit graph

17587 commits

Author SHA1 Message Date
Esteban Küber
1f82b45b6a Use #[derive(Default)] instead of manually implementing it 2024-12-23 03:01:29 +00:00
Zalathar
87c2f9a5be Revert "Auto merge of #130766 - clarfonthey:stable-coverage-attribute, r=wesleywiser"
This reverts commit 1d35638dc3, reversing
changes made to f23a80a4c2.
2024-12-23 12:30:37 +11:00
bors
908af5ba4a Auto merge of #134666 - matthiaskrgr:rollup-whe0chp, r=matthiaskrgr
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-23 01:18:40 +00:00
bors
5a14967f7b Auto merge of #131311 - rust-lang:cargo_update, r=clubby789
Weekly `cargo update`

Automation to keep dependencies in `Cargo.lock` current.

The following is the output from `cargo update`:

```txt

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-22 22:29:29 +00:00
Matthias Krüger
c16f00cff6
Rollup merge of #134642 - kpreid:pointerlike-cell, r=compiler-errors
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-22 21:59:27 +01:00
Matthias Krüger
6ade237b6c
Rollup merge of #134583 - Enselic:maybe-uninit-transmute, r=workingjubilee
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-22 21:59:24 +01:00
Matthias Krüger
bd160f11f0
Rollup merge of #130289 - intgr-forks:Permissions-readonly-vs-unix-root, 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-22 21:59:24 +01:00
Mostafa Khaled
5a8d970e4f Fixes safety docs for dyn Any + Send {+ Sync} 2024-12-22 21:38:23 +02:00
Kevin Reid
5c04151c6c 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`.

Also updated UI tests to account for the `isize` implementation changing
error messages.
2024-12-22 11:18:56 -08:00
bors
e108481f74 Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper
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-22 18:49:18 +00:00
Marti Raudsepp
edfdfbe832 docs: Permissions.readonly() also ignores root user special permissions
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-22 20:47:41 +02:00
Kevin Reid
6a43716ada Specify only that duplicates are discarded, not the order. 2024-12-22 08:16:54 -08:00
bors
303e8bd768 Auto merge of #131193 - EFanZh:asserts-vec-len, r=the8472
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-22 16:09:16 +00:00
Scott McMurray
5ba54c9e31 Delete Rvalue::Len
Everything's moved to `PtrMetadata` instead.
2024-12-22 06:12:39 -08:00
Martin Nordholts
2305012e6a docs: transmute<&mut T, &mut MaybeUninit<T>> is unsound when exposed to 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-22 14:21:10 +01:00
Matthias Krüger
7f36ae400c
Rollup merge of #134602 - kpreid:pointerlike-doc, r=tgross35
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-22 09:12:11 +01:00
Alex Saveau
f19ba15a2c
Fix forgetting to save statx availability on success
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21 22:50:08 -08:00
bors
a2bcfae5c5 Auto merge of #134640 - matthiaskrgr:rollup-xlstm3o, r=matthiaskrgr
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-22 05:29:45 +00:00
Kevin Reid
b5e8a5d393 Document collection From and FromIterator impls that drop duplicate keys.
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-21 19:57:42 -08:00
Matthias Krüger
9b4e40dcb8
Rollup merge of #134630 - fifty-six:master, r=workingjubilee
Use `&raw` for `ptr` primitive docs

Fixes the first item in #133024
2024-12-22 03:49:45 +01:00
bors
c1132470a6 Auto merge of #130733 - okaneco:is_ascii, r=scottmcm
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-22 02:44:13 +00:00
github-actions
b4ef16857e cargo update
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-22 00:22:56 +00:00
Alex Saveau
e0a1549e44
Eliminate redundant statx syscalls
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21 15:22:28 -08:00
Matthias Krüger
3aedae24a2
Rollup merge of #134325 - theemathas:is_null-docs, r=RalfJung
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-21 22:16:02 +01:00
Matthias Krüger
51df98ddb0
Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, 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-21 22:16:02 +01:00
Yusuf Bham
466335205f Use &raw for ptr primitive docs 2024-12-21 15:47:44 -05:00
Alex Saveau
73b41fbcfa
Unify fs::copy and io::copy 2024-12-21 12:20:58 -08:00
Chris Denton
1e3ecd5e4d
Windows: Use WriteFile to write to a UTF-8 console 2024-12-21 15:59:56 +00:00
Chris Denton
fdb43ef0c4
Avoid short writes in LineWriter
Also update the tests to avoid testing implementation details.
2024-12-21 15:13:22 +00:00
Tim (Theemathas) Chirananthavat
e6efbb210b Document CTFE behavior of methods that call is_null 2024-12-21 16:32:47 +07:00
Tim (Theemathas) Chirananthavat
93889172bc Correctly document is_null CTFE behavior.
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-21 15:36:16 +07:00
Ralf Jung
526d29865c ptr::copy: fix docs for the overlapping case 2024-12-21 08:34:55 +01:00
Jacob Pratt
cc27e3f08b
Rollup merge of #134593 - kornelski:less-unwrap, r=jhpratt
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-21 01:18:43 -05:00
Jacob Pratt
c682d30337
Rollup merge of #134579 - hkBst:patch-6, r=jhpratt
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-21 01:18:42 -05:00
Jacob Pratt
91320f6eb8
Rollup merge of #134577 - hkBst:patch-5, r=jhpratt
Improve prose around `as_slice` example of Iter
2024-12-21 01:18:41 -05:00
Jacob Pratt
ba4f4f6a4f
Rollup merge of #134576 - hkBst:patch-4, r=jhpratt
Improve prose around basic examples of Iter and IterMut
2024-12-21 01:18:41 -05:00
Kevin Reid
da6616c54f Document PointerLike implementation restrictions. 2024-12-20 20:47:03 -08:00
Kornel
7b42bc0c79
Less unwrap() in documentation 2024-12-21 01:26:47 +00:00
Matthias Krüger
758ad53005
Rollup merge of #123604 - michaelvanstraten:proc_thread_attribute_list, r=ChrisDenton
Abstract `ProcThreadAttributeList` into its own struct

As extensively discussed in issue #114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer.

This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads.

try-job: x86_64-mingw
2024-12-21 01:30:13 +01:00
Matthias Krüger
0b1834d66b
Rollup merge of #134573 - lukas-code:unimpl-dyn-pointerlike, r=compiler-errors
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-20 21:32:33 +01:00
Matthias Krüger
04c804eb46
Rollup merge of #134570 - hkBst:patch-3, r=joboet
remove reference to dangling from slice::Iter

This aligns the comment with reality and with IterMut. Also dangling does not seem to take any arguments.
2024-12-20 21:32:32 +01:00
Matthias Krüger
1a992573e6
Rollup merge of #134560 - RalfJung:miri-thread-spawn, r=jhpratt
mri: add track_caller to thread spawning methods for better backtraces

This is in preparation for https://github.com/rust-lang/miri/pull/4093
2024-12-20 21:32:30 +01:00
Marijn Schouten
07ab203f34
Improve prose around into_slice example of IterMut 2024-12-20 19:57:20 +01:00
Marijn Schouten
3cfe66ab65
Improve prose around as_slice example of Iter 2024-12-20 19:19:34 +01:00
Marijn Schouten
a8e7a6c1d8
Improve prose around basic examples of Iter and IterMut 2024-12-20 18:55:48 +01:00
Marijn Schouten
496adcf36c
remove reference to dangling from slice::Iter
This aligns the comment with reality and with IterMut. Also dangling does not seem to take any arguments.
2024-12-20 18:20:40 +01:00
Lukas Markeffsky
159dba89ef fix PointerLike docs 2024-12-20 17:37:34 +01:00
Lukas Markeffsky
971a4f2d3b unimplement PointerLike for trait objects 2024-12-20 17:35:29 +01:00
Lukas Markeffsky
42c00cb647 split up #[rustc_deny_explicit_impl] attribute
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-20 16:57:14 +01:00
Ralf Jung
8b2b6359f9 mri: add track_caller to thread spawning methods for better backtraces 2024-12-20 15:03:51 +01:00