Commit Graph

15439 Commits

Author SHA1 Message Date
bors 44fb8575de Auto merge of #127674 - jhpratt:rollup-0dxy3k7, r=jhpratt
Rollup of 3 pull requests

Successful merges:

 - #127654 (Fix incorrect NDEBUG handling in LLVM bindings)
 - #127661 (Stabilize io_slice_advance)
 - #127668 (Improved slice documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-13 06:05:25 +00:00
Jacob Pratt f0119130de
Rollup merge of #127668 - spencer3035:improve-slice-doc, r=jhpratt
Improved slice documentation

Improve slice documentation to include assert_eq checks for all the cases where there were existing examples. I think it makes things more clear when the documentation explicitly checks against values and shows the reader what it does.

I also started a rust internals discussion about it here: https://internals.rust-lang.org/t/improve-slice-documentaion/21168
2024-07-13 00:24:36 -04:00
Jacob Pratt 68ec9c1992
Rollup merge of #127661 - eduardosm:stabilize-io_slice_advance, r=cuviper
Stabilize io_slice_advance

Closes https://github.com/rust-lang/rust/issues/62726 (FCP completed)

Stabilized API:

```rust
impl<'a> IoSlice<'a> {
    pub fn advance(&mut self, n: usize);
    pub fn advance_slices(bufs: &mut &mut [IoSlice<'a>], n: usize);
}

impl<'a> IoSliceMut<'a> {
    pub fn advance(&mut self, n: usize);
    pub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize);
}
```
2024-07-13 00:24:35 -04:00
bors 0065384608 Auto merge of #127397 - jyn514:multi-thread-panic-hook, r=workingjubilee
fix interleaved output in the default panic hook when multiple threads panic simultaneously

previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook from one thread would be interleaved with the backtrace from another. now, we hold the lock for the full duration of the hook, and the output is ordered.

---

i noticed some odd things while working on this you may or may not already be aware of.

- libbacktrace is included as a submodule instead of a normal rustc crate, and as a result uses `cfg(backtrace_in_std)` instead of a more normal `cfg(feature = "rustc-dep-of-std")`. probably this is left over from before rust used a cargo-based build system?
- the default panic handler uses `trace_unsynchronized`, etc, in `sys::backtrace::print`. as a result, the lock only applies to concurrent *panic handlers*, not concurrent *threads*.  in other words, if another, non-panicking, thread tried to print a backtrace at the same time as the panic handler, we may have UB, especially on windows.
    - we have the option of changing backtrace to enable locking when `backtrace_in_std` is set so we can reuse their lock instead of trying to add our own.
2024-07-13 03:42:24 +00:00
bors 03c2100ded Auto merge of #126606 - zachs18:patch-2, r=joboet
Guard against calling `libc::exit` multiple times on Linux.

Mitigates (but does not fix) #126600 by ensuring only one thread which calls Rust `exit` actually calls `libc::exit`, and all other callers of Rust `exit` block.
2024-07-13 01:18:59 +00:00
Spencer 163d98b2ea Updated slice documentation 2024-07-12 18:09:44 -06:00
Eduardo Sánchez Muñoz a45c12cf0f Stabilize io_slice_advance 2024-07-12 20:09:29 +02:00
Trevor Gross 2772f89797 Rename the internal `const_strlen` to just `strlen`
Since the libs and lang teams completed an FCP to allow for const
`strlen` ([1]), currently implemented with `const_eval_select`, there is
no longer any reason to avoid this specific function or use it only in
const.

Rename it to reflect this status change.

[1]: https://github.com/rust-lang/rust/issues/113219#issuecomment-2016939401
2024-07-12 13:53:58 -04:00
jyn 1c8f9bb84d fix interleaved panic output
previously, we only held a lock for printing the backtrace itself. since all threads were printing to the same file descriptor, that meant random output in the default panic hook would be interleaved with the backtrace. now, we hold the lock for the full duration of the hook, and the output is ordered.
2024-07-12 11:52:04 -04:00
Matthias Krüger 8ceb4e49ff
Rollup merge of #127433 - dtolnay:conststrlen, r=workingjubilee
Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes)

