Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new
While working on concurrency support for Miri, I found that the `libstd::syn::unix::Thread::new` method has two potential problems: double-free and undefined behaviour.
**Double-free** could occur if the following events happened (credit for pointing this out goes to @RalfJung):
1. The call to `pthread_create` successfully launched a new thread that executed to completion and deallocated `p`.
2. The call to `pthread_attr_destroy` returned a non-zero value causing the `assert_eq!` to panic.
3. Since `mem::forget(p)` was not yet executed, the destructor of `p` would be executed and cause a double-free.
As far as I understand, this code also violates the stacked-borrows aliasing rules and thus would result in **undefined behaviour** if these rules were adopted. The problem is that the ownership of `p` is passed to the newly created thread before the call to `mem::forget`. Since the call to `mem::forget` is still a call, it counts as a use of `p` and triggers UB.
This pull request changes the code to use `mem::ManuallyDrop` instead of `mem::forget`. As a consequence, in case of a panic, `p` would be potentially leaked, which while undesirable is probably better than double-free or undefined behaviour.
Use associated numeric consts in documentation
Now when the associated constants on int/float types are stabilized and the recommended way of accessing said constants (#68952). We can start using it in this repository, and recommend it via documentation example code.
This PR is the reincarnation of #67913 minus the actual adding + stabilization of said constants. (EDIT: Now it's only changing the documentation. So users will see the new consts, but we don't yet update the internal code)
Because of how fast bit rot happens to PRs that touch this many files, it does not try to replace 100% of the old usage of the constants in the entire repo, but a good chunk of them.
bootstrap: add `--json-output` for rust-analyzer
Motivation is that this allows us to customize rust-analyzer's "cargo watch" integration to run x.py. You simply have to set the command to run to be `x.py --json-output`
r? @Mark-Simulacrum -- feel free to make changes, this is quick and dirty for sure
Miri engine: stronger type-based sanity check for assignments
r? @oli-obk @eddyb
Fixes https://github.com/rust-lang/rust/issues/70405
That issue says
> be sure to also add appropriate mutability checks to the patterns (mutable for the source, immutable for the dest)
I decided not to do that because I see no good reason to do it. The engine does not care either way, the assignment will happen correctly.
Clean up rustdoc js testers
I realized after the improvement made by @ollie27 on the rustdoc-js-tester that a lot of code was actually duplicated. This PR intends to remove this duplication, making it simpler to update in case of future main.js updates.
r? @ollie27
cc @kinnison
Translate the virtual `/rustc/$hash` prefix back to a real directory.
Closes#53486 and fixes#53081, by undoing the remapping to `/rustc/$hash` on the fly, when appropriate (e.g. our testsuites, or user crates that depend on `libstd`), but not during the Rust build itself (as that could leak the absolute build directory into the artifacts, breaking deterministic builds).
Tested locally by setting `remap-debuginfo = true` in `config.toml`, which without these changes, was causing 56 tests to fail (see https://github.com/rust-lang/rust/issues/53081#issuecomment-606703215 for more details).
cc @Mark-Simulacrum @alexcrichton @ehuss
Rollup of 7 pull requests
Successful merges:
- #70487 (Stabilize float::to_int_unchecked)
- #70595 (Remove unused discriminant reads from MIR bodies)
- #70691 (Improve docs in `AllocRef`)
- #70694 (Use Self over specific type in return position)
- #70700 (Expand on platform details of `include_xxx` macros)
- #70708 (Fix typo in u8::to_ascii_uppercase and u8::to_ascii_lowercase)
- #70716 (Unerase regions in infer_placeholder_type)
Failed merges:
r? @ghost
Expand on platform details of `include_xxx` macros
This is a small detail that is not explicitly mentioned, but it left me scratching my head for a while until I looked into its implementation details. Maybe worth mentioning.
Remove unused discriminant reads from MIR bodies
Allow the `SimplifyLocals` pass to remove reads of discriminants if the
read is never used.
Fixes#70531
r? @oli-obk
Stabilize float::to_int_unchecked
This renames and stabilizes unsafe floating point to integer casts, which are intended to be the substitute for the currently unsound `as` behavior, once that changes to safe-but-slower saturating casts. As such, I believe this also likely unblocks #10184 (our oldest I-unsound issue!), as once this rolls out to stable it would be far easier IMO to change the behavior of `as` to be safe by default.
This does not stabilize the trait or the associated method, as they are deemed internal implementation details (and consumers should not, generally, want to expose them, as in practice all callers likely know statically/without generics what the return type is).
Closes#67058