Completed the pair of FCPs https://github.com/rust-lang/rust/issues/113219#issuecomment-2016939401 + https://github.com/rust-lang/rust/issues/114441#issuecomment-2016942566.

`CStr::from_ptr` is covered by just the first FCP on its own. `CStr::count_bytes` requires the approval of both FCPs. The second paragraph of the first link and the last paragraph of the second link explain the relationship between the two FCPs. As both have been approved, we can proceed with stabilizing `const` on both of these already-stable functions.
2024-07-12 14:37:58 +02:00
Matthias Krüger f9b3e8b387
Rollup merge of #126827 - the8472:pidfd-spawn, r=workingjubilee
Use pidfd_spawn for faster process spawning when a PidFd is requested

glibc 2.39 added `pidfd_spawnp` and `pidfd_getpid` which makes it possible to get pidfds while staying on the CLONE_VFORK path.

verified that vfork gets used with strace:

```
$  strace -ff -e pidfd_open,clone3,openat,execve,waitid,close ./x test std --no-doc -- pidfd
[...]
[pid 2820532] clone3({flags=CLONE_VM|CLONE_PIDFD|CLONE_VFORK|CLONE_CLEAR_SIGHAND, pidfd=0x7b7f885fec6c, exit_signal=SIGCHLD, stack=0x7b7f88aff000, stack_size=0x9000}strace: Process 2820533 attached
 <unfinished ...>
[pid 2820533] execve("/home/the8472/bin/sleep", ["sleep", "1000"], 0x7ffdd0e268d8 /* 107 vars */) = -1 ENOENT (No such file or directory)
[pid 2820533] execve("/home/the8472/.cargo/bin/sleep", ["sleep", "1000"], 0x7ffdd0e268d8 /* 107 vars */) = -1 ENOENT (No such file or directory)
[pid 2820533] execve("/usr/local/bin/sleep", ["sleep", "1000"], 0x7ffdd0e268d8 /* 107 vars */) = -1 ENOENT (No such file or directory)
[pid 2820533] execve("/usr/bin/sleep", ["sleep", "1000"], 0x7ffdd0e268d8 /* 107 vars */ <unfinished ...>
[pid 2820532] <... clone3 resumed> => {pidfd=[3]}, 88) = 2820533
[pid 2820533] <... execve resumed>)     = 0
[pid 2820532] openat(AT_FDCWD, "/proc/self/fdinfo/3", O_RDONLY|O_CLOEXEC) = 4
[pid 2820532] close(4)                  = 0
```

Tracking issue: #82971
2024-07-12 14:37:58 +02:00
Matthias Krüger 65ea92d4a1
Rollup merge of #124980 - zachs18:rc-allocator, r=Amanieu
Generalize `fn allocator` for Rc/Arc.

Split out from #119761

- For `Rc`/`Arc`, the existing associated `fn`s are changed to allow unsized pointees.
 - For `Weak`s, new methods are added.

`````@rustbot````` label +A-allocators
2024-07-12 14:37:56 +02:00
David Tolnay 7f1518bddd
Add instability attribute on private const_strlen function
A `rustc_const_stable` attribute by itself has nonintuitive purpose when
placed in a public module.

Separately, it would probably be okay to rename `const_strlen` to just
`strlen` to make it more clear this is our general-purpose
implementation of strlen now, not something specifically for const
(avoiding confusion like in PR 127444).
2024-07-11 20:57:37 -07:00
Matthias Krüger 1e7ad4c3ed
Rollup merge of #127422 - greaka:master, r=workingjubilee
as_simd: fix doc comment to be in line with align_to

In #121201, the guarantees about `align_offset` and `align_to` were changed. This PR aims to correct the doc comment of `as_simd` to be in line with the new `align_to`.

Tagging #86656 for good measure.
2024-07-12 03:43:34 +02:00
Matthias Krüger 47ab86653e
Rollup merge of #127599 - tgross35:lazy_cell_consume-rename, r=workingjubilee
Rename `lazy_cell_consume` to `lazy_cell_into_inner`

Name this something that is less confusable with an atomic consume API for `{Lazy,Once}Lock`.
2024-07-11 17:01:39 +02:00
Matthias Krüger 380c78741e
Rollup merge of #127588 - uweigand:s390x-f16-doctests, r=tgross35
core: Limit remaining f16 doctests to x86_64 linux

On s390x, every use of the f16 data type will currently ICE due to https://github.com/llvm/llvm-project/issues/50374, causing doctest failures on the platform.

Most doctests were already restricted to certain platforms, so fix this by likewise restricting the remaining five.
2024-07-11 17:01:37 +02:00
Matthias Krüger 6fd955549a
Rollup merge of #127572 - tbu-:pr_debug_event_nonpacked, r=jhpratt
Don't mark `DEBUG_EVENT` struct as `repr(packed)`

That would give it alignment of 1 which is ABI-incompatible with its C definition.
2024-07-11 17:01:37 +02:00
Matthias Krüger 8de487fdbd
Rollup merge of #124599 - estebank:issue-41708, r=wesleywiser
Suggest borrowing on fn argument that is `impl AsRef`

When encountering a move conflict, on an expression that is `!Copy` passed as an argument to an `fn` that is `impl AsRef`, suggest borrowing the expression.

```
error[E0382]: use of moved value: `bar`
  --> f204.rs:14:15
   |
12 |     let bar = Bar;
   |         --- move occurs because `bar` has type `Bar`, which does not implement the `Copy` trait
13 |     foo(bar);
   |         --- value moved here
14 |     let baa = bar;
   |               ^^^ value used here after move
   |
help: borrow the value to avoid moving it
   |
13 |     foo(&bar);
   |         +
```

Fix #41708
2024-07-11 17:01:36 +02:00
Trevor Gross ab56fe2053 Rename `lazy_cell_consume` to `lazy_cell_into_inner`
Name this something that is less confusable with an atomic consume API for
`{Lazy,Once}Lock`.
2024-07-11 03:16:45 -04:00
Ulrich Weigand 0065763950 core: Limit remaining f16 doctests to x86_64 linux
On s390x, every use of the f16 data type will currently ICE
due to https://github.com/llvm/llvm-project/issues/50374,
causing doctest failures on the platform.

Most doctests were already restricted to certain platforms,
so fix this by likewise restricting the remaining five.
2024-07-10 23:21:57 +02:00
Matthias Krüger aae262cafa
Rollup merge of #127554 - ferrocene:tshepang-add-missing-attribute, r=pietroalbini
do not run test where it cannot run

This was seen on Ferrocene, where we have a custom test target that does not have unwind support
2024-07-10 17:54:26 +02:00
Tobias Bucher 45ad522e87 Don't mark `DEBUG_EVENT` struct as `repr(packed)`
That would give it alignment of 1 which is ABI-incompatible with its C
definition.
2024-07-10 15:47:24 +02:00
bors d81987661a Auto merge of #126690 - andyolivares:feature/show_window, r=dtolnay
Exposing STARTUPINFOW.wShowWindow in CommandExt trait

Hi:

I needed a way to control how a new process's window is displayed in Windows (normal, minimized, maximized, etc).
I noticed that there is no direct way to do that (I even searched for crates doing this, but didn't find any).

Inspecting the standard library source code, I figured that it would be a good addition to CommandExt trait that allows some Windows specific customization to a Command.

This is my first time contributing to Rust, so please bear with me if I'm not following the rules :)
2024-07-10 11:09:31 +00:00
Jacob Pratt e71d3d5238
Rollup merge of #127091 - Sky9x:fused-error-sources-iter, r=dtolnay
impl FusedIterator and a size hint for the error sources iter

cc tracking issue #58520
2024-07-10 00:37:11 -04:00
Andres Olivares b8b6d14de9 Fixed doc links 2024-07-09 22:09:13 -04:00
Andres Olivares e82ad2e622 Few changes to doc comments. Added tracking issue number. 2024-07-09 22:09:13 -04:00
Andres Olivares 06d76c3156 Exposing STARTUPINFOW.wShowWindow in CommandExt (show_window function) to control how a new process should display its window (normal, minimized, maximized, etc) 2024-07-09 22:09:13 -04:00
Tshepang Mbambo af3aa36d60
do not run test where it cannot run
This was seen on Ferrocene, where we have a custom test target that does not have unwind support
2024-07-10 01:00:55 +02:00
bors 32e692681e Auto merge of #127235 - martn3:no-mips-f16, r=tgross35,scottmcm
std: Set `has_reliable_f16` to false for MIPS targets in build.rs

This PR makes std tests link for MIPS again (they broke with https://github.com/rust-lang/rust/pull/126608) by avoiding the following link errors. Step-by-step instructions on how to reproduce these errors in docker can be found below.

    std.9e27ea-cgu.12:(.text._ZN3std3num8test_num17edc3E+0x38): undefined reference to `__gnu_f2h_ieee'
    std.9e27ea-cgu.12:(.text._ZN3std3num8test_num17hdc3E+0x38): undefined reference to `__gnu_h2f_ieee'

This PR just adds one line of config in existing f16 infrastructure. It also disables four doctests that fails with the same link errors.

## Step-by-step to reproduce linking error

1. Prepare:

```sh
docker run -it ubuntu:24.10

apt update && apt install -y \
    libc6-mips-cross \
    libc6-mipsel-cross \
    libc6-mips64-cross \
    libc6-mips64el-cross \
    gcc-mips-linux-gnu \
    gcc-mipsel-linux-gnu \
    gcc-mips64-linux-gnuabi64 \
    gcc-mips64el-linux-gnuabi64 \
    git curl python3 build-essential

git clone --depth 1 https://github.com/rust-lang/rust.git
cd rust
```
2. Try to link std tests for any of these 4 MIPS targets by running any one of these commands:

```sh
CC_mips_unknown_linux_gnu=mips-linux-gnu-gcc \
CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \
./x test library/std --target mips-unknown-linux-gnu

CC_mipsel_unknown_linux_gnu=mipsel-linux-gnu-gcc \
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_GNU_LINKER=mipsel-linux-gnu-gcc \
./x test library/std --target mipsel-unknown-linux-gnu

CC_mips64_unknown_linux_gnuabi64=mips64-linux-gnuabi64-gcc \
CARGO_TARGET_MIPS64_UNKNOWN_LINUX_GNUABI64_LINKER=mips64-linux-gnuabi64-gcc \
./x test library/std --target mips64-unknown-linux-gnuabi64

CC_mips64el_unknown_linux_gnuabi64=mips64el-linux-gnuabi64-gcc \
CARGO_TARGET_MIPS64EL_UNKNOWN_LINUX_GNUABI64_LINKER=mips64el-linux-gnuabi64-gcc \
./x test library/std --target mips64el-unknown-linux-gnuabi64
```

### Expected

No link error. After this PR there are no link errors.

### Actual

```
error: linking with `mips-linux-gnu-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "mips-linux-gnu-gcc" "/tmp/rustcEtKsay/symbols.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.00.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.01.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.02.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.03.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.04.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.05.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.06.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.07.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.08.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.09.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.10.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.11.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.12.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.13.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.14.rcgu.o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.15.rcgu.o" "-Wl,--as-needed" "-L" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps" "-L" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/release/deps" "-L" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/librand_xorshift-deb32232a867c543.rlib" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/librand-5a391600dce9d98f.rlib" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/librand_core-a11cfba3d86c5298.rlib" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib/libtest-65b05caf5a9b99a4.rlib" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib/libgetopts-ba692b2f798aef60.rlib" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib/libunicode_width-20ec8b475126cb0b.rlib" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib/librustc_std_workspace_std-c17f739fee51cc86.rlib" "-L" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lstd-124ee57a4c00deda" "-Wl,-Bstatic" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/libcompiler_builtins-bd55a137b89bc81f.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/mips-unknown-linux-gnu/lib" "-o" "/rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,origin" "-Wl,-rpath,$ORIGIN/../lib"
  = note: /usr/lib/gcc-cross/mips-linux-gnu/12/../../../../mips-linux-gnu/bin/ld: /rust/build/x86_64-unknown-linux-gnu/stage1-std/mips-unknown-linux-gnu/release/deps/std-1cffa50fa8c43b63.std.9ee227e919a554fa-cgu.12.rcgu.o: in function `std::num::test_num':
          std.9ee227e919a554fa-cgu.12:(.text._ZN3std3num8test_num17haed2ea710c1afdc3E+0x38): undefined reference to `__gnu_f2h_ieee'
          /usr/lib/gcc-cross/mips-linux-gnu/12/../../../../mips-linux-gnu/bin/ld: std.9ee227e919a554fa-cgu.12:(.text._ZN3std3num8test_num17haed2ea710c1afdc3E+0x3c): undefined reference to `__gnu_f2h_ieee'
          /usr/lib/gcc-cross/mips-linux-gnu/12/../../../../mips-linux-gnu/bin/ld: std.9ee227e919a554fa-cgu.12:(.text._ZN3std3num8test_num17haed2ea710c1afdc3E+0x44): undefined reference to `__gnu_h2f_ieee'
          ...
          collect2: error: ld returned 1 exit status

error: could not compile `std` (lib test) due to 1 previous error
```
2024-07-08 18:22:26 +00:00
Matthias Krüger 55d25ceccb
Rollup merge of #127460 - Borgerr:clarify-drop-comment, r=jhpratt
clarify `sys::unix::fd::FileDesc::drop` comment

closes #66876

simply clarifies some resource-relevant things regarding the `close` syscall to reduce the amount of search needed in other parts of the web.
2024-07-08 16:28:17 +02:00
Matthias Krüger 5b6eb28bda
Rollup merge of #127355 - aceArt-GmbH:126475, r=oli-obk
Mark format! with must_use hint

Uses unstable feature https://github.com/rust-lang/rust/issues/94745

Part of #126475

First contribution to rust, please let me know if the blessing of tests is correct
Thanks `@bjorn3` for the help
2024-07-08 16:28:15 +02:00
Matthias Krüger c4ee2df539
Rollup merge of #120248 - WaffleLapkin:bonk-ptr-object-casts, r=compiler-errors,oli-obk,lnicola
Make casts of pointers to trait objects stricter

This is an attempt to `fix` https://github.com/rust-lang/rust/issues/120222 and https://github.com/rust-lang/rust/issues/120217.

This is done by adding restrictions on casting pointers to trait objects.

Before this PR the rules were as follows:

> When casting `*const X<dyn A>` -> `*const Y<dyn B>`, principal traits in `A` and `B` must refer to the same trait definition (or no trait).

With this PR the rules are changed to

> When casting `*const X<dyn Src>` -> `*const Y<dyn Dst>`
> - if `Dst` has a principal trait `DstP`,
>   - `Src` must have a principal trait `SrcP`
>   - `dyn SrcP` and `dyn DstP` must be the same type (modulo the trait object lifetime, `dyn T+'a` -> `dyn T+'b` is allowed)
>   - Auto traits in `Dst` must be a subset of auto traits in `Src`
>     - Not adhering to this is currently a FCW (warn-by-default + `FutureReleaseErrorReportInDeps`), instead of an error
> - if `Src` has a principal trait `Dst` must as well
>   - this restriction will be removed in a follow up PR

This ensures that
1. Principal trait's generic arguments match (no `*const dyn Tr<A>` -> `*const dyn Tr<B>` casts, which are a problem for [#120222](https://github.com/rust-lang/rust/issues/120222))
2. Principal trait's lifetime arguments match (no `*const dyn Tr<'a>` -> `*const dyn Tr<'b>` casts, which are a problem for [#120217](https://github.com/rust-lang/rust/issues/120217))
3. No auto traits can be _added_ (this is a problem for arbitrary self types, see [this comment](https://github.com/rust-lang/rust/pull/120248#discussion_r1463835350))

Some notes:
 - We only care about the metadata/last field, so you can still cast `*const dyn T` to `*const WithHeader<dyn T>`, etc
- The lifetime of the trait object itself (`dyn A + 'lt`) is not checked, so you can still cast `*mut FnOnce() + '_` to `*mut FnOnce() + 'static`, etc
  - This feels fishy, but I couldn't come up with a reason it must be checked

The diagnostics are currently not great, to say the least, but as far as I can tell this correctly fixes the issues.

cc `@oli-obk` `@compiler-errors` `@lcnr`
2024-07-08 16:28:15 +02:00
zachs18 8bcbab5dd1
Attempt to fix CI 2024-07-08 09:19:25 -05:00
许杰友 Jieyou Xu (Joe) e76b01775c
Rollup merge of #127367 - ChrisDenton:run-sync, r=Nilstrieb
Run alloc sync tests

I was browsing the code and this struck me as weird. We're not running some doc tests because, the comment says, Windows builders deadlock. That should absolutely not happen, at least with our current implementation. And if it does happen I'd like to know.

Just to be sure though I'll do some try builds.

try-job: x86_64-msvc
try-job: i686-msvc
try-job: i686-mingw
try-job: x86_64-mingw
2024-07-08 13:04:31 +08:00
许杰友 Jieyou Xu (Joe) adbcb1a8a9
Rollup merge of #126921 - workingjubilee:outline-va-list, r=Nilstrieb
Give VaList its own home

Just rearranging things internally and reexporting.
2024-07-08 13:04:31 +08:00
bors 0ca92de473 Auto merge of #127454 - matthiaskrgr:rollup-k3vfen2, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #127179 (Print `TypeId` as hex for debugging)
 - #127189 (LinkedList's Cursor: method to get a ref to the cursor's list)
 - #127236 (doc: update config file path in platform-support/wasm32-wasip1-threads.md)
 - #127297 (Improve std::Path's Hash quality by avoiding prefix collisions)
 - #127308 (Attribute cleanups)
 - #127354 (Describe Sized requirements for mem::offset_of)
 - #127409 (Emit a wrap expr span_bug only if context is not tainted)
 - #127447 (once_lock: make test not take as long in Miri)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-07 16:29:52 +00:00
zachs18 98010765f9
Move/change declaration of `mod exit_guard;` 2024-07-07 10:44:47 -05:00
Ashton Hunt a0f2b41d03 clarify `sys::unix::fd::FileDesc::drop` comment (#66876) 2024-07-07 09:29:16 -06:00
Matthias Krüger b564c510c1
Rollup merge of #127447 - RalfJung:once_lock_miri, r=joboet
once_lock: make test not take as long in Miri

Allocating 1000 list elements takes a while (`@zachs18` reported >5min), so let's reduce the iteration count when running in Miri. Unfortunately due to this clever `while let i @ 0..LEN =` thing, the count needs to be a constants, and constants cannot be shadowed, so we need to use another trick to hide the `cfg!(miri)` from the docs. (I think this loop condition may be a bit too clever, it took me a bit to decipher. Ideally this would be `while let i = ... && i < LEN`, but that is not stable yet.)
2024-07-07 14:22:03 +02:00
Matthias Krüger c40530d0de
Rollup merge of #127354 - nicholasbishop:bishop-sized-doc, r=Nilstrieb
Describe Sized requirements for mem::offset_of

The container doesn't have to be sized, but the field must be sized (at least until https://github.com/rust-lang/rust/issues/126151 is stable).
2024-07-07 14:22:02 +02:00
Matthias Krüger 56557c4555
Rollup merge of #127297 - the8472:path-new-hash, r=Nilstrieb
Improve std::Path's Hash quality by avoiding prefix collisions

This adds a bit rotation to the already existing state so that the same sequence of characters chunked at different offsets into separate path components results in different hashes.

The tests are from #127255

Closes #127254
2024-07-07 14:22:00 +02:00
Matthias Krüger 94d07befe7
Rollup merge of #127189 - GrigorenkoPV:linkedlist-cursor-list, r=Nilstrieb
LinkedList's Cursor: method to get a ref to the cursor's list

We're already providing `.back()` & `.front()`, for which we hold onto a reference to the parent list, so why not share it? Useful for when you got `LinkedList` -> `CursorMut` -> `Cursor` and cannot take another ref to the list, even though you should be able to. This seems to be completely safe & sound.

The name is, of course, bikesheddable.
2024-07-07 14:21:59 +02:00
Matthias Krüger 35a1ca043e
Rollup merge of #127179 - tgross35:typeid-debug-hex, r=Nilstrieb
Print `TypeId` as hex for debugging

In <https://github.com/rust-lang/rust/pull/127134>, the `Debug` impl for `TypeId` was changed to print a single integer rather than a tuple. Change this again to print as hex for more concise and consistent formatting, as was suggested.

Result:

    TypeId(0x1378bb1c0a0202683eb65e7c11f2e4d7)
2024-07-07 14:21:59 +02:00
Ralf Jung bee9120458 once_lock: make test not take as long in Miri 2024-07-07 09:19:32 +02:00
Chayim Refael Friedman 54556f49d3 Specialize `TrustedLen` for `Iterator::unzip()`
Don't check the capacity every time (and also for `Extend` for tuples, as this is how `unzip()` is implemented).

I did this with an unsafe method on `Extend` that doesn't check for growth (`extend_one_unchecked()`). I've marked it as perma-unstable currently, although we may want to expose it in the future so collections outside of std can benefit from it. Then specialize `Extend for (A, B)` for `TrustedLen` to call it.

It may seem that an alternative way of implementing this is to have a semi-public trait (`#[doc(hidden)]` public, so collections outside of core can implement it) for `extend()` inside tuples, and specialize it from collections. However, it is impossible due to limitations of `min_specialization`.

A concern that may arise with the current approach is that implementing `extend_one_unchecked()` correctly must also incur implementing `extend_reserve()`, otherwise you can have UB. This is a somewhat non-local safety invariant. However, I believe this is fine, since to have actual UB you must have unsafe code inside your `extend_one_unchecked()` that makes incorrect assumption, *and* not implement `extend_reserve()`. I've also documented this requirement.
2024-07-07 06:58:52 +03:00
David Tolnay 53d3e6217b
Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes) 2024-07-06 13:50:32 -07:00
lukas 3e9c9a05a8 Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
Greaka 585ca16e0b
as_simd: fix comment to be in line with 507583a (#121201) 2024-07-06 13:59:20 +02:00
Matthias Krüger 2137d19ef6
Rollup merge of #127275 - RalfJung:offset-from-isize-min, r=Amanieu
offset_from, offset: clearly separate safety requirements the user needs to prove from corollaries that automatically follow

By landing https://github.com/rust-lang/rust/pull/116675 we decided that objects larger than `isize::MAX` cannot exist in the address space of a Rust program, which lets us simplify these rules.

For `offset_from`, we can even state that the *absolute* distance fits into an `isize`, and therefore exclude `isize::MIN`. This PR also changes Miri to treat an `isize::MIN` difference like the other isize-overflowing cases.
2024-07-06 13:26:25 +02:00
Jubilee 9c8a88996e
Rollup merge of #125751 - pitaj:new_range_api, r=jhpratt
Add `new_range_api` for RFC 3550

Initial implementation for #125687

This includes a `From<legacy::RangeInclusive> for RangeInclusive` impl for convenience, instead of the `TryFrom` impl from the RFC. Having `From` is highly convenient and the debug assert should find almost all misuses.

This includes re-exports of all existing `Range` types under `core::range`, plus the range-related traits (`RangeBounds`, `Step`, `OneSidedRange`) and the `Bound` enum.

Currently the iterators are just wrappers around the old range types.

Tracking issues:

- https://github.com/rust-lang/rust/issues/123741
- https://github.com/rust-lang/rust/issues/125687
2024-07-05 23:23:34 -07:00