Commit Graph

16173 Commits

Author SHA1 Message Date
Min a3f8edff20 [SPARC] fix the name of signal 19 in sparc arch 2024-08-09 09:21:09 +08:00
Min 11b801bc4e [MIPS] fix the name of signal 19 in mips 2024-08-09 09:21:09 +08:00
Matthias Krüger 5f0461707a
Rollup merge of #128818 - RalfJung:std-miri-floats, r=tgross35
std float tests: special-case Miri in feature detection

Quick work-around to fix miri-test-libstd failures.

r? ``@tgross35``
2024-08-09 00:03:37 +02:00
Matthias Krüger 95b40727bd
Rollup merge of #128640 - RalfJung:rwlock-macos-miri, r=joboet
rwlock: disable 'frob' test in Miri on macOS

Due to https://github.com/rust-lang/rust/issues/121950, Miri will sometimes complain about this test on macOS. Better disable the test, as otherwise it can fail for unrelated PRs.

r? ``@joboet``
2024-08-09 00:03:35 +02:00
Matthias Krüger 127fbc8481
Rollup merge of #128749 - tgross35:float-inline, r=scottmcm
Mark `{f32,f64}::{next_up,next_down,midpoint}` inline

Most float functions are marked `#[inline]` so any float symbols used by these functions only need to be provided if the function itself is used. RFL recently noticed that `next_up`, `next_down`, and `midpoint` for `f32` and `f64` are not inline, which causes linker errors when building with certain configurations <https://lore.kernel.org/all/20240806150619.192882-1-ojeda@kernel.org/>.

Add the missing attributes so the symbols should no longer be required.
2024-08-08 18:57:02 +02:00
Matthias Krüger 3a9dd829d0
Rollup merge of #128306 - WiktorPrzetacznik:WiktorPrzetacznik-nonnull-alignoffset-update, r=Amanieu
Update NonNull::align_offset quarantees

This PR proposes to update [`NonNull::align_offset`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.align_offset) guarantees, which should to be matched with [`ptr::align_offset`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.align_offset-1)
(as `NonNull::align_offset` delegates to `ptr::align_offset`).

[PR #121201](https://github.com/rust-lang/rust/pull/121201) updated only `ptr::align_offset` docs.
2024-08-08 18:57:00 +02:00
Guillaume Gomez 6d69b2e408 Update compiler-builtins version to 0.1.118 2024-08-08 14:47:49 +02:00
Ralf Jung 5d968705b1 std float tests: special-case Miri in feature detection
also fix some cfg logic
2024-08-08 12:17:50 +02:00
B I Mohammed Abbas 2abcc6beeb Vxworks: Extern taskNameSet and fix build errors 2024-08-08 15:16:22 +05:30
Ralf Jung a120fb7031 rwlock: disable 'frob' test in Miri on macOS 2024-08-08 11:15:18 +02:00
B I Mohammed Abbas fb1dac21ff Fix VxWorks available parallelism: Move nonzero::uncheked into unsafe block 2024-08-08 12:59:04 +05:30
Trevor Gross 36b9aee947
Rollup merge of #128800 - clarfonthey:core-pattern-type, r=compiler-errors
Add tracking issue to core-pattern-type

While the actual `pattern_types` feature flag has an issue assigned, the exported macro and its module do not.

cc #123646
2024-08-07 20:49:05 -05:00
Trevor Gross 1d820dc9a6
Rollup merge of #128691 - tgross35:update-builtins, r=Amanieu
Update `compiler-builtins` to 0.1.117

This includes [1] which means we can remove the (nonworking) configuration of `no-f16-f128`.

Fixes https://github.com/rust-lang/rust/issues/128401.

[1]: https://github.com/rust-lang/compiler-builtins/pull/652

try-job: dist-various-1
2024-08-07 20:49:03 -05:00
ltdk 0257f42089 Add tracking issue to core-pattern-type 2024-08-07 20:43:05 -04:00
daxpedda 0732f7d5e1
Stabilize `Ready::into_inner()` 2024-08-08 00:18:19 +02:00
Matthias Krüger 2ee9678338
Rollup merge of #128261 - clarfonthey:iter-default, r=dtolnay
impl `Default` for collection iterators that don't already have it

There is a pretty strong precedent for implementing `Default` for collection iterators, and this does so for some where this implementation was missed.

I don't think this needs a separate ACP (since this precedent already exists, and these feel like they were just missed), however, it *will* need an FCP since these implementations are instantly stable.
2024-08-07 20:28:16 +02:00
Michael Howell 3312f5d652 alloc: make `to_string_str!` a bit less complex 2024-08-07 10:06:54 -07:00
Trevor Gross 6b3feb49c6 Mark `{f32,f64}::{next_up,next_down,midpoint}` inline
Most float functions are marked `#[inline]` so any float symbols used by
these functions only need to be provided if the function itself is used.
RFL recently noticed that `next_up`, `next_down`, and `midpoint` for
`f32` and `f64` are not inline, which causes linker errors when building
with certain configurations [1].

Add the missing attributes so the symbols should no longer be required.

Cc: Gary Guo <gary@garyguo.net>
Reported-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/all/20240806150619.192882-1-ojeda@kernel.org/ [1]
2024-08-07 03:24:55 -05:00
Trevor Gross 701bc03c52
Rollup merge of #128766 - Monadic-Cat:patch-1, r=tgross35
Trivial grammar fix in const keyword docs

This PR makes a trivial fix to the wording of a sentence in the `const` keyword docs.

> `const` items looks remarkably similar to `static` items, [...]

Either this should be written as
> A `const` items looks remarkably similar to a `static` item, [...]

or "looks" should be changed to "look".

I have selected the smaller diff.
2024-08-06 22:17:35 -05:00
Trevor Gross b3bfd66627
Rollup merge of #128417 - tgross35:f16-f128-math, r=dtolnay
Add `f16` and `f128` math functions

This adds intrinsics and math functions for `f16` and `f128` floating point types. Support is quite limited and some things are broken so tests don't run on many platforms, but this provides a starting point.
2024-08-06 22:17:32 -05:00
Monadic Cat f34ff1e05a
Trivial grammar fix in const keyword docs
> `const` items looks remarkably similar to `static` items, [...]

Either this should be written as
> A `const` items looks remarkably similar to a `static` item,

or "looks" should be changed to "look".

I have selected the smaller diff.
2024-08-06 21:59:04 -05:00
Trevor Gross 51e68c3006 Update `compiler-builtins` to 0.1.117
This includes [1] which means we can remove the (nonworking)
configuration of `no-f16-f128`.

Fixes https://github.com/rust-lang/rust/issues/128401.

[1]: https://github.com/rust-lang/compiler-builtins/pull/652
2024-08-06 21:48:32 -05:00
Matthias Krüger 6ed9a33001
Rollup merge of #128751 - devnexen:vxworks_set_thread_name, r=tgross35
std:🧵 set_name implementation proposal for vxWorks.
2024-08-07 00:34:15 +02:00
Matthias Krüger f00a55188f
Rollup merge of #128539 - biabbas:deny_unsafe, r=workingjubilee
Forbid unused unsafe in vxworks-specific std modules

Tracking issue #127747
Adding deny(unsafe_op_in_unsafe_fn) in VxWorks specific files did not cause any error.
Most of VxWorks falls back on Unix libraries. So we'll have to wait for Unix changes.

r? ```@workingjubilee```
2024-08-07 00:34:12 +02:00
Matthias Krüger 7e1360b1e1
Rollup merge of #128406 - lolbinarycat:bufreader_peek, r=Mark-Simulacrum
implement BufReader::peek

Part of https://github.com/rust-lang/rust/issues/128405
2024-08-07 00:34:12 +02:00
Matthias Krüger 16b251be10
Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieu
PinCoerceUnsized trait into core

cc ``@Darksonn`` ``@wedsonaf`` ``@ojeda``

This is a PR to introduce a `PinCoerceUnsized` trait in order to make trait impls generated by the proc-macro `#[derive(SmartPointer)]`, proposed by [RFC](e17e19ac7a/text/3621-derive-smart-pointer.md (pincoerceunsized-1)), sound. There you may find explanation, justification and discussion about the alternatives.

Note that we do not seek stabilization of this `PinCoerceUnsized` trait in the near future. The stabilisation of this trait does not block the eventual stabilization process of the `#[derive(SmartPointer)]` macro. Ideally, use of `DerefPure` is more preferrable except this will actually constitute a breaking change. `PinCoerceUnsized` emerges as a solution to the said soundness hole while avoiding the breaking change. More details on the `DerefPure` option have been described in this [section](e17e19ac7a/text/3621-derive-smart-pointer.md (derefpure)) of the RFC linked above.

Earlier discussion can be found in this [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Pin.20and.20soundness.20of.20unsizing.20coercions) and [rust-for-linux thread](https://rust-lang.zulipchat.com/#narrow/stream/425075-rust-for-linux/topic/.23.5Bderive.28SmartPointer.29.5D.20and.20pin.20unsoundness.20rfc.233621).

try-job: dist-various-2
2024-08-07 00:34:11 +02:00
Michael Howell 1b587a6e76 alloc: add ToString specialization for `&&str`
Fixes #128690
2024-08-06 14:37:33 -07:00
David Carlier b9e8e99198
std:🧵 set_name implementation proposal for vxWorks. 2024-08-06 21:10:12 +01:00
David Tolnay ba3cb156cb
Remove unused lifetime parameter from spawn_unchecked 2024-08-06 10:20:48 -07:00
Flying-Toast b335ec9ec8 Add a special case for CStr/CString in the improper_ctypes lint
Instead of saying to "consider adding a `#[repr(C)]` or
`#[repr(transparent)]` attribute to this struct", we now tell users to
"Use `*const ffi::c_char` instead, and pass the value from
`CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.

Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-08-06 13:56:59 +00:00
binarycat 4af77dfea5 implement BufReader::peek 2024-08-05 15:44:54 -04:00
Ralf Jung 212417b87f custom MIR: add support for tail calls 2024-08-05 18:23:14 +02:00
Ralf Jung 28e0907111 nontemporal_store: make sure that the intrinsic is truly just a hint 2024-08-05 10:57:14 +02:00
Georgii Rylov 8a61674559 WASI fixing unsafe_op_in_unsafe_fn for std::{os, sys} 2024-08-05 09:48:26 +01:00
bors 4d48a6be74 Auto merge of #128673 - matthiaskrgr:rollup-gtvpkm7, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #128026 (std:🧵 available_parallelism implementation for vxWorks proposal.)
 - #128471 (rustdoc: Fix handling of `Self` type in search index and refactor its representation)
 - #128607 (Use `object` in `run-make/symbols-visibility`)
 - #128609 (Remove unnecessary constants from flt2dec dragon)
 - #128611 (run-make: Remove cygpath)
 - #128619 (Correct the const stabilization of `<[T]>::last_chunk`)
 - #128630 (docs(resolve): more explain about `target`)
 - #128660 (tests: more crashes)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-05 06:55:50 +00:00
Matthias Krüger 74df517b90
Rollup merge of #128619 - glandium:last_chunk, r=scottmcm
Correct the const stabilization of `<[T]>::last_chunk`

`<[T]>::first_chunk` became const stable in 1.77, but `<[T]>::last_chunk` was left out. This was fixed in 3488679768, which reached stable in 1.80, making `<[T]>::last_chunk` const stable as of that version, but it is documented as being const stable as 1.77. While this is what should have happened, the documentation should reflect what actually did happen.
2024-08-05 08:22:24 +02:00
Matthias Krüger 1e951b70c7
Rollup merge of #128609 - swenson:smaller-faster-dragon, r=Amanieu
Remove unnecessary constants from flt2dec dragon

The "dragon" `flt2dec` algorithm uses multi-precision multiplication by (sometimes large) powers of 10. It has precomputed some values to help with these calculations.

BUT:

* There is no need to store powers of 10 and 2 * powers of 10: it is trivial to compute the second from the first.
* We can save a chunk of memory by storing powers of 5 instead of powers of 10 for the large powers (and just shifting as appropriate).
* This also slightly speeds up the routines (by ~1-3%) since the intermediate products are smaller and the shift is cheap.

In this PR, we remove the unnecessary constants and do the necessary adjustments.

Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu):

```
num::flt2dec::bench_big_shortest                      137.92/iter   +/- 2.24
num::flt2dec::strategy:🐉:bench_big_exact_12   2135.28/iter  +/- 38.90
num::flt2dec::strategy:🐉:bench_big_exact_3     904.95/iter  +/- 10.58
num::flt2dec::strategy:🐉:bench_big_exact_inf 47230.33/iter +/- 320.84
num::flt2dec::strategy:🐉:bench_big_shortest   3915.05/iter  +/- 51.37
```

and after:

```
num::flt2dec::bench_big_shortest                      137.40/iter   +/- 2.03
num::flt2dec::strategy:🐉:bench_big_exact_12   2101.10/iter  +/- 25.63
num::flt2dec::strategy:🐉:bench_big_exact_3     873.86/iter   +/- 4.20
num::flt2dec::strategy:🐉:bench_big_exact_inf 47468.19/iter +/- 374.45
num::flt2dec::strategy:🐉:bench_big_shortest   3877.01/iter  +/- 45.74
```
2024-08-05 08:22:22 +02:00
Matthias Krüger 02c3837d8b
Rollup merge of #128026 - devnexen:available_parallelism_vxworks, r=Mark-Simulacrum
std:🧵 available_parallelism implementation for vxWorks proposal.
2024-08-05 08:22:21 +02:00
Matthias Krüger e4367cec5e
Rollup merge of #128309 - kmicklas:btreeset-cursor, r=Amanieu
Implement cursors for `BTreeSet`

Tracking issue: https://github.com/rust-lang/rust/issues/107540

This is a straightforward wrapping of the map API, except that map's `CursorMut` does not make sense, because there is no value to mutate. Hence, map's `CursorMutKey` is wrapped here as just `CursorMut`, since it's unambiguous for sets and we don't normally speak of "keys". On the other hand, I can see some potential for confusion with `CursorMut` meaning different things in each module. I'm happy to take suggestions to improve that.

r? ````@Amanieu````
2024-08-05 05:40:20 +02:00
Mike Hommey 70ab51f988 Correct the const stabilization of `<[T]>::last_chunk`
`<[T]>::first_chunk` became const stable in 1.77, but `<[T]>::last_chunk` was
left out. This was fixed in 3488679768, which reached stable in 1.80,
making `<[T]>::last_chunk` const stable as of that version, but it is
documented as being const stable as 1.77. While this is what should have
happened, the documentation should reflect what actually did happen.
2024-08-05 05:01:39 +09:00
bors 176e545209 Auto merge of #128534 - bjorn3:split_stdlib_workspace, r=Mark-Simulacrum
Move the standard library to a separate workspace

This ensures that the Cargo.lock packaged for it in the rust-src component is up-to-date, allowing rust-analyzer to run cargo metadata on the standard library even when the rust-src component is stored in a read-only location as is necessary for loading crates.io dependencies of the standard library.

This also simplifies tidy's license check for runtime dependencies as it can now look at all entries in library/Cargo.lock without having to filter for just the dependencies of runtime crates. In addition this allows removing an exception in check_runtime_license_exceptions that was necessary due to the compiler enabling a feature on the object crate which pulls in a dependency not allowed for the standard library.

While cargo workspaces normally enable dependencies of multiple targets to be reused, for the standard library we do not want this reusing to prevent conflicts between dependencies of the sysroot and of tools that are built using this sysroot. For this reason we already use an unstable cargo feature to ensure that any dependencies which would otherwise be shared get a different -Cmetadata argument as well as using separate build dirs.

This doesn't change the situation around vendoring. We already have several cargo workspaces that need to be vendored. Adding another one doesn't change much.

There are also no cargo profiles that are shared between the root workspace and the library workspace anyway, so it doesn't add any extra work when changing cargo profiles.
2024-08-04 18:40:03 +00:00
joboet 207ee73b7a
std: refactor UNIX random data generation
This PR makes a number of changes to the UNIX randomness implementation:
* Use `io::Error` for centralized error handling
* Move the file-fallback logic out of the `getrandom`-specific module
* Stop redefining the syscalls on macOS and DragonFly, they have appeared in `libc`
* Add a `OnceLock` to cache the random device file descriptor
2024-08-04 18:39:59 +02:00
Konippi 341511ad4e refactor: standardize duplicate processes in parser 2024-08-04 21:39:42 +09:00
Matthias Krüger c8a33f7e34
Rollup merge of #128526 - tshepang:patch-1, r=Amanieu
time.rs: remove "Basic usage text"

Only one example is given (for each method)
2024-08-04 11:32:34 +02:00
bors b389b0ab72 Auto merge of #128466 - sayantn:stdarch-update, r=tgross35
Update the stdarch submodule

cc `@tgross35` `@Amanieu`
r? `@tgross35`

try-job: dist-various-2
2024-08-04 02:11:27 +00:00
sayantn 01bda01e33 Update stdarch 2024-08-04 03:40:21 +05:30
sayantn 2cde11f2d1 Chore: add `x86_amx_intrinsics` feature flag to `core/lib.rs` and remove `issue-120720-reduce-nan.rs` 2024-08-04 03:08:18 +05:30
Matthias Krüger 06133811a6
Rollup merge of #128551 - Konippi:refactor-backtrace-style-in-panic, r=tgross35
chore: refactor backtrace style in panic

# Refactor get_backtrace_style for better readability and potential performance improvements

This PR aims to improve the readability and maintainability of the `set_backtrace_style` and `get_backtrace_style` function.
2024-08-03 20:51:53 +02:00
Matthias Krüger 53a56190af
Rollup merge of #128530 - scottmcm:repeat-n-unchecked, r=joboet
Implement `UncheckedIterator` directly for `RepeatN`

This just pulls the code out of `next` into `next_unchecked`, rather than making the `Some` and `unwrap_unchecked`ing it.

And while I was touching it, I added a codegen test that `array::repeat` for something that's just `Clone`, not `Copy`, still ends up optimizing to the same thing as `[x; n]`: <https://rust.godbolt.org/z/YY3a5ajMW>.
2024-08-03 20:51:52 +02:00
Christopher Swenson 36a805939e Remove unnecessary constants from flt2dec dragon
The "dragon" `flt2dec` algorithm uses multi-precision multiplication by
(sometimes large) powers of 10. It has precomputed some values to help
with these calculations.

BUT:

* There is no need to store powers of 10 and 2 * powers of 10: it is
  trivial to compute the second from the first.
* We can save a chunk of memory by storing powers of 5 instead of powers
  of 10 for the large powers (and just shifting by 2 as appropriate).
* This also slightly speeds up the routines (by ~1-3%) since the
  intermediate products are smaller and the shift is cheap.

In this PR, we remove the unnecessary constants and do the necessary
adjustments.

Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu):

```
num::flt2dec::bench_big_shortest                      137.92/iter   +/- 2.24
num::flt2dec::strategy:🐉:bench_big_exact_12   2135.28/iter  +/- 38.90
num::flt2dec::strategy:🐉:bench_big_exact_3     904.95/iter  +/- 10.58
num::flt2dec::strategy:🐉:bench_big_exact_inf 47230.33/iter +/- 320.84
num::flt2dec::strategy:🐉:bench_big_shortest   3915.05/iter  +/- 51.37
```

and after:

```
num::flt2dec::bench_big_shortest                      137.40/iter   +/- 2.03
num::flt2dec::strategy:🐉:bench_big_exact_12   2101.10/iter  +/- 25.63
num::flt2dec::strategy:🐉:bench_big_exact_3     873.86/iter   +/- 4.20
num::flt2dec::strategy:🐉:bench_big_exact_inf 47468.19/iter +/- 374.45
num::flt2dec::strategy:🐉:bench_big_shortest   3877.01/iter  +/- 45.74
```
2024-08-03 08:49:38 -07:00
Lukas Bergdoll 613155c96a Apply review comments to PartialOrd section 2024-08-03 15:10:27 +02:00
bors 1f47624f9a Auto merge of #128404 - compiler-errors:revert-dead-code-changes, r=pnkfelix
Revert recent changes to dead code analysis

This is a revert to recent changes to dead code analysis, namely:
* efdf219 Rollup merge of #128104 - mu001999-contrib:fix/128053, r=petrochenkov
* a70dc297a8 Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelix
* 31fe9628cf Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
* 2724aeaaeb Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix
* 977c5fd419 Rollup merge of #126315 - mu001999-contrib:fix/126289, r=petrochenkov
* 13314df21b Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix

There is an additional change stacked on top, which suppresses false-negatives that were masked by this work. I believe the functions that are touched in that code are legitimately unused functions and the types are not reachable since this `AnonPipe` type is not publically reachable -- please correct me if I'm wrong cc `@NobodyXu` who added these in ##127153.

Some of these reverts (#126315 and #126618) are only included because it makes the revert apply cleanly, and I think these changes were only done to fix follow-ups from the other PRs?

I apologize for the size of the PR and the churn that it has on the codebase (and for reverting `@mu001999's` work here), but I'm putting this PR up because I am concerned that we're making ad-hoc changes to fix bugs that are fallout of these PRs, and I'd like to see these changes reimplemented in a way that's more separable from the existing dead code pass. I am happy to review any code to reapply these changes in a more separable way.

cc `@mu001999`
r? `@pnkfelix`

Fixes #128272
Fixes #126169
2024-08-03 13:04:30 +00:00
Michael Goulet cbd27db9a9 Suppress new false-negatives that were masked by dead code analysis changes 2024-08-03 07:57:31 -04:00
Michael Goulet 5f5b4ee128 Revert "Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix"
This reverts commit 31fe9628cf, reversing
changes made to f20307851e.
2024-08-03 07:57:31 -04:00
Matthias Krüger 2f549aac39
Rollup merge of #128368 - nnethercote:rustfmt-tweaks, r=cuviper
Formatting tweaks

Some small post-#125443 formatting tweaks.

r? ``@cuviper``
2024-08-03 11:17:44 +02:00
Matthias Krüger 95d9f1c4ab
Rollup merge of #128303 - NobodyXu:specialise-for-pipe, r=cuviper
Enable `std::io::copy` specialisation for `std::pipe::{PipeReader, PipeWriter}`

Enable `std::io::copy` specialisation on unix for the newly added anonymous pipe API, tracking issue rust-lang/rust#127154
2024-08-03 11:17:43 +02:00
Matthias Krüger 1f700139f8
Rollup merge of #127586 - zachs18:more-must-use, r=cuviper
Add `#[must_use]` to some `into_raw*` functions.

cc #121287

r? ``@cuviper``

Adds `#[must_use = "losing the pointer will leak memory"]`[^1] to `Box::into_raw(_with_allocator)`, `Vec::into_raw_parts(_with_alloc)`, `String::into_raw_parts`[^2], and `rc::{Rc, Weak}::into_raw_with_allocator` (Rc's normal `into_raw` and all of `Arc`'s `into_raw*`s are already `must_use`).

Adds `#[must_use = "losing the raw <resource name may leak resources"]` to `IntoRawFd::into_raw_fd`, `IntoRawSocket::into_raw_socket`, and `IntoRawHandle::into_raw_handle`.

[^1]: "*will* leak memory" may be too-strong wording (since `Box`/`Vec`/`String`/`rc::Weak` might not have a backing allocation), but I left it as-is for simplicity and consistency.

[^2]: `String::into_raw_parts`'s `must_use` message is changed from the previous (possibly misleading) "`self` will be dropped if the result is not used".
2024-08-03 11:17:42 +02:00
Matthias Krüger 8aa18290a4
Rollup merge of #126704 - sayantn:sha, r=Amanieu
Added SHA512, SM3, SM4 target-features and `sha512_sm_x86` feature gate

This is an effort towards #126624. This adds support for these 3 target-features and introduces the feature flag `sha512_sm_x86`, which would gate these target-features and the yet-to-be-implemented detection and intrinsics in stdarch.
2024-08-03 11:17:41 +02:00
B I Mohammed Abbas c2c46e3e30 Forbid unsafe_op_in_unsafe_fn in vxworks specific os and sys files 2024-08-03 08:00:39 +05:30
Konippi a798e0f488 chore: refactor backtrace style in panic 2024-08-03 11:12:16 +09:00
bors 1df0458781 Auto merge of #128528 - workingjubilee:you-dont-need-to-see-this-cpuid-move-along, r=Amanieu
Finish removing `has_cpuid`

The one use of it was guaranteed to be always true.

try-job: test-various
2024-08-03 00:18:15 +00:00
bjorn3 1f3be75f56 Move the standard library to a separate workspace
This ensures that the Cargo.lock packaged for it in the rust-src
component is up-to-date, allowing rust-analyzer to run cargo metadata on
the standard library even when the rust-src component is stored in a
read-only location as is necessary for loading crates.io dependencies of
the standard library.

This also simplifies tidy's license check for runtime dependencies as it
can now look at all entries in library/Cargo.lock without having to
filter for just the dependencies of runtime crates. In addition this
allows removing an exception in check_runtime_license_exceptions that
was necessary due to the compiler enabling a feature on the object crate
which pulls in a dependency not allowed for the standard library.

While cargo workspaces normally enable dependencies of multiple targets
to be reused, for the standard library we do not want this reusing to
prevent conflicts between dependencies of the sysroot and of tools that
are built using this sysroot. For this reason we already use an unstable
cargo feature to ensure that any dependencies which would otherwise be
shared get a different -Cmetadata argument as well as using separate
build dirs.

This doesn't change the situation around vendoring. We already have
several cargo workspaces that need to be vendored. Adding another one
doesn't change much.

There are also no cargo profiles that are shared between the root
workspace and the library workspace anyway, so it doesn't add any extra
work when changing cargo profiles.
2024-08-02 10:48:12 +00:00
bors 19326022d2 Auto merge of #128254 - Amanieu:orig-binary-search, r=tgross35
Rewrite binary search implementation

This PR builds on top of #128250, which should be merged first.

This restores the original binary search implementation from #45333 which has the nice property of having a loop count that only depends on the size of the slice. This, along with explicit conditional moves from #128250, means that the entire binary search loop can be perfectly predicted by the branch predictor.

Additionally, LLVM is able to unroll the loop when the slice length is known at compile-time. This results in a very compact code sequence of 3-4 instructions per binary search step and zero branches.

Fixes #53823
Fixes #115271
2024-08-02 08:20:35 +00:00
Scott McMurray 77ca30f195 Implement `UncheckedIterator` directly for `RepeatN` 2024-08-01 21:58:34 -07:00
Matthias Krüger 55ed05cbac
Rollup merge of #128491 - c410-f3r:unlock-rfc-2011, r=workingjubilee
[`macro_metavar_expr_concat`] Dogfooding

cc #124225

Starts inner usage to test the robustness of the implementation.
2024-08-02 06:43:43 +02:00
Matthias Krüger 67fcb58347
Rollup merge of #128453 - RalfJung:raw_eq, r=saethlin
raw_eq: using it on bytes with provenance is not UB (outside const-eval)

The current behavior of raw_eq violates provenance monotonicity. See https://github.com/rust-lang/rust/pull/124921 for an explanation of provenance monotonicity. It is violated in raw_eq because comparing bytes without provenance is well-defined, but adding provenance makes the operation UB.

So remove the no-provenance requirement from raw_eq. However, the requirement stays in-place for compile-time invocations of raw_eq, that indeed cannot deal with provenance.

Cc `@rust-lang/opsem`
2024-08-02 06:43:43 +02:00
Jubilee Young 2f0aaaf2b9 std: Remove has_cpuid
The one use of it was guaranteed to be always true.
2024-08-01 20:45:38 -07:00
Tshepang Mbambo af79a6396c
time.rs: remove "Basic usage text"
Only one example is given (for each method)
2024-08-02 05:16:01 +02:00
Caio b2f7e71f0b Dogfood 2024-08-01 21:32:12 -03:00
sayantn 41b017ec99 Add the `sha512`, `sm3` and `sm4` target features
Add the feature in `core/lib.rs`
2024-08-02 02:29:15 +05:30
Ken Micklas 0bc501e0ad Fix mutability in doc tests for `BTreeSet` cursors 2024-08-01 21:02:51 +01:00
Trevor Gross 8e2ca0c9d5 Add a disclaimer about x86 `f128` math functions
Due to a LLVM bug, `f128` math functions link successfully but LLVM
chooses the wrong symbols (`long double` symbols rather than those for
binary128).

Since this is a notable problem that may surprise a number of users, add
a note about it.

Link: https://github.com/llvm/llvm-project/issues/44744
2024-08-01 15:38:53 -04:00
Trevor Gross 43836421f8 Update comments for `{f16, f32, f64, f128}::midpoint`
Clarify what makes some operations not safe, and correct comment in the
default branch ("not safe" -> "safe").
2024-08-01 15:38:53 -04:00
Trevor Gross e18036c769 Add `core` functions for `f16` and `f128` that require math routines
`min`, `max`, and similar functions require external math routines. Add
these under the same gates as `std` math functions (`reliable_f16_math`
and `reliable_f128_math`).
2024-08-01 15:38:53 -04:00
Trevor Gross fc43c01417 Add math functions for `f16` and `f128`
This adds missing functions for math operations on the new float types.

Platform support is pretty spotty at this point, since even platforms
with generally good support can be missing math functions.
`std/build.rs` is updated to reflect this.
2024-08-01 15:38:51 -04:00
Trevor Gross 82b40c4d8e Add math intrinsics for `f16` and `f128`
These already exist in the compiler. Expose them in core so we can add
their library functions.
2024-08-01 15:36:15 -04:00
Ken Micklas cbdc377866 Introduce `Cursor`/`CursorMut`/`CursorMutKey` thrichotomy for `BTreeSet` like map API 2024-08-01 19:49:26 +01:00
Ken Micklas 4560770451 Fix some uses of "map" instead of "set" in `BTreeSet` cursor API docs 2024-08-01 19:48:23 +01:00
Ken Micklas 020476296b Share `UnorderedKeyError` with `BTReeMap` for set API 2024-08-01 19:47:57 +01:00
Matthias Krüger e6b6d04b06
Rollup merge of #128499 - Konippi:refactor-backtrace-formatting, r=tgross35
chore: refactor backtrace formatting

Replace `write_str()` with the `writeln!()` macro, consolidating multiple write operations.
2024-08-01 18:43:42 +02:00
Matthias Krüger ca73b8b7a5
Rollup merge of #128497 - Bryanskiy:fix-dropck-doc, r=lcnr
fix dropck documentation for `[T;0]` special-case

fixes https://github.com/rust-lang/rust/issues/110288.

r? ``@lcnr``
2024-08-01 18:43:41 +02:00
Matthias Krüger 683f2d3cb2
Rollup merge of #128433 - hermit-os:hermit-unsafe_op_in_unsafe_fn, r=joboet
fix(hermit): `deny(unsafe_op_in_unsafe_fn)`

Tracking issue: https://github.com/rust-lang/rust/issues/127747

r? workingjubilee

CC: ``@stlankes``
2024-08-01 18:43:39 +02:00
Lukas Bergdoll eae7a186b2 Hide internal sort module 2024-08-01 17:37:07 +02:00
Konippi 45d35ba4fd chore: refactor backtrace formatting 2024-08-02 00:24:29 +09:00
Bryanskiy c8a3cafc0f fix dropck documentation for `[T;0]` special-case 2024-08-01 17:44:14 +03:00
joboet 88fda58bf5
core: use `compare_bytes` for more slice element types 2024-08-01 14:41:35 +02:00
Martin Kröning 820ec720ff
fix(os/hermit): `deny(unsafe_op_in_unsafe_fn)`
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-08-01 12:34:43 +02:00
Martin Kröning 4da966c30e
fix(pal/hermit): `deny(unsafe_op_in_unsafe_fn)`
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-08-01 12:34:43 +02:00
Martin Kröning b21af629ef
refactor(pal/hermit): make `ENV` a non-mutable static
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-08-01 12:34:43 +02:00
Matthias Krüger 0cda002610
Rollup merge of #128416 - maurer:remove-android-hack, r=tgross35
android: Remove libstd hacks for unsupported Android APIs

Our minimum supported API version is 21, remove hacks to support older Android APIs.

try-job: arm-android

r? tgross35
2024-08-01 08:33:27 +02:00
bors e485266c67 Auto merge of #128461 - matthiaskrgr:rollup-3dpp11g, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #123813 (Add `REDUNDANT_IMPORTS` lint for new redundant import detection)
 - #126697 ([RFC] mbe: consider the `_` in 2024 an expression)
 - #127159 (match lowering: Hide `Candidate` from outside the lowering algorithm)
 - #128244 (Peel off explicit (or implicit) deref before suggesting clone on move error in borrowck, remove some hacks)
 - #128431 (Add myself as VxWorks target maintainer for reference)
 - #128438 (Add special-case for [T, 0] in dropck_outlives)
 - #128457 (Fix docs for OnceLock::get_mut_or_init)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-01 02:26:32 +00:00
Matthias Krüger 8377aae6a1
Rollup merge of #128162 - ChrisDenton:cleanup, r=joboet
Cleanup sys module to match house style

This moves a test file out of sys as it's just testing std types. Also cleans up some assorted bits including making the `use` statements match the house style.
2024-08-01 00:50:11 +02:00
Matthias Krüger c1f2112600
Rollup merge of #127567 - joboet:once_wait, r=Amanieu
std: implement the `once_wait` feature

Tracking issue: #127527

This additionally adds a `wait_force` method to `Once` that doesn't panic on poison.

I also took the opportunity and cleaned up up the code of the queue-based implementation a bit.
2024-08-01 00:50:10 +02:00
Juniper Tyree 83fb140ec1
Fix docs for OnceLock::get_mut_or_init 2024-07-31 22:00:38 +03:00
Ralf Jung f97aba2271 raw_eq: using it on bytes with provenance is not UB (outside const-eval) 2024-07-31 20:26:20 +02:00
joboet 1d49aad844
std: fix busy-waiting in `Once::wait_force`, add more tests 2024-07-31 17:44:10 +02:00
joboet cf11f499b3
std: implement the `once_wait` feature 2024-07-31 17:42:20 +02:00
Chris Denton e84a7d91b7
Remove unneeded `pub(crate)` 2024-07-31 13:45:14 +00:00
Matthias Krüger 5c63363284
Rollup merge of #128388 - beetrees:f16-f128-slightly-improve-windows-abi, r=tgross35
Match LLVM ABI in `extern "C"` functions for `f128` on Windows

As MSVC doesn't support `_Float128`, x86-64 Windows doesn't have a defined ABI for `f128`. Currently, Rust will pass and return `f128` indirectly for `extern "C"` functions. This is inconsistent with LLVM, which passes and returns `f128` in XMM registers, meaning that e.g. the ABI of `extern "C"` compiler builtins won't match. This PR fixes this discrepancy by making the x86-64 Windows `extern "C"` ABI pass `f128` directly through to LLVM, so that Rust will follow whatever LLVM does. This still leaves the difference between LLVM and GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054) but this PR is still an improvement as at least Rust is now consistent with it's primary codegen backend and compiler builtins from `compiler-builtins` will now work.

I've also fixed the x86-64 Windows `has_reliable_f16` match arm in `std` `build.rs` to refer to the correct target, and added an equivalent match arm to `has_reliable_f128` as the LLVM-GCC ABI difference affects both `f16` and `f128`.

Tracking issue: #116909

try-job: x86_64-msvc
try-job: x86_64-mingw
2024-07-31 15:36:31 +02:00
Matthias Krüger 22dbf88744
Rollup merge of #128387 - liigo:patch-14, r=tgross35
More detailed note to deprecate ONCE_INIT
2024-07-31 15:36:31 +02:00
Martin Kröning 127b469b7e
refactor(pal/hermit): use default impl of `GlobalAlloc::alloc_zeroed`
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-07-31 13:31:41 +02:00
Martin Kröning 76b4a86b57
refactor(pal/hermit): return `!` to satisfy rust-analyzer
This silences this rust-analyzer-specific error: `expected !, found ()`

Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
2024-07-31 13:31:41 +02:00
Lukas Bergdoll afc404fdfc Apply review comments
- Use if the implementation of [`Ord`] for `T`
  language
- Link to total order wiki page
- Rework total order help and examples
- Improve language to be more precise and less
  prone to misunderstandings.
- Fix usage of `sort_unstable_by` in `sort_by`
  example
- Fix missing author mention
- Use more consistent example input for sort
- Use more idiomatic assert_eq! in examples
- Use more natural "comparison function" language
  instead of "comparator function"
2024-07-31 11:36:57 +02:00
Xiangfei Ding d495b84a9a
PinCoerceUnsized trait into core 2024-07-31 17:10:55 +08:00
Matthew Maurer 7d7ad7b874 android: Remove libstd hacks for unsupported Android APIs
Our minimum supported API version is 21, remove hacks to support older
Android APIs.
2024-07-31 01:03:36 +00:00
Chris Denton 9169622027
Move Windows implementation of anon pipe 2024-07-30 19:23:52 +00:00
beetrees fe6478cc53
Match LLVM ABI in `extern "C"` functions for `f128` on Windows 2024-07-30 20:23:33 +01:00
Chris Denton a75d2f9d38
Cleanup sys module to match house style 2024-07-30 19:22:54 +00:00
bors f8060d282d Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68
Bump bootstrap compiler to new beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-30 17:49:08 +00:00
Amanieu d'Antras bb58488207 Rewrite binary search implementation
This restores the original binary search implementation from #45333
which has the nice property of having a loop count that only depends on
the size of the slice. This, along with explicit conditional moves
from #128250, means that the entire binary search loop can be perfectly
predicted by the branch predictor.

Additionally, LLVM is able to unroll the loop when the slice length is
known at compile-time. This results in a very compact code sequence of
3-4 instructions per binary search step and zero branches.

Fixes #53823
2024-07-30 17:07:56 +01:00
Liigo Zhuang 918cdcc9c5
More detailed note to deprecate ONCE_INIT 2024-07-30 19:36:28 +08:00
bors 7e3a971870 Auto merge of #128378 - matthiaskrgr:rollup-i3qz9uo, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #127574 (elaborate unknowable goals)
 - #128141 (Set branch protection function attributes)
 - #128315 (Fix vita build of std and forbid unsafe in unsafe in the os/vita module)
 - #128339 ([rustdoc] Make the buttons remain when code example is clicked)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-30 05:50:05 +00:00
bors 710ce90fbe Auto merge of #128250 - Amanieu:select_unpredictable, r=nikic
Add `select_unpredictable` to force LLVM to use CMOV

Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-30 03:22:27 +00:00
Matthias Krüger f396a42ed6
Rollup merge of #128315 - zetanumbers:psvita-unsafe-in-unsafe, r=workingjubilee
Fix vita build of std and forbid unsafe in unsafe in the os/vita module

See #127747

r? `@workingjubilee`

`@pheki` `@nikarh`
2024-07-30 04:31:55 +02:00
bors dba8e2d2c2 Auto merge of #128234 - jcsp:retain-empty-case, r=tgross35
Optimize empty case in Vec::retain

While profiling some code that happens to call Vec::retain() in a tight loop, I noticed more runtime than expected in retain, even in a bench case where the vector was always empty.  When I wrapped my call to retain in `if !myvec.is_empty()` I saw faster execution compared with doing retain on an empty vector.

On closer inspection, Vec::retain is doing set_len(0) on itself even when the vector is empty, and then resetting the length again in BackshiftOnDrop::drop.

Unscientific screengrab of a flamegraph illustrating how we end up spending time in set_len and drop:
![image](https://github.com/user-attachments/assets/ebc72ace-84a0-4432-9b6f-1b3c96d353ba)
2024-07-30 00:55:52 +00:00
Nicholas Nethercote 70fcf9e790 Insert some blank lines.
After things that are immediately followed by a `use` declaration and
look like they might apply to that `use` item but actually don't.
2024-07-30 07:25:15 +10:00
Nicholas Nethercote bd24763aaf Move a comment.
In #125443 this comment ended up in the wrong spot. I'm not sure why;
after careful checking this was the only case I could find like this.
2024-07-30 07:24:19 +10:00
Pavel Grigorenko 110c273f4f CloneToUninit: use a private specialization trait
and move implementation details into a submodule
2024-07-29 20:44:43 +03:00
Pavel Grigorenko dbc13fb309 Sparkle some attributes over `CloneToUninit` stuff 2024-07-29 20:44:42 +03:00
Pavel Grigorenko afabc583f7 impl CloneToUninit for Path and OsStr 2024-07-29 20:44:39 +03:00
Pavel Grigorenko ec921db289 impl CloneToUninit for str and CStr 2024-07-29 20:33:11 +03:00
George Bateman 23f46e5b99
Stabilize offset_of_nested 2024-07-29 17:50:12 +01:00
bors 56c698c711 Auto merge of #128334 - matthiaskrgr:rollup-nhxdt0c, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #128182 (handle no_std targets on std builds)
 - #128277 (miri: fix offset_from behavior on wildcard pointers)
 - #128304 (Isolate the diagnostic code that expects `thir::Pat` to be printable)
 - #128307 (Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`)
 - #128322 (CI: move RFL job forward to v6.11-rc1)
 - #128333 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-29 10:05:42 +00:00
Matthias Krüger 8f7af88b33
Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomez
Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`

I am not sure if the lint is supposed to be "ready enough" (since it is `allow` by default), but it does catch a couple issues in `core` (`alloc`, `std`, `test` and `proc_macro` are already clean), so I propose making it `warn` in all the crates rendered in the website.

Cc: `@GuillaumeGomez`
2024-07-29 11:42:35 +02:00
John Spray 6a6824a0ab Optimize empty case in Vec::retain 2024-07-29 09:40:51 +01:00
bors 80d8270d84 Auto merge of #125016 - nicholasbishop:bishop-cb-112, r=tgross35
Update compiler_builtins to 0.1.114

The `weak-intrinsics` feature was removed from compiler_builtins in https://github.com/rust-lang/compiler-builtins/pull/598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.

In https://github.com/rust-lang/compiler-builtins/pull/593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
2024-07-29 07:41:33 +00:00
Matthias Krüger 0c6d2fb3dc
Rollup merge of #128310 - kmicklas:btree-map-peek-next-docs, r=tgross35
Add missing periods on `BTreeMap` cursor `peek_next` docs

Tracking issue: https://github.com/rust-lang/rust/issues/107540
2024-07-29 07:11:16 +02:00
Matthias Krüger d573743779
Rollup merge of #128055 - workingjubilee:deny-unsafe-ops-in-sys-personality-dwarf-eh, r=Amanieu
std: unsafe-wrap personality::dwarf::eh

Moves the forbiddance up a little. This is another largely whitespace diff, except for hoisting some variable declarations to allow enclosing the `unsafe {}` scope fully and make it clearer where the bounds of some temporaries are.
2024-07-29 07:11:15 +02:00
Matthias Krüger 1a9f91a43e
Rollup merge of #109174 - soerenmeier:cursor_fns, r=dtolnay
Replace `io::Cursor::{remaining_slice, is_empty}`

This is a late follow up to the concerns raised in https://github.com/rust-lang/rust/issues/86369.

https://github.com/rust-lang/rust/issues/86369#issuecomment-953096691
> This API seems focussed on the `Read` side of things. When `Seek`ing around and `Write`ing data, `is_empty` becomes confusing and `remaining_slice` is not very useful. When writing, the part of the slice before the cursor is much more interesting. Maybe we should have functions for both? Or a single function that returns both slices? (If we also have a `mut` version, a single function would be useful to allow mutable access to both sides at once.)

New feature name: `cursor_remaining` > `cursor_split`.
Added functions:
```rust
fn split(&self) -> (&[u8], &[u8]);
// fn before(&self) -> &[u8];
// fn after(&self) -> &[u8];
fn split_mut(&mut self) -> (&mut [u8], &mut [u8]);
// fn before_mut(&mut self) -> &mut [u8];
// fn after_mut(&mut self) -> &mut [u8];
```

A question was raised in https://github.com/rust-lang/rust/issues/86369#issuecomment-927124211 about whether to return a lifetime that would reflect the lifetime of the underlying bytes (`impl Cursor<&'a [u8]> { fn after(&self) -> &'a [u8] }`). The downside of doing this would be that it would not be possible to implement these functions generically over `T: AsRef<[u8]>`.

## Update
Based on the review, before* and after* methods where removed.
2024-07-29 07:11:13 +02:00
Nicholas Bishop ecf2963baf Update compiler_builtins to 0.1.114
The `weak-intrinsics` feature was removed from compiler_builtins in
https://github.com/rust-lang/compiler-builtins/pull/598, so dropped the
`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.

In https://github.com/rust-lang/compiler-builtins/pull/593, some
builtins for f16/f128 were added. These don't work for all compiler
backends, so add a `compiler-builtins-no-f16-f128` feature and disable
it for cranelift and gcc. Also disable it for LLVM targets that don't
support it.
2024-07-28 20:43:07 -04:00
Miguel Ojeda dc815df1e1 Warn on `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`
They are all clean now, so enable the lint to keep them clean going forward.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29 00:58:45 +02:00
Miguel Ojeda cf87203f48 Remove spurious backticks detected by `rustdoc::unescaped_backticks`
There are only 3 cases across the crates rendered in the website (`core`,
`alloc`, `std`, `proc_macro` and `test`), and they are all in `core`.

Clean them up, so that the lint can be enabled in the next commit.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29 00:57:08 +02:00
Nicholas Nethercote 84ac80f192 Reformat `use` declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Sören Meier 10da5553a8 Replace `io::Cursor::{remaining_slice, is_empty}` with `io::Cursor::{split, split_mut}` 2024-07-28 21:51:57 +02:00
Mark Rousskov 5eca36d27a step cfg(bootstrap) 2024-07-28 14:46:29 -04:00
Mark Rousskov e8644f85b8 Update CURRENT_RUSTC_VERSION 2024-07-28 14:46:29 -04:00
Daria Sukhonina 0a5a84ee34 Add forbid(unsafe_op_in_unsafe_fn) 2024-07-28 21:10:59 +03:00
Guillaume Gomez eeb76ccaf0
Rollup merge of #128240 - mbrubeck:patch-3, r=joboet
Add links from `assert_eq!` docs to `debug_assert_eq!`, etc.

This adds information and links from the docs for the following macros to their debug-only versions:

* `assert_eq!`
* `assert_ne!`
* `assert_matches!`

This matches the existing documentation for the `assert!` macro.
2024-07-28 20:07:46 +02:00
Guillaume Gomez ee5956fd8a
Rollup merge of #128228 - slanterns:const_waker, r=dtolnay,oli-obk
Stabilize `const_waker`

Closes: https://github.com/rust-lang/rust/issues/102012.

For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under https://github.com/rust-lang/rust/issues/102012 from the beginning IMO.)~~ reused their own feature gates as suggested by ``@tgross35.``

``@rustbot`` label: +T-libs-api

r? libs-api
2024-07-28 20:07:46 +02:00
Guillaume Gomez 0e45047e81
Rollup merge of #128103 - folkertdev:unsigned-int-is-multiple-of, r=Amanieu
add `is_multiple_of` for unsigned integer types

tracking issue: https://github.com/rust-lang/rust/issues/128101

This adds the `.is_multiple_of` method on unsigned integers.

Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise.

This function is equivalent to `self % rhs == 0`, except that it will not panic for `rhs == 0`. Instead, `0.is_multiple_of(0) == true`, and for any non-zero `n`, `n.is_multiple_of(0) == false`.
2024-07-28 20:07:45 +02:00
Guillaume Gomez 506a6317be
Rollup merge of #127765 - bitfield:fix_stdlib_doc_nits, r=dtolnay
Fix doc nits

Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo"), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits.
2024-07-28 20:07:44 +02:00
Daria Sukhonina 352707da76 fix: psvita's std code 2024-07-28 21:07:38 +03:00
Amanieu d'Antras 4f78f9fbb0 Force LLVM to use CMOV for binary search
Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs
into branches if it comes from a `select` marked with an `unpredictable`
metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits
such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-28 17:24:57 +01:00
Slanterns 0a6ebbaf2e
stabilize const_waker 2024-07-28 22:31:13 +08:00
Ken Micklas 0468983eae Add missing periods on `BTreeMap` cursor `peek_next` docs 2024-07-28 15:28:35 +01:00
Ken Micklas 9b165a1600 Implement cursors for `BTreeSet` 2024-07-28 15:25:40 +01:00
Wiktor Przetacznik 3d7aa163d6
Update NonNull::align_offset quarantees
Update NonNull::align_offset quarantees, keeping it in sync with ptr::align_offset
2024-07-28 16:08:08 +02:00
Jiahao XU 649b4310a3
Enable `std::io::copy` specialisation for `std::pipe::{PipeReader, PipeWriter}`
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2024-07-28 22:20:01 +10:00
Matthias Krüger 32f6534c91
Rollup merge of #128282 - pitaj:nonzero_bitwise, r=workingjubilee
bitwise and bytewise methods on `NonZero`

Implementation for `nonzero_bitwise`
Tracking issue #128281
ACP https://github.com/rust-lang/libs-team/issues/413
2024-07-28 08:57:18 +02:00
Matthias Krüger 99204047c9
Rollup merge of #128279 - slanterns:is_sorted, r=dtolnay
Stabilize `is_sorted`

Closes: https://github.com/rust-lang/rust/issues/53485.

~~Question: does~~ 8fe0c753f2/compiler/rustc_lint_defs/src/builtin.rs (L1986-L1994) ~~need a new example?~~
edit: It causes a test failure and needs to be changed anyway.

``@rustbot`` label: +T-libs-api

r? libs-api
2024-07-28 08:57:17 +02:00
Slanterns ec0b354092
stabilize `is_sorted` 2024-07-28 03:11:54 +08:00
Peter Jaszkowiak c9e408e3f8 bitwise and bytewise methods on `NonZero` 2024-07-27 13:06:03 -06:00
Trevor Gross 2b58d8c08c
Rollup merge of #128259 - sunshowers:msg-nosignal, r=Mark-Simulacrum
[illumos/solaris] set MSG_NOSIGNAL while writing to sockets

Both these platforms have MSG_NOSIGNAL available, and we should set it for socket writes in the event that the SIGPIPE handler has been reset to SIG_DFL (i.e. terminate the process).

I've verified via a quick program at
https://github.com/sunshowers/msg-nosignal-test/ that even when the SIGPIPE handler is reset to SIG_DFL, writes to closed TCP sockets now error out with EPIPE. (Under ordinary circumstances UDP writes won't cause MSG_NOSIGNAL.)

However, I couldn't find any existing tests which verified the MSG_NOSIGNAL behavior.
2024-07-27 13:32:57 -04:00
Trevor Gross 51734a8a6d
Rollup merge of #125897 - RalfJung:from-ref, r=Amanieu
from_ref, from_mut: clarify documentation

This was brought up [here](https://github.com/rust-lang/rust/issues/56604#issuecomment-2143193486). The domain of quantification is generally always constrained by the type in the type signature, and I am not sure it's always worth spelling that out explicitly as that makes things exceedingly verbose. But since this was explicitly brought up, let's clarify.
2024-07-27 13:32:56 -04:00
Lukas Bergdoll 00ce238885 Improve panic sections for sort*, sort_unstable* and select_nth_unstable*
- Move panic information into # Panics section
- Fix mentions of T: Ord that should be compare
- Add missing information
2024-07-27 16:48:42 +02:00
Lukas Bergdoll 644550f3de Improve panic message and surrounding documentation for Ord violations
The new sort implementations have the ability to
detect Ord violations in many cases. This commit
improves the message in a way that should help
users realize what went wrong in their program.
2024-07-27 16:47:10 +02:00
bors ad3c5a3301 Auto merge of #128255 - stepancheg:doc-shl, r=scottmcm
Document 0x10.checked_shl(BITS - 1) does not overflow

Not obvious.
2024-07-27 07:11:32 +00:00
ltdk 0b99720497 Okay, I guess I have to give these a different feature name 2024-07-27 02:48:55 -04:00
ltdk 50835bf194 impl Default for collection iterators that don't already have it 2024-07-27 02:04:32 -04:00
bors a526d7ce45 Auto merge of #127946 - tgross35:fmt-builders-set-result, r=cuviper
Always set `result` during `finish()` in debug builders

Most functions for format builders set `self.result` after writing strings. This ensures that any further writing fails immediately rather than trying to write again.

A few `.finish()` methods and the `.finish_non_exhaustive` did have this same behavior, so update the remaining `.finish()` methods to make it consistent here.
2024-07-27 02:26:30 +00:00
Rain 50d127e6ec [illumos/solaris] set MSG_NOSIGNAL while writing to sockets
Both these platforms have MSG_NOSIGNAL available, and we should set it for
socket writes in the event that the SIGPIPE handler has been reset to SIG_DFL
(i.e. terminate the process).

I've verified via a quick program at
https://github.com/sunshowers/msg-nosignal-test/ that even when the SIGPIPE
handler is reset to SIG_DFL, writes to closed sockets now error out with EPIPE.
(Under ordinary circumstances UDP writes won't cause MSG_NOSIGNAL.)
2024-07-27 02:10:24 +00:00
Stepan Koltsov 723336d835 Document int.checked_shl(BITS - 1)
Not obvious.
2024-07-27 00:23:05 +01:00
Trevor Gross 8385f3b7ee
Rollup merge of #128235 - harryscholes:fix-iterator-filter-docs, r=tgross35
Fix `Iterator::filter` docs

Small fix to add code formatting around `Iterator::filter` `true` return type
2024-07-26 19:03:08 -04:00
Trevor Gross 86721a4c90
Rollup merge of #124941 - Skgland:stabilize-const-int-from-str, r=dtolnay
Stabilize const `{integer}::from_str_radix` i.e. `const_int_from_str`

This PR stabilizes the feature `const_int_from_str`.

- ACP Issue: rust-lang/libs-team#74
- Implementation PR: rust-lang/rust#99322
- Part of Tracking Issue: rust-lang/rust#59133

API Change Diff:

```diff
impl {integer} {
- pub       fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
+ pub const fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
}

impl ParseIntError {
- pub       fn kind(&self) -> &IntErrorKind;
+ pub const fn kind(&self) -> &IntErrorKind;
}
```
This makes it easier to parse integers at compile-time, e.g.
the example from the Tracking Issue:

```rust
env!("SOMETHING").parse::<usize>().unwrap()
```

could now be achived  with

```rust
match usize::from_str_radix(env!("SOMETHING"), 10) {
  Ok(val) => val,
  Err(err) => panic!("Invalid value for SOMETHING environment variable."),
}
```

rather than having to depend on a library that implements or manually implement the parsing at compile-time.

---

Checklist based on [Libs Stabilization Guide - When there's const involved](https://std-dev-guide.rust-lang.org/development/stabilization.html#when-theres-const-involved)

I am treating this as a [partial stabilization](https://std-dev-guide.rust-lang.org/development/stabilization.html#partial-stabilizations) as it shares a tracking issue (and is rather small), so directly opening the partial stabilization PR for the subset (feature `const_int_from_str`) being stabilized.

- [x] ping Constant Evaluation WG
- [x] no unsafe involved
- [x] no `#[allow_internal_unstable]`
- [ ] usage of `intrinsic::const_eval_select` rust-lang/rust#124625 in `from_str_radix_assert` to change the error message between compile-time and run-time
- [ ] [rust-labg/libs-api FCP](https://github.com/rust-lang/rust/pull/124941#issuecomment-2207021921)
2024-07-26 19:03:04 -04:00
Matt Brubeck 1c64fd3be8 Add links from `assert_eq!` docs to `debug_assert_eq!`, etc.
This adds information and links from the docs for the following macros to their debug-only versions:

* `assert_eq!`
* `assert_ne!`
* `assert_matches!`

This matches the existing documentation for the `assert!` macro.
2024-07-26 12:17:10 -07:00
Trevor Gross cc9da0b2ce Always set `result` during `finish()` in debug builders
Most functions for format builders set `self.result` after writing
strings. This ensures that any further writing fails immediately rather
than trying to write again.

A few `.finish()` methods did have this same behavior, so make it
consistent here.
2024-07-26 13:37:20 -04:00
harryscholes 130ce490f5 Fix docs 2024-07-26 16:09:17 +01:00
bors 2d5a628a1d Auto merge of #128165 - saethlin:optimize-clone-shims, r=compiler-errors
Let InstCombine remove Clone shims inside Clone shims

The Clone shims that we generate tend to recurse into other Clone shims, which gets very silly very quickly. Here's our current state: https://godbolt.org/z/E69YeY8eq

So I've added InstSimplify to the shims optimization passes, and improved `is_trivially_pure_clone_copy` so that it can delete those calls inside the shim. This makes the shim way smaller because most of its size is the required ceremony for unwinding.

This change also completely breaks the UI test added for https://github.com/rust-lang/rust/issues/104870. With this PR, that program ICEs in MIR type checking because `is_trivially_pure_clone_copy` and the trait solver disagree on whether `*mut u8` is `Copy`. And adding the requisite `Copy` impl to make them agree makes the test not generate any diagnostics. Considering that I spent most of my time on this PR fixing `#![no_core]` tests, I would prefer to just delete this one. The maintenance burden of `#![no_core]` is uniquely high because when they break they tend to break in very confusing ways.

try-job: x86_64-mingw
2024-07-26 13:13:04 +00:00
John Arundel a19472a93e Fix doc nits
Many tiny changes to stdlib doc comments to make them consistent (for example
"Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph
breaks, backticks for monospace style, and other minor nits.

https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-26 13:26:33 +01:00
Trevor Gross 97eade42f7
Rollup merge of #128170 - saethlin:clone-fn, r=compiler-errors
Make Clone::clone a lang item

I want to absorb all the logic for picking whether an Instance is LocalCopy or GloballyShared into one place. As part of this, I wanted to identify Clone shims inside `cross_crate_inlinable` and found that rather tricky. `@compiler-errors` suggested that I add a lang item for `Clone::clone` because that would produce other cleanups in the compiler.

That sounds good to me, but I have looked and I've only been able to find one.

r? compiler-errors
2024-07-26 02:20:31 -04:00
Matthias Krüger d87fa5e788
Rollup merge of #128211 - juliusl:pr/align-change-time, r=tgross35
fix: compilation issue w/ refactored type

Fixes a compilation issue related to #121478
2024-07-26 00:57:24 +02:00
Matthias Krüger ba990ae8af
Rollup merge of #128150 - BoxyUwU:std_only_sized_const_params, r=workingjubilee
Stop using `unsized_const_parameters` in core/std

`feature(unsized_const_parameters)` is an incomplete feature and should not be used by core/std as it makes it can make it significantly harder to evolve the feature. It also just generally opens the possibility of introducing bugs on stable through std's backdoor.

The only usage of this feature in std is the `simd_shuffle_intrinsic` added in #119213. It doesn't seem to be used anywhere as far as I can tell so it is removed in this PR. All tests and codegen logic etc have been kept however.

r? `@workingjubilee`
2024-07-26 00:57:22 +02:00
Matthias Krüger ab2dd3aeb9
Rollup merge of #127950 - nnethercote:rustfmt-skip-on-use-decls, r=cuviper
Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.

`use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it.

This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it.

r? `@cuviper`
2024-07-26 00:57:21 +02:00
Ben Kimock f4f57bfccb Make Clone::clone a lang item 2024-07-25 18:46:07 -04:00
Julius Liu e141b07164 fix: compilation issue w/ refactored type 2024-07-25 15:27:20 -07:00
Ben Kimock a7d57aa7c8 Let InstCombine remove Clone shims inside Clone shims
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2024-07-25 15:14:42 -04:00
Boxy 8174f9b44b Stop using `unsized_const_parameters` in core/std 2024-07-25 19:47:21 +01:00
bors aa877bc71c Auto merge of #128195 - matthiaskrgr:rollup-195dfdf, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #126908 (Use Cow<'static, str> for InlineAsmTemplatePiece::String)
 - #127999 (Inject arm32 shims into Windows metadata generation)
 - #128137 (CStr: derive PartialEq, Eq; add test for Ord)
 - #128185 (Fix a span error when parsing a wrong param of function.)
 - #128187 (Fix 1.80.0 version in RELEASES.md)
 - #128189 (Turn an unreachable code path into an ICE)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-25 18:05:00 +00:00
Matthias Krüger 512277ff70
Rollup merge of #128137 - GrigorenkoPV:cstr-derive, r=dtolnay
CStr: derive PartialEq, Eq; add test for Ord

While working on #128046, I've spotted a peculiarity: `CStr` has `PartialEq, Eq, PartialOrd, Ord` implemented manually and not derived.

While we can't derive `PartialOrd, Ord` (due to inner `[c_char]` being `[i8]` or `[u8]` on different platforms), we *can* derive `PartialEq, Eq` (I think), allowing as to remove `#[allow(clippy::derived_hash_with_manual_eq)]` as well.

(I really hope `c_char: Eq` on all platforms)
2024-07-25 18:57:58 +02:00
Matthias Krüger c96311bf8a
Rollup merge of #127999 - ChrisDenton:arm32, r=Amanieu
Inject arm32 shims into Windows metadata generation

I had been keen to eventually move to using windows-sys as a normal Cargo dependency. But for linking, compile times and other reasons that's unlikely to ever happen.

So if we're sticking with generated bindings then injecting any necessary missing type definitions (i.e. for the MS unsupported arm32) is simpler than defining whole functions ourselves just because we need to manually implement those types on a tier 3 platform. This also reduces the places we need to change when making changes to how we use `#[link]`.

r? libs
2024-07-25 18:57:57 +02:00
binarycat 3877a7bcf3 clarify interactions with MaybeUninit and UnsafeCell 2024-07-25 12:14:20 -04:00
binarycat 1073f97ed8 remove duplicate explanations of the ptr to ref conversion rules 2024-07-25 12:14:18 -04:00
binarycat 7643ea5b9c create a new section on pointer to reference conversion
also start deduplicating the docs that are getting moved to this
section.
2024-07-25 12:14:18 -04:00
Matthias Krüger 606c9fcb4d
Rollup merge of #128158 - workingjubilee:unsafe-wrap-personality-gcc, r=ChrisDenton
std: unsafe-wrap personality::gcc

Nothing seems obviously wrong with these implementations except for some unanswered questions. Admittedly, I don't want to burn excessive time on exceptional exception handlers. Thus this is mostly a brute-force syntactic wrapping and some comments where they seemed correct, creating another largely whitespace diff.

try-job: armhf-gnu
2024-07-25 16:48:20 +02:00
Matthias Krüger d1070df553
Rollup merge of #127300 - biabbas:fix_connect_timeout, r=tgross35
Fix connect timeout for non-linux targets, read readiness of socket connection, Read readiness to detect errors. `Fixes #127018`

Fixes #127018
Connect_timeout would call `poll` and check `pollfd.revents` for POLLHUP error, rather that checking readiness. This behavior was meant for Linux as it returns POLLHUP | POLLOUT | POLLERR in case of errors. But on targets that do not return POLLHUP in `pollfd.revents`, this would indicate a false success and result in this issue. To resolve this we will check readiness of socket using  `getsockopt():`  and return success from connect_timeout when there are no errors.
Changes were tested on Linux and an rtos.
![Screenshot 2024-07-04 105820](https://github.com/rust-lang/rust/assets/88673422/5ef5a87f-f2af-4fb7-98da-7612d5e27e9a)
Thank you.
2024-07-25 16:48:19 +02:00
Pavel Grigorenko cf9816c17e CStr: derive PartialEq, Eq; add test for Ord 2024-07-25 14:18:40 +03:00
B I Mohammed Abbas 17b4fbc388 In connect timeout, read readiness of socket for vxworks. Check pollhup or pollerr for refused connections in linux 2024-07-25 15:11:26 +05:30
Jubilee Young c9cd4a6853 std: update comments on gcc personality fn 2024-07-24 16:17:52 -07:00
Jubilee Young 2c7ae388b3 std: unsafe-wrap gcc::rust_eh_personality and impl 2024-07-24 16:17:52 -07:00
Matthias Krüger d146ecdcb9
Rollup merge of #128135 - joboet:reduplicate_tls, r=tgross35
std: use duplicate thread local state in tests

With rust-lang/miri#3739 merged, the deduplication hack is no longer necessary.
2024-07-24 22:22:18 +02:00
Matthias Krüger 07947f3773
Rollup merge of #128046 - GrigorenkoPV:90435, r=tgross35
Fix some `#[cfg_attr(not(doc), repr(..))]`

Now that #90435 seems to have been resolved.
2024-07-24 22:22:17 +02:00
Matthias Krüger ed5dfed535
Rollup merge of #126548 - rik86189:issue-88264-fix, r=tgross35
Improved clarity of documentation for std::fs::create_dir_all

Closes #88264
2024-07-24 22:22:15 +02:00
Matthias Krüger 7fac549ff1
Rollup merge of #126042 - davidzeng0:master, r=Amanieu
Implement `unsigned_signed_diff`

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
Implements https://github.com/rust-lang/rust/issues/126041
2024-07-24 22:22:15 +02:00
Matthias Krüger f3a7c3fd3b
Rollup merge of #128131 - ChrisDenton:stuff, r=workingjubilee
Import `c_void` rather than using the full path

Follow up to #128092. As requested, this imports `c_void` in more places. I also fixed up some imports to use `core` for core types instead of `crate`. While that is not strictly necessary, I think ideally things in `sys/pal` should only depend on itself or core so that the code is less spaghetti. We're far away from that ideal at the moment but I can at least try to slowly move in that direction.

Also this forbids `unsafe_op_in_unsafe_fn` for library/std/src/sys/pal/windows by fixing up the remaining unsafe bits that are just punting their unsafe requirements onto the caller of the `unsafe` function (or definition macro).

<!--
r? workingjubilee
-->
2024-07-24 18:00:40 +02:00
Matthias Krüger e342efe545
Rollup merge of #128120 - compiler-errors:async-fn-name, r=oli-obk
Gate `AsyncFn*` under `async_closure` feature

T-lang has not come to a consensus on the naming of async closure callable bounds, and as part of allowing the async closures RFC merge, we agreed to place `AsyncFn` under the same gate as `async Fn` so that these syntaxes can be evaluated in parallel.

See https://github.com/rust-lang/rfcs/pull/3668#issuecomment-2246435537

r? oli-obk
2024-07-24 18:00:40 +02:00
Matthias Krüger 34abb9647c
Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=Amanieu
Replace some `mem::forget`'s with `ManuallyDrop`

              > but I would like to see a larger effort to replace all uses of `mem::forget`.

_Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_

So,
r? `@saethlin`

Sorry, I have finished writing all of this before I got your response.
2024-07-24 18:00:39 +02:00
Matthias Krüger ce523d65e0
Rollup merge of #127480 - biabbas:vxworks, r=workingjubilee
Fix build failure on vxworks #127084

PR to address issue #127084 .
1. Skip `reset_segpipe` for vxworks
2. Return unimplemented error for vxworks from settimes and lchown
3. Temporarily skip dirfd for vxworks
4. Add allow unused unsafe on read_at and write_at functions in unix/fs.rs
5. Using cfg disable ON_BROKEN_PIPE_FLAG_USED and on_broken_pipe_flag_used() for vxworks
6. Remove old crate::syscommon:🧵:min_stack() reference from process_vxworks.rs and update to set stack size of rtpthread

Thank you.
2024-07-24 18:00:38 +02:00
Matthias Krüger 720c6f19b7
Rollup merge of #127252 - fitzgen:edge-cases-for-bitwise-operations, r=m-ou-se
Add edge-case examples to `{count,leading,trailing}_{ones,zeros}` methods

Some architectures (i386) do not define a "count leading zeros" instruction, they define a "find first set bit" instruction (`bsf`) whose result is undefined when given zero (ie none of the bits are set). Of this family of bitwise operations, I always forget which of these things is potentially undefined for zero, and I'm also not 100% sure that Rust provides a hard guarantee for the results of these methods when given zero. So I figured there are others who have these same uncertainties, and it would be good to resolve them and answer the question via extending these doc examples/tests.

See https://en.wikipedia.org/wiki/Find_first_set#Hardware_support for more info on i386 and `bsf` on zero.
2024-07-24 18:00:36 +02:00
Matthias Krüger 130d15e23e
Rollup merge of #126152 - RalfJung:size_of_val_raw, r=saethlin
size_of_val_raw: for length 0 this is safe to call

For motivation, see https://github.com/rust-lang/unsafe-code-guidelines/issues/465, specifically around [here](https://github.com/rust-lang/unsafe-code-guidelines/issues/465#issuecomment-2136401114).
Cc `@rust-lang/opsem`
2024-07-24 18:00:35 +02:00
rik86189 dfb3fb32ce Improved clarity of documentation for std::fs::create_dir_all 2024-07-24 14:23:29 +02:00
joboet a4dd0d6899
std: use duplicate thread local state in tests
With rust-lang/miri#3739 merged, the deduplication hack is no longer necessary.
2024-07-24 14:13:57 +02:00
Chris Denton 7cd25b1b11
Forbid unsafe_op_in_unsafe_fn in sys/pal/windows 2024-07-24 08:28:47 +00:00
Chris Denton 9b87fbc3e5
Import `core::ffi::c_void` in more places 2024-07-24 08:27:22 +00:00
B I Mohammed Abbas 0ea5694c7c Add chroot unsupported implementation for VxWorks 2024-07-24 09:59:04 +05:30
Matthias Krüger 888422880c
Rollup merge of #128106 - hallfox:patch-1, r=ChrisDenton
Fix return type of FileAttr methods on AIX target

At some point it seems `SystemTime::new` changed from returning `SystemTime` to `io::Result<SystemTime>`. This seems to have been addressed on other platforms, but was never changed for AIX.

This was caught by running
```
python3 x.py build --host x86_64-unknown-linux-gnu --target powerpc64-ibm-aix
```
2024-07-24 05:05:36 +02:00
Matthias Krüger ee77dda778
Rollup merge of #128092 - ChrisDenton:wrappers, r=workingjubilee
Remove wrapper functions from c.rs

I'd like for the windows `c.rs` just to contain the basic platform definitions and not anything higher level unless absolutely necessary. So this removes some wrapper functions that weren't really necessary in any case. The functions are only used in a few places which themselves are relatively thin wrappers. The "interesting" bit is that we had an `AlertableIoFn` that abstracted over `ReadFileEx` and `WriteFileEx`. I've replaced this with a closure.

Also I removed an `#[allow(unsafe_op_in_unsafe_fn)]` while I was moving things around.
2024-07-24 05:05:34 +02:00
Matthias Krüger e56e886796
Rollup merge of #128043 - safinaskar:primitive, r=workingjubilee
Docs for core::primitive: mention that "core" can be shadowed, too, so we should write "::core"

``@rustbot`` label +A-docs
2024-07-24 05:05:33 +02:00
Matthias Krüger 6f696257cb
Rollup merge of #127481 - a1phyr:pattern_gat, r=Amanieu
Remove generic lifetime parameter of trait `Pattern`

Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway.

cc #27721
2024-07-24 05:05:32 +02:00
Matthias Krüger d6080a1e2f
Rollup merge of #126770 - wr7:master, r=Amanieu
Add elem_offset and related methods

Implementation of #126769
2024-07-24 05:05:31 +02:00
Matthias Krüger 0666eee2a1
Rollup merge of #125962 - Coekjan:const-binary-heap, r=Amanieu
Update tracking issue for `const_binary_heap_new_in`

This PR updates the tracking issue of `const_binary_heap_new_in` feature:
- Old issue: #112353
- New issue: #125961
2024-07-24 05:05:30 +02:00
bors f751af4d78 Auto merge of #127153 - NobodyXu:pipe, r=ChrisDenton
Initial implementation of anonymous_pipe API

ACP completed in rust-lang/libs-team#375
Tracking issue: #127154

try-job: x86_64-msvc
try-job: i686-mingw
2024-07-24 00:03:14 +00:00
Michael Goulet b82f878f03 Gate AsyncFn* under async_closure feature 2024-07-23 19:56:06 -04:00
wr7 557210c5c7 Add elem_offset and related methods 2024-07-23 18:22:29 -05:00
Askar Safin b8f7ed2394
library/core/src/primitive.rs: small doc fix
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-07-23 23:11:26 +03:00
Taylor Foxhall 1f59a8030d
Fix return type of FileAttr methods on AIX target
At some point it seems `SystemTime::new` changed from returning `SystemTime` to `io::Result<SystemTime>`. This seems to have been addressed on other platforms, but was never changed for AIX.

This was caught by running 
```
python3 x.py build --host x86_64-unknown-linux-gnu --target powerpc64-ibm-aix
```
2024-07-23 12:36:52 -04:00
Folkert aded725d6b
add `is_multiple_of` for unsigned integer types 2024-07-23 18:02:13 +02:00
Jiahao XU c9c8a14884
Initial implementation of anonymous_pipe
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2024-07-23 23:13:56 +10:00
B I Mohammed Abbas 786ad3d3ae Update process vxworks, set default stack size of 256 Kib for vxworks. User can set the stack size using RUST_MIN_STACK, with min size of libc::PTHREAD_STACK_MIN(4kib) 2024-07-23 16:58:00 +05:30
Matthias Krüger f8373adcda
Rollup merge of #128089 - workingjubilee:commonly-wrapped-to-make-safe, r=ChrisDenton
std: Unsafe-wrap actually-universal platform code

Every platform compiles the unsafe parts of this code, so just clean this up. Almost entirely a whitespace diff.
2024-07-23 13:06:57 +02:00
Matthias Krüger 1b4b0e9a4d
Rollup merge of #125834 - workingjubilee:weaken-thir-unsafeck-for-addr-of-static-mut, r=compiler-errors
treat `&raw (const|mut) UNSAFE_STATIC` implied deref as safe

Fixes rust-lang/rust#125833

As reported in that and related issues, `static mut STATIC_MUT: T` is very often used in embedded code, and is in many ways equivalent to `static STATIC_CELL: SyncUnsafeCell<T>`. The Rust expression of `&raw mut STATIC_MUT` and `SyncUnsafeCell::get(&STATIC_CELL)` are approximately equal, and both evaluate to `*mut T`. The library function is safe because it has *declared itself* to be safe. However, the raw ref operator is unsafe because all uses of `static mut` are considered unsafe, even though the static's value is not used by this expression (unlike, for example, `&STATIC_MUT`).

We can fix this unnatural difference by simply adding the proper exclusion for the safety check inside the THIR unsafeck, so that we do not declare it unsafe if it is not.

While the primary concern here is `static mut`, this change is made for all instances of an "unsafe static", which includes a static declared inside `extern "abi" {}`. Hypothetically, we could go as far as generalizing this to all instances of `&raw (const|mut) *ptr`, but today we do not, as we have not actually considered the range of possible expressions that use a similar encoding. We do not even extend this to thread-local equivalents, because they have less clear semantics.
2024-07-23 13:06:54 +02:00
Chris Denton 8c3ce60e30
Remove wrapper functions from c.rs 2024-07-23 10:51:24 +00:00
Jubilee Young e4d89bc802 std: Unsafe-wrap backtrace code held in-common 2024-07-23 01:17:26 -07:00
Jubilee Young ed809e9b79 std: Unsafe-wrap alloc code held in-common 2024-07-23 01:14:39 -07:00
B I Mohammed Abbas 5c9f3762d0 Cfg disable on_broken_pipe_flag_used() for vxworks 2024-07-23 10:55:54 +05:30
B I Mohammed Abbas a598ca0f86 Disable dirfd for vxworks, Return unsupported error from set_times and lchown for vxworks 2024-07-23 10:52:53 +05:30
B I Mohammed Abbas 2561d91983 Allow unused unsafe for vxworks in read_at and write at 2024-07-23 10:47:01 +05:30
Askar Safin b2e5ccef5e Docs for core::primitive: mention that "core" can be shadowed, too, so we should write "::core" 2024-07-23 05:14:16 +03:00
Jubilee Young bf454afcaa library: vary unsafety in bootstrapping for SEH 2024-07-22 14:54:36 -07:00
Jubilee Young e2137a2487 std: unsafe-wrap personality::dwarf::eh
In so doing, move the forbid up to the top of personality::dwarf
2024-07-22 11:22:34 -07:00
Ian Jackson c404406a87 LocalWaker docs: Make long-ago omitted but probably intended changes
In 6f8a944ba4, titled

  Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.

the summary line for Waker was changed:

  -    /// Creates a new `Waker` that does nothing when `wake` is called.
  +    /// Returns a reference to a `Waker` that does nothing when used.

and the sentence about clone was added.

LocalWaker's docs were not changed, even though the types were, but
there is no explanation for why not.  It seems like it was simply a
slip induced by the clone-and-hack.
2024-07-22 18:07:28 +01:00
Ian Jackson b18c7d85a9 Docs for Waker and LocalWaker: Add cross-refs in comment 2024-07-22 18:07:28 +01:00
Trevor Gross 8ee5e271ef
Rollup merge of #128008 - weiznich:fix/121521, r=lcnr
Start using `#[diagnostic::do_not_recommend]` in the standard library

This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in #121521

The result in not perfect yet, but at least the `Yeet` suggestion is not shown anymore. I would consider that as a minor improvement.
2024-07-22 11:40:21 -05:00
许杰友 Jieyou Xu (Joe) 7d81e092a1
Rollup merge of #127996 - ian-h-chamberlain:fix/horizon-warnings-unsafe-in-unsafe, r=tgross35
Clean up warnings + `unsafe_op_in_unsafe_fn` when building std for armv6k-nintendo-3ds

See #127747

ping `@AzureMarker` `@Meziu`

I could only find one instance needing an extra `unsafe` that was not also shared with many other `unix` targets (presumably these will get covered in larger sweeping changes, I didn't want to introduce churn that would potentially conflict with those). The one codepath I found is shared with `vita` however, so also pinging `@nikarh` `@pheki` `@zetanumbers` just to make sure they're aware of this change.

Also removed one unused import from `process_unsupported` which should simply fix the warning for any target that uses it.
2024-07-22 16:44:06 +08:00
许杰友 Jieyou Xu (Joe) 9f4039fcd5
Rollup merge of #127415 - AljoschaMeyer:master, r=dtolnay
Add missing try_new_uninit_slice_in and try_new_zeroed_slice_in

The methods for fallible slice allocation in a given allocator were missing from `Box`, which was an oversight according to https://github.com/rust-lang/wg-allocators/issues/130

This PR adds them as `try_new_uninit_slice_in` and `try_new_zeroed_slice_in`. I simply copy-pasted the implementations of `try_new_uninit_slice` and `try_new_zeroed_slice` and adusted doc comment, typings, and the allocator it uses internally.

Also adds missing punctuation to the doc comments of `try_new_uninit_slice` and `try_new_zeroed_slice`.

Related issue is https://github.com/rust-lang/rust/issues/32838 (Allocator traits and std::heap) *I think*. Also relevant is https://github.com/rust-lang/rust/issues/63291, but I did not add the corresponding `#[unstable]` proc macro, since `try_new_uninit_slice` and `try_new_zeroed_slice` are also not annotated with it.
2024-07-22 16:44:03 +08:00
Aljoscha Meyer 351fe27354
Use given allocator instad of Global 2024-07-22 08:17:46 +02:00
Georg Semmler 00da9fc961
Start using `#[diagnostic::do_not_recommend]` in the standard library
This commit starts using `#[diagnostic::do_not_recommend]` in the
standard library to improve some error messages. In this case we just
hide a certain nightly only impl as suggested in #121521
2024-07-22 07:29:59 +02:00
Jubilee 6af66e836f
Rollup merge of #127583 - Nilstrieb:invalid-utf8, r=joboet
Deal with invalid UTF-8 from `gai_strerror`

When the system is using a non-UTF-8 locale, the value will indeed not be UTF-8. That sucks for everyone involved, but is no reason for panic. We can "handle" this gracefully by just using from lossy, replacing the invalid UTF-8 with � and keeping the accidentally valid UTF-8. Good luck when debugging, but at least it's not a crash.

We already do this for `strerror_r`.

fixes #127563
2024-07-21 17:44:27 -07:00
Ian Chamberlain dba6b74dd8
Fix warnings when checking armv6k-nintendo-3ds
Also fix one instance of unsafe_op_in_unsafe_fn that's specific to
horizon + vita - most others should be common with other code.
2024-07-21 20:12:54 -04:00
Pavel Grigorenko b74f426e07 Fix some `#[cfg_attr(not(doc), repr(..))]`
Now that #90435 seems to have been resolved.
2024-07-22 01:10:06 +03:00
Trevor Gross 827970ebe9 Implement `debug_more_non_exhaustive`
Add a `.finish_non_exhaustive()` method to `DebugTuple`, `DebugSet`,
`DebugList`, and `DebugMap`. This indicates that the structures have
remaining items with `..`.

This implements the ACP at
<https://github.com/rust-lang/libs-team/issues/248>.
2024-07-21 12:05:02 -05:00
Trevor Gross 68fb25e2eb Make use of raw strings in `core::fmt::builders`
There are quite a few uses of escaped quotes. Turn these into raw
strings within documentation and tests to make things easier to read.
2024-07-21 12:05:02 -05:00
Nilstrieb ae42efc522 Deal with invalid UTF-8 from `gai_strerror`
When the system is using a non-UTF-8 locale, the value will indeed not
be UTF-8. That sucks for everyone involved, but is no reason for panic.
We can "handle" this gracefully by just using from lossy, replacing the
invalid UTF-8 with the ? and keeping the accidentally valid UTF-8.
Good luck when debugging, but at least it's not a crash.

We already do this for `strerror_r`.
2024-07-21 13:22:03 +02:00
David Carlier 468f9358f3
std:🧵 available_parallelism implementation for vxWorks proposal. 2024-07-21 09:52:21 +01:00
bors 9629b90b3f Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, r=compiler-errors
Forbid borrows and unsized types from being used as the type of a const generic under `adt_const_params`

Fixes #112219
Fixes #112124
Fixes #112125

### Motivation

Currently the `adt_const_params` feature allows writing `Foo<const N: [u8]>` this is entirely useless as it is not possible to write an expression which evaluates to a type that is not `Sized`. In order to actually use unsized types in const generics they are typically written as `const N: &[u8]` which *is* possible to provide a value of.

Unfortunately allowing the types of const parameters to contain references is non trivial (#120961) as it introduces a number of difficult questions about how equality of references in the type system should behave. References in the types of const generics is largely only useful for using unsized types in const generics.

This PR introduces a new feature gate `unsized_const_parameters` and moves support for `const N: [u8]` and `const N: &...` from `adt_const_params` into it. The goal here hopefully is to experiment with allowing `const N: [u8]` to work without references and then eventually completely forbid references in const generics.

Splitting this out into a new feature gate means that stabilization of `adt_const_params` does not have to resolve #120961 which is the only remaining "big" blocker for the feature. Remaining issues after this are a few ICEs and naming bikeshed for `ConstParamTy`.

### Implementation

The implementation is slightly subtle here as we would like to ensure that a stabilization of `adt_const_params` is forwards compatible with any outcome of `unsized_const_parameters`. This is inherently tricky as we do not support unstable trait implementations and we determine whether a type is valid as the type of a const parameter via a trait bound.

There are a few constraints here:
- We would like to *allow for the possibility* of adding a `Sized` supertrait to `ConstParamTy` in the event that we wind up opting to not support unsized types and instead requiring people to write the 'sized version', e.g. `const N: [u8; M]` instead of `const N: [u8]`.
- Crates should be able to enable `unsized_const_parameters` and write trait implementations of `ConstParamTy` for `!Sized` types without downstream crates that only enable `adt_const_params` being able to observe this (required for std to be able to `impl<T> ConstParamTy for [T]`

Ultimately the way this is accomplished is via having two traits (sad), `ConstParamTy` and `UnsizedConstParamTy`. Depending on whether `unsized_const_parameters` is enabled or not we change which trait is used to check whether a type is allowed to be a const parameter.

Long term (when stabilizing `UnsizedConstParamTy`) it should be possible to completely merge these traits (and derive macros), only having a single `trait ConstParamTy` and `macro ConstParamTy`.

Under `adt_const_params` it is now illegal to directly refer to `ConstParamTy` it is only used as an internal impl detail by `derive(ConstParamTy)` and checking const parameters are well formed. This is necessary in order to ensure forwards compatibility with all possible future directions for `feature(unsized_const_parameters)`.

Generally the intuition here should be that `ConstParamTy` is the stable trait that everything uses, and `UnsizedConstParamTy` is that plus unstable implementations (well, I suppose `ConstParamTy` isn't stable yet :P).
2024-07-21 05:36:21 +00:00
Matthias Krüger 8fe93c9bec
Rollup merge of #128005 - ChrisDenton:msvc-include, r=joboet
Remove _tls_used hack

All the MSVC targets use `target_thread_locals` (see the [base spec](1afc5fd042/compiler/rustc_target/src/spec/base/windows_msvc.rs (L34))) so this hack is no longer needed. The compiler will ensure that thread locals work properly.
2024-07-20 19:29:00 +02:00
Matthias Krüger b3d682c577
Rollup merge of #127734 - ChrisDenton:netc, r=Mark-Simulacrum
Windows: move BSD socket shims to netc

On Windows we need to alter a few types so that they can be used in the cross-platform socket code. Currently these alterations are spread throughout the `c` module with some more in the `netc` module.

Let's gather all our BSD compatibility shims in the `netc` module so it's all in one place and easier to discover.
2024-07-20 19:28:57 +02:00
Chris Denton af735f3bd3
Remove _tls_used hack 2024-07-20 12:37:36 +00:00
Matthias Krüger 6b9982d4fb
Rollup merge of #127873 - workingjubilee:forbid-unsafe-ops-for-kmc-solid, r=Amanieu
kmc-solid: `#![forbid(unsafe_op_in_unsafe_fn)]`

The path logic _should_ handle the forbiddance in the itron sources correctly, despite them being an "out-of-line" module.
2024-07-20 13:24:53 +02:00
Matthias Krüger 2ee3668ad5
Rollup merge of #127843 - workingjubilee:break-up-big-ass-stack-overflow-fn, r=joboet
unix: document unsafety for std `sig{action,altstack}`

I found many surprising elements here while trying to wrap a measly 5 functions with `unsafe`. I would rather not "just" mindlessly wrap this code with `unsafe { }`, so I decided to document it properly.

On Unix, this code covers the "create and setup signal handler" part of the stack overflow code, and serves as the primary safety boundary for the signal handler. It is rarely audited, very gnarly, and worth extra attention. It calls other unsafe functions defined in this module, but "can we correctly map the right memory, or find the right address ranges?" are separate questions, and get increasingly platform-specific. The question here is the more general "are we doing everything in the correct order, and setting up the handler in the correct way?"

As part of this audit, I noticed that we do some peculiar things that we should probably refrain from. However, I avoided making changes that I deemed might have a different final result in Rust programs. I did, however, reorder some events so that the signal handler is installed _after_ we install the alternate stack. We do not run much code between these events, but it is probably best if the timespan between the handler being available and the new stack being installed is 0 nanoseconds.
2024-07-20 13:24:53 +02:00
Chris Denton c629bfc9e1
Inject win arm32 shims into metadata generation 2024-07-20 08:21:26 +00:00
Matthias Krüger 4da2869bc7
Rollup merge of #127918 - ChrisDenton:thread-name-string, r=joboet
Safely enforce thread name requirements

The requirements for the thread name to be both UTF-8 and null terminated are easily enforced by a wrapper type so lets do that. The fact this used to be just a bare `CString` has tripped me up before because it was entirely safe to use a non UTF-8 `CString`.
2024-07-20 07:13:43 +02:00
Matthias Krüger bc86893a1a
Rollup merge of #123196 - Ayush1325:uefi-process, r=joboet
Add Process support for UEFI

UEFI does not have an actual process. However, it does provide methods to launch and execute another UEFI image. Having process support is important since it is possible to run rust test suit using `Command::output` and is the first step towards being able to run it for UEFI.

Here is an overview of how the support is implemented.

- We create a copy of the SystemTable. This is required since at least OVMF seems to crash if the original system table is modified.
- Stdout and Stderr pipe works by registering a new `simple_text_output` Protocol and pointing the child system table to use those.
- `Stdio::Inherit` just points the console to the current running image console which seems to work with even 3 levels of process.
- `spawn` is left unimplemented since it does not make sense for UEFI architecture. Additionally, since https://github.com/rust-lang/rust/pull/105458 was merged, the `spawn` and `output` implementations are completely independent.
2024-07-20 07:13:41 +02:00
Jubilee Young e9b3e9c7f4 std: forbid unwrapped unsafe in unsupported_backslash 2024-07-19 13:46:06 -07:00
Jubilee Young 1d83da8847 kmc-solid: forbid(unsafe_op_in_unsafe_fn) 2024-07-19 13:46:06 -07:00
bors ff4b39867e Auto merge of #127982 - matthiaskrgr:rollup-nzyvphj, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #127295 (CFI: Support provided methods on traits)
 - #127814 (`C-cmse-nonsecure-call`: improved error messages)
 - #127949 (fix: explain E0120 better cover cases when its raised)
 - #127966 (Use structured suggestions for unconstrained generic parameters on impl blocks)
 - #127976 (Lazy type aliases: Diagostics: Detect bivariant ty params that are only used recursively)
 - #127978 (Avoid ref when using format! for perf)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-19 18:40:33 +00:00
Matthias Krüger e28be0d168
Rollup merge of #127978 - nyurik:lib-refs, r=workingjubilee
Avoid ref when using format! for perf

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).  Inlining format args prevents accidental `&` misuse.
2024-07-19 20:03:58 +02:00
Yuri Astrakhan 91275b2c2b Avoid ref when using format! for perf
Clean up a few minor refs in `format!` macro, as it has a tiny perf
cost. A few more minor related cleanups.
2024-07-19 12:23:49 -04:00
Matthias Krüger 355cdd3bc1
Rollup merge of #126199 - ivan-shrimp:nonzero_isqrt, r=tgross35
Add `isqrt` to `NonZero<uN>`

Implements [#70887 (comment)](https://github.com/rust-lang/rust/issues/116226#issuecomment-2144225174), with the following signature:

```rust
impl NonZero<uN> {
    const fn isqrt(self) -> Self;
}
```

Unintended benefits include one fewer panicking branch in `ilog2` for LLVM to optimize away, and one fewer `assume_unchecked` as `NonZero` already does that.

The fast path for `self == 1` is dropped, but the current implementation is very slow anyways compared to hardware. Performance improvements can always come later.

(I didn't add the function to `NonZero<iN>`, since _every_ existing `NonZero` method is non-panicking, and it might be nice to leave it that way.)
2024-07-19 17:06:49 +02:00
Matthias Krüger 45e4e96385
Rollup merge of #112328 - juliusl:pr/windows-add-change-time, r=ChrisDenton
Feat. adding ext that returns change_time

Addresses #112327
2024-07-19 17:06:49 +02:00
Ayush Singh e2903989da
uefi: process: Fixes from PR
- Update system table crc32
- Fix unsound use of Box
- Free exit data
- Code improvements
- Introduce OwnedTable
- Update r-efi to latest version
- Use extended_varargs_abi_support for
  install_multiple_protocol_interfaces and
  uninstall_multiple_protocol_interfaces
- Fix comments
- Stub out args implementation

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:44:27 +05:30
Ayush Singh 56e2a57505
uefi: process: Final Touchups
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:45 +05:30
Ayush Singh c899e05457
uefi: process: Add CommandArgs support
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:45 +05:30
Ayush Singh 29c198c85f
uefi: process: Add support for args
Also fix stdio inherit

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:45 +05:30
Ayush Singh d44b3fb120
uefi: process Implement inherit
Only tested in 2 levels right now. Need args support for 3 levels

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:45 +05:30
Ayush Singh 725376567a
uefi: process: Add null protocol
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:45 +05:30
Ayush Singh 87d7a07f50
uefi: process: Add stderr support
Implement stderr support in similar fashion.

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:44 +05:30
Ayush Singh 6737a02a50
uefi: process: Add support to capture stdout
Use a custom simple_text_output protocol to capture output.

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:44 +05:30
Ayush Singh a8d7121e4a
uefi: Add process
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-07-19 17:43:37 +05:30
ivan-shrimp 90bba8beb5 improve safety comment 2024-07-19 19:16:33 +08:00
ivan-shrimp eaaed00ff5 add `NonZero<uN>::isqrt` 2024-07-19 18:10:41 +08:00
Nicholas Nethercote c5dadd0408 Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.
`use` declarations will be reformatted in #125443. Very rarely, there is
a desire to force a group of `use` declarations together in a way that
auto-formatting will break up. E.g. when you want a single comment to
apply to a group. #126776 dealt with all of these in the codebase,
ensuring that no comments intended for multiple `use` declarations would
end up in the wrong place. But some people were unhappy with it.

This commit uses `#[rustfmt::skip]` to create these custom `use` groups
in an idiomatic way for a few of the cases changed in #126776. This
works because rustfmt treats any `use` item annotated with
`#[rustfmt::skip]` as a barrier and won't reorder other `use` items
around it.
2024-07-19 13:26:48 +10:00
Jubilee 529fcbcd6d
unix: acquire-load NEED_ALTSTACK
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-18 15:24:40 -07:00
Jubilee Young c1740eee1e unix: Unsafe-wrap stack_overflow::{drop,make}_handler
Note that current_guard is probably not unsafe for future work.
2024-07-18 15:22:47 -07:00
Jubilee Young fa628ceaff unix: Unsafe-wrap stack_overflow::cleanup
Editorialize on the wisdom of this as we do.
2024-07-18 15:22:17 -07:00
Jubilee Young 357ba1f8ec unix: lift init of sigaltstack before sigaction
This is technically "not necessary", as we will "just" segfault instead
if we e.g. arrive inside the handler fn with the null altstack. However,
it seems incorrect to go about this hoping that segfaulting is okay,
seeing as how our purpose here is to mitigate stack overflow problems.

Make sure NEED_ALTSTACK syncs with PAGE_SIZE when we do.

Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-18 15:18:38 -07:00
Jubilee Young 9e354daf7b unix: Unsafe-wrap stack_overflow::signal_handler
sometimes a safety comment is a prayer.
avoid fuzzy provenance casts after deref.

Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-18 15:12:18 -07:00
Matthias Krüger c1bbe347c2
Rollup merge of #127594 - c6c7:fuchsia-status-code-match-arm, r=tmandry
Fuchsia status code match arm

Adds a match arm for the Fuchsia status code upon a process abort. An additional change moves the Windows status code down into the match arm itself instead of being defined as a constant elsewhere.

r​? tmandry
2024-07-18 23:05:21 +02:00
Chris Denton 9432955a01
Move ThreadName conversions to &cstr/&str 2024-07-18 19:53:09 +00:00
Chris Denton 8e4a9205e9
Style change 2024-07-18 18:10:36 +00:00
Chris Denton 939ee38304
Make `Thread::new_inner` a safe function 2024-07-18 17:33:52 +00:00
Matthias Krüger 6f7fa03a06
Rollup merge of #127748 - scottmcm:option_len, r=joboet
Use Option's discriminant as its size hint

I was looking at this in MIR after a question on discord, and noticed that it ends up with a switch in MIR (<https://rust.godbolt.org/z/3q4cYnnb3>), which it doesn't need because (as `Option::as_slice` uses) the discriminant is already the length.
2024-07-18 18:10:16 +02:00
Matthias Krüger f62aa415c3
Rollup merge of #124881 - Sp00ph:reentrant_lock_tid, r=joboet
Use ThreadId instead of TLS-address in `ReentrantLock`

Fixes #123458

`ReentrantLock` currently uses the address of a thread local variable as an ID that's unique across all currently running threads. This can lead to uninituitive behavior as in #123458 if TLS blocks get reused. This PR changes `ReentrantLock` to instead use the `ThreadId` provided by `std` as the unique ID. `ThreadId` guarantees uniqueness across the lifetime of the whole process, so we don't need to worry about reusing IDs of terminated threads. The main appeal of this PR is thus the possibility of changing the `ReentrantLock` API to guarantee that if a thread leaks a lock guard, no other thread may ever acquire that lock again.

This does entail some complications:
- previously, the only way to retrieve the current thread ID would've been using `thread::current().id()` which creates a temporary `Arc` and which isn't available in TLS destructors. As part of this PR, the thread ID instead gets cached in its own thread local, as suggested [here](https://github.com/rust-lang/rust/issues/123458#issuecomment-2038207704).
- `ThreadId` is always 64-bit whereas the current implementation uses a usize-sized ID. Since this ID needs to be updated atomically, we can't simply use a single atomic variable on 32 bit platforms. Instead, we fall back to using a (sound) seqlock on 32-bit platforms, which works because only one thread at a time can write to the ID. This seqlock is technically susceptible to the ABA problem, but the attack vector to create actual unsoundness has to be very specific:
  - You would need to be able to lock+unlock the lock exactly 2^31 times (or a multiple thereof) while a thread trying to lock it sleeps
  - The sleeping thread would have to suspend after reading one half of the thread id but before reading the other half
  - The teared result from combining the halves of the thread ID would have to exactly line up with the sleeping thread's ID

The risk of this occurring seems slim enough to be acceptable to me, but correct me if I'm wrong. This also means that the size of the lock increases by 8 bytes on 32-bit platforms, but this also shouldn't be an issue.

Performance wise, I did some crude testing of the only case where this could lead to real slowdowns, which is the case of locking a `ReentrantLock` that's already locked by the current thread. On both aarch64 and x86-64, there is (expectedly) pretty much no performance hit. I didn't have any 32-bit platforms to test the seqlock performance on, so I did the next best thing and just forced the 64-bit platforms to use the seqlock implementation. There, the performance degraded by ~1-2ns/(lock+unlock) on x86-64 and ~6-8ns/(lock+unlock) on aarch64, which is measurable but seems acceptable to me seeing as 32-bit platforms should be a small minority anyways.

cc `@joboet` `@RalfJung` `@CAD97`
2024-07-18 18:10:14 +02:00
Markus Everling fe89962237 Update `ReentrantLock` implementation, add `CURRENT_ID` thread local.
This changes `ReentrantLock` to use `ThreadId` for the thread ownership check instead of the address of a thread local. Unlike TLS blocks, `ThreadId` is guaranteed to be unique across the lifetime of the process, so if any thread ever terminates while holding a `ReentrantLockGuard`, no other thread may ever acquire that lock again.

On platforms with 64-bit atomics, this is a very simple change. On other platforms, the approach used is slightly more involved, as explained in the module comment.

This also adds a `CURRENT_ID` thread local in addition to the already existing `CURRENT`. This allows us to access the current `ThreadId` without the relatively heavy machinery used by `thread::current().id()`.
2024-07-18 14:09:25 +00:00
Chris Denton a605e2f498
Safely enforce thread name requirements 2024-07-18 13:45:20 +00:00
Matthias Krüger 3aafbd28e5
Rollup merge of #127077 - tbu-:pr_doc_fd_to_owned, r=workingjubilee
Make language around `ToOwned` for `BorrowedFd` more precise
2024-07-18 08:08:58 +02:00
Trevor Gross 8bb057874d
Rollup merge of #127861 - Kriskras99:patch-1, r=tgross35
Document the column numbers for the dbg! macro

The line numbers were also made consistent, some examples used the line numbers as shown on the playground while others used the line numbers that you would expect when just seeing the documentation.

The second option was chosen to make everything consistent.
2024-07-17 19:53:29 -05:00
Trevor Gross c36a39cd1f
Rollup merge of #127859 - RalfJung:ptr-dyn-metadata, r=scottmcm
ptr::metadata: avoid references to extern types

References to `extern types` are somewhat dubious entities, since generally we say that references must be dereferenceable for their size as determined via `size_of_val`, but with `extern type` that is an ill-defined statement. I'd like to make Miri warn for such cases since it interacts poorly with Stacked Borrows. To avoid warnings people can't fix, this requires not using references to `extern type` in the standard library, and I think `DynMetadata` is the only currently remaining use. so this changes `DynMetadata` to use a NonNull raw pointer instead. Given that the alignment was 1, this shouldn't really change anything meaningful.

I also updated a comment added by `@scottmcm` in https://github.com/rust-lang/rust/pull/125479, since I think the old comment is wrong. The `DynMetadata` type itself is not special, it is a normal aggregate. But computing field types for wide pointers (including references) is special.
2024-07-17 19:53:28 -05:00
Trevor Gross 3c4f820c5b
Rollup merge of #127845 - workingjubilee:actually-break-up-big-ass-stack-overflow-fn, r=joboet
unix: break `stack_overflow::install_main_guard` into smaller fn

This was one big deeply-indented function for no reason. This made it hard to reason about the boundaries of its safety. Or just, y'know, read. Simplify it by splitting it into platform-specific functions, but which are still asked to keep compiling (a desirable property, since all of these OS use a similar API).

This is mostly a whitespace change, so I suggest reviewing it only after setting Files changed -> (the options gear) -> [x] Hide whitespace as that will make it easier to see how the code was actually broken up instead of raw line diffs.
2024-07-17 19:53:28 -05:00
bors e35364a521 Auto merge of #127865 - matthiaskrgr:rollup-8m49dlg, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #125042 (Use ordinal number in argument error)
 - #127229 (rustdoc: click target for sidebar items flush left)
 - #127337 (Move a few intrinsics to Rust abi)
 - #127472 (MIR building: Stop using `unpack!` for `BlockAnd<()>`)
 - #127579 (Solve a error `.clone()` suggestion when moving a mutable reference)
 - #127769 (Don't use implicit features in `Cargo.toml` in `compiler/`)
 - #127844 (Remove invalid further restricting suggestion for type bound)
 - #127855 (Add myself to review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-17 21:52:29 +00:00
Julius Liu 35428cff60 feat: adding ext that returns change_time for Windows 2024-07-17 13:34:18 -07:00
bors fcc325f1bc Auto merge of #125942 - timokroeger:windows-once-futex, r=ChrisDenton
Windows: Use futex implementation for `Once`

Keep the queue implementation for win7.
Inspired by PR #121956

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
2024-07-17 19:28:24 +00:00
Matthias Krüger 3ddfd97198
Rollup merge of #127337 - celinval:intrinsics-fallback, r=oli-obk
Move a few intrinsics to Rust abi

Move a few more intrinsic functions to the convention added in #121192. In the second commit, I added documentation about their safety requirements. Let me know if you would like me to move the second commit to a different PR.

Note: I kept the same signature of `pref_align_of`, but I was wondering why this function is considered unsafe?
2024-07-17 16:22:28 +02:00
Tobias Bucher 2162f3f34b Mention how you can go from `BorrowedFd` to `OwnedFd` and back 2024-07-17 14:34:00 +02:00
Tobias Bucher 538b31e977 Make language around `ToOwned` for `BorrowedFd` more precise 2024-07-17 14:33:39 +02:00
Kriskras99 99f879c32f
Document the column numbers for the dbg! macro
The line numbers were also made consistent, some examples used the line numbers as shown on the playground while others used the line numbers that you would expect when just seeing the documentation.
The second option was chosen to make everything consistent.
2024-07-17 14:10:41 +02:00
Ralf Jung f9c0d3370f ptr::metadata: update comment on vtable_ptr work-around 2024-07-17 13:56:25 +02:00
Ralf Jung 21dc49c587 ptr::metadata: avoid references to extern types 2024-07-17 13:50:01 +02:00
Boxy d0c11bf6e3 Split part of `adt_const_params` into `unsized_const_params` 2024-07-17 11:01:29 +01:00
Boxy 42cc42b942 Forbid `!Sized` types and references 2024-07-17 11:01:29 +01:00
Trevor Gross 599d32414b
Rollup merge of #127813 - ChrisDenton:win-futex, r=joboet
Prevent double reference in generic futex

In the Windows futex implementation we were a little lax at allowing references to references (i.e. `&&`) which can lead to deadlocks due to reading the wrong memory address. This uses a trait to tighten the constraints and ensure this doesn't happen.

r? libs
2024-07-17 04:05:59 -05:00
Trevor Gross 56f95559da
Rollup merge of #127763 - ChrisDenton:safe-unsafe-unsafe, r=tgross35
Make more Windows functions `#![deny(unsafe_op_in_unsafe_fn)]`

As part of #127747, I've evaluated some more Windows functions and added `unsafe` blocks where necessary. Some are just trivial wrappers that "inherit" the full unsafety of their function, but for others I've added some safety comments. A few functions weren't actually unsafe at all. I think they were just using `unsafe fn` to avoid an `unsafe {}` block.

I'm not touching `c.rs` yet because that is partially being addressed by another PR and also I have plans to further reduce the number of wrapper functions we have in there.

r? libs
2024-07-17 04:05:59 -05:00
Jubilee Young d47cb26ddd unix: unsafe-wrap install_main_guard_default 2024-07-17 00:08:05 -07:00
Jubilee Young 6ed563d491 unix: clean up install_main_guard_freebsd
This just was a mess.
2024-07-17 00:06:27 -07:00
Jubilee Young e285c95cee unix: stack_start_aligned is a safe fn
This function is purely informative, answering where a stack starts.
This is a safe operation, even if an answer requires unsafe code,
and even if the result is some unsafe code decides to trust the answer.
It also doesn't need to fetch the PAGE_SIZE when its caller just did so!
Let's complicate its signature and in doing so simplify its operation.

This allows sprinkling around #[forbid(unsafe_op_in_unsafe_fn)]
2024-07-16 23:46:03 -07:00
Jubilee Young 17c70a9aac unix: split stack_overflow::install_main_guard by os 2024-07-16 23:32:02 -07:00
Chris Denton 0585c4a23e
Prevent double reference in generic futex 2024-07-17 05:57:39 +00:00
Chris Denton 2043de12a3
Narrow the scope of the ReadFile unsafe block 2024-07-17 05:53:20 +00:00
Chris Denton a33abbba98
forbid(unsafe_op_in_unsafe_fn) in sys/os_str 2024-07-17 05:52:38 +00:00
Trevor Gross 1a1b44fcae
Rollup merge of #127836 - workingjubilee:forbid-unsafe-ops-in-xous-uefi, r=tgross35
std: Forbid unwrapped unsafe ops in xous and uefi modules
2024-07-16 20:10:14 -05:00
Trevor Gross dd80a728cc
Rollup merge of #127833 - risc0:erik/zkvm-deny-unsafe, r=workingjubilee
zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib`

This also adds an additional `unsafe` block to address compiler errors.
This PR is intended to address https://github.com/rust-lang/rust/issues/127747 for the zkvm target.
2024-07-16 20:10:13 -05:00
Trevor Gross 446e0177ec
Rollup merge of #127807 - ChrisDenton:win-parking, r=joboet
Use futex.rs for Windows thread parking

If I'm not overlooking anything then the Windows 10+ thread parking implementation is practically the same as the futex.rs implementation. So we may as well use the same implementation for both. The old version is still kept around for Windows 7 support.

r? ````@joboet```` if you wouldn't mind double checking I've not missed something
2024-07-16 20:10:12 -05:00
Trevor Gross 045b8107f2
Rollup merge of #127792 - workingjubilee:read-unaligned-is-dwarfier, r=joboet
std: Use `read_unaligned` for reads from DWARF

There's a lot of... *stuff* going on here. Meanwhile, `read_unaligned` has been available since 1.17.0, so let's just use that.
2024-07-16 20:10:12 -05:00
Trevor Gross 4013acdda2
Rollup merge of #127444 - Sky9x:cstr-bytes-iter, r=dtolnay
`impl Send + Sync` and override `count` for the `CStr::bytes` iterator

cc tracking issue #112115
2024-07-16 20:10:11 -05:00
Trevor Gross 606d8cf9e8
Rollup merge of #126776 - nnethercote:rustfmt-use-pre-cleanups-2, r=cuviper
Clean up more comments near use declarations

#125443 will reformat all use declarations in the repository. There are a few edge cases involving comments on use declarations that require care. This PR fixes them up so #125443 can go ahead with a simple `x fmt --all`. A follow-up to #126717.

r? ``@cuviper``
2024-07-16 20:10:10 -05:00
Trevor Gross fe1dc02163
Rollup merge of #126271 - diondokter:dec2flt-skip-fast-path, r=tgross35
Skip fast path for dec2flt when optimize_for_size

Tracking issue: https://github.com/rust-lang/rust/issues/125612

Skip the fast algorithm when optimizing for size.
When compiling for https://github.com/quartiq/stabilizer I get these numbers:

Before
```
   text    data     bss     dec     hex filename
 192192       8   49424  241624   3afd8 dual-iir
```

After
```
   text    data     bss     dec     hex filename
 191632       8   49424  241064   3ada8 dual-iir
```

This saves 560 bytes.
2024-07-16 20:10:09 -05:00
Trevor Gross 689d27293a
Rollup merge of #125206 - mgeisler:simplify-std-env-vars, r=jhpratt,tgross35
Simplify environment variable examples

I’ve found myself visiting the documentation for `std::env::vars` every few months, and every time I do, it is because I want to quickly get a snippet to print out all environment variables :-)

So I think it could be nice to simplify the examples a little to make them self-contained. It is of course a style question if one should import a module a not, but I personally don’t import modules used just once in a code snippet.
2024-07-16 20:10:09 -05:00
Jubilee Young 586ef83f3f uefi: Forbid unwrapped unsafe in platform modules 2024-07-16 16:21:10 -07:00
Dion Dokter 33f1d9d554
Cfg nit
Co-authored-by: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2024-07-17 01:20:56 +02:00
Jubilee Young b5a83a6f71 xous: Forbid unwrapped unsafe in platform modules 2024-07-16 16:16:03 -07:00
Erik Kaneda e48d33e18a
zkvm: add `#[forbid(unsafe_op_in_unsafe_fn)]` in `stdlib`
This also adds an additional `unsafe` block to address compiler errors.
2024-07-16 16:04:02 -07:00
Nicholas Nethercote 7f0ccfe69d Adjust some comments on individual `use` declarations.
When we do the big `use` reformatting there are a tiny number of cases
where rustfmt moves a comment from one `use` item to another in an
undesirable way. This commit pre-emptively rearranges things to prevent
this from happening.
2024-07-17 08:05:39 +10:00
Nicholas Nethercote 75b6ec9800 Avoid comments that describe multiple `use` items.
There are some comments describing multiple subsequent `use` items. When
the big `use` reformatting happens some of these `use` items will be
reordered, possibly moving them away from the comment. With this
additional level of formatting it's not really feasible to have comments
of this type. This commit removes them in various ways:

- merging separate `use` items when appropriate;

- inserting blank lines between the comment and the first `use` item;

- outright deletion (for comments that are relatively low-value);

- adding a separate "top-level" comment.

We also entirely skip formatting for four library files that contain
nothing but `pub use` re-exports, where reordering would be painful.
2024-07-17 08:02:46 +10:00
Nicholas Nethercote d9fde2504a Merge some `core::iter` entries. 2024-07-17 08:02:46 +10:00
Chris Denton 10b845cbc8
Add unsafe blocks in unsafe Thread::new 2024-07-16 20:48:39 +00:00
Chris Denton 55c84e39cc
Remove `slice_to_end` 2024-07-16 20:24:57 +00:00
Jubilee 249905780f
std: unwrapped unsafe is VERBOTEN!
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-07-16 12:51:14 -07:00
Matthias Krüger 08809eb746
Rollup merge of #127789 - Sword-Destiny:master, r=petrochenkov
delete #![allow(unsafe_op_in_unsafe_fn)] in teeos

deny unsafe_op_in_unsafe_fn for teeos
2024-07-16 18:09:11 +02:00
Chris Denton 51bdcf66d3
Use futex.rs for Windows thread parking 2024-07-16 11:21:51 +00:00
Jubilee Young 8dafc5c819 std: Use read_unaligned for reading DWARF 2024-07-16 00:10:08 -07:00
Trevor Gross 57fef31096
Rollup merge of #127047 - tspiteri:f128-aconsts-lsd, r=tgross35
fix least significant digits of f128 associated constants

While the numbers are parsed to the correct value, the decimal numbers in the source were rounded to zero instead of to the nearest, making the literals different from the values shown in the documentation.
2024-07-16 02:02:24 -05:00
袁浩----天命剑主 9183af25e5
deny unsafe_op_in_unsafe_fn for teeos 2024-07-16 11:47:22 +08:00
袁浩----天命剑主 af5c90d33f
clean unsafe op in unsafe fn 2024-07-16 11:46:16 +08:00
袁浩----天命剑主 00fff8ac64
clean unsafe op in unsafe fn 2024-07-16 11:34:23 +08:00
袁浩----天命剑主 060a40de63
clean unsafe op in unsafe fn 2024-07-16 11:18:51 +08:00
袁浩----天命剑主 00811621fe
delete #![allow(unsafe_op_in_unsafe_fn)]
this is redundant, so we can just delete it.
2024-07-16 11:05:18 +08:00
Sky 7f8f1780d4
`impl Send + Sync` and override `count` for the `CStr::bytes` iterator 2024-07-15 23:01:41 -04:00
Charles Celerier deb8ebb39b Update name of Windows abort constant to match platform documentation 2024-07-15 22:21:41 +00:00
Charles Celerier 1aad89d11c Add match arm for Fuchsia status code upon an abort in a test
This change adds ZX_TASK_RETCODE_EXCEPTION_KILL as an expected status
code upon an abort in a test on Fuchsia. Tests

fixes #127539
2024-07-15 22:21:41 +00:00
bors 24d2ac0b56 Auto merge of #127777 - matthiaskrgr:rollup-qp2vkan, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #124921 (offset_from: always allow pointers to point to the same address)
 - #127407 (Make parse error suggestions verbose and fix spans)
 - #127684 (consolidate miri-unleashed tests for mutable refs into one file)
 - #127729 (Stop using the `gen` identifier in the compiler)
 - #127736 (Add myself to the review rotation)
 - #127758 (coverage: Restrict `ExpressionUsed` simplification to `Code` mappings)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-15 19:44:22 +00:00
Matthias Krüger 78529d9841
Rollup merge of #124921 - RalfJung:offset-from-same-addr, r=oli-obk
offset_from: always allow pointers to point to the same address

This PR implements the last remaining part of the t-opsem consensus in https://github.com/rust-lang/unsafe-code-guidelines/issues/472: always permits offset_from when both pointers have the same address, no matter how they are computed. This is required to achieve *provenance monotonicity*.

Tracking issue: https://github.com/rust-lang/rust/issues/117945

### What is provenance monotonicity and why does it matter?

Provenance monotonicity is the property that adding arbitrary provenance to any no-provenance pointer must never make the program UB. More specifically, in the program state, data in memory is stored as a sequence of [abstract bytes](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#abstract-byte), where each byte can optionally carry provenance. When a pointer is stored in memory, all of the bytes it is stored in carry that provenance. Provenance monotonicity means: if we take some byte that does not have provenance, and give it some arbitrary provenance, then that cannot change program behavior or introduce UB into a UB-free program.

We care about provenance monotonicity because we want to allow the optimizer to remove provenance-stripping operations. Removing a provenance-stripping operation effectively means the program after the optimization has provenance where the program before the optimization did not -- since the provenance removal does not happen in the optimized program. IOW, the compiler transformation added provenance to previously provenance-free bytes. This is exactly what provenance monotonicity lets us do.

We care about removing provenance-stripping operations because `*ptr = *ptr` is, in general, (likely) a provenance-stripping operation. Specifically, consider `ptr: *mut usize` (or any integer type), and imagine the data at `*ptr` is actually a pointer (i.e., we are type-punning between pointers and integers). Then `*ptr` on the right-hand side evaluates to the data in memory *without* any provenance (because [integers do not have provenance](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html#integers-do-not-have-provenance)). Storing that back to `*ptr` means that the abstract bytes `ptr` points to are the same as before, except their provenance is now gone. This makes  `*ptr = *ptr`  a provenance-stripping operation  (Here we assume `*ptr` is fully initialized. If it is not initialized, evaluating `*ptr` to a value is UB, so removing `*ptr = *ptr` is trivially correct.)

### What does `offset_from` have to do with provenance monotonicity?

With `ptr = without_provenance(N)`, `ptr.offset_from(ptr)` is always well-defined and returns 0. By provenance monotonicity, I can now add provenance to the two arguments of `offset_from` and it must still be well-defined. Crucially, I can add *different* provenance to the two arguments, and it must still be well-defined. In other words, this must always be allowed: `ptr1.with_addr(N).offset_from(ptr2.with_addr(N))` (and it returns 0). But the current spec for `offset_from` says that the two pointers must either both be derived from an integer or both be derived from the same allocation, which is not in general true for arbitrary `ptr1`, `ptr2`.

To obtain provenance monotonicity, this PR hence changes the spec for offset_from to say that if both pointers have the same address, the function is always well-defined.

### What further consequences does this have?

It means the compiler can no longer transform `end2 = begin.offset(end.offset_from(begin))` into `end2 = end`. However, it can still be transformed into `end2 = begin.with_addr(end.addr())`, which later parts of the backend (when provenance has been erased) can trivially turn into `end2 = end`.

The only alternative I am aware of is a fundamentally different handling of zero-sized accesses, where a "no provenance" pointer is not allowed to do zero-sized accesses and instead we have a special provenance that indicates "may be used for zero-sized accesses (and nothing else)". `offset` and `offset_from` would then always be UB on a "no provenance" pointer, and permit zero-sized offsets on a "zero-sized provenance" pointer. This achieves provenance monotonicity. That is, however, a breaking change as it contradicts what we landed in https://github.com/rust-lang/rust/pull/117329. It's also a whole bunch of extra UB, which doesn't seem worth it just to achieve that transformation.

### What about the backend?

LLVM currently doesn't have an intrinsic for pointer difference, so we anyway cast to integer and subtract there. That's never UB so it is compatible with any relaxation we may want to apply.

If LLVM gets a `ptrsub` in the future, then plausibly it will be consistent with `ptradd` and [consider two equal pointers to be inbounds](https://github.com/rust-lang/rust/pull/124921#issuecomment-2205795829).
2024-07-15 21:11:47 +02:00
Pavel Grigorenko f6fe7e49a2 lib: replace some `mem::forget`'s with `ManuallyDrop` 2024-07-15 22:01:09 +03:00
bors eb72697e41 Auto merge of #127020 - tgross35:f16-f128-classify, r=workingjubilee
Add classify and related methods for f16 and f128

Also constify some functions where that was blocked on classify being available.

r? libs
2024-07-15 17:20:33 +00:00
Chris Denton 5922234654
allow(unsafe_op_in_unsafe_fn) on some functions
These need to get their safety story straight
2024-07-15 14:16:17 +00:00
Chris Denton 37295e6268
Some Windows functions are safe 2024-07-15 14:16:17 +00:00
Chris Denton d1a3c1daeb
Deny more windows unsafe_op_in_unsafe_fn 2024-07-15 14:16:11 +00:00
Chris Denton fae6037884
Windows: move BSD socket shims to netc 2024-07-15 12:34:31 +00:00
Benoît du Garreau 772315de7c Remove generic lifetime parameter of trait `Pattern`
Use a GAT for `Searcher` associated type because this trait is always
implemented for every lifetime anyway.
2024-07-15 12:12:44 +02:00
Jubilee 476d399782
Rollup merge of #127750 - ChrisDenton:safe-unsafe-unsafe, r=workingjubilee
Make os/windows and pal/windows default to `#![deny(unsafe_op_in_unsafe_fn)]`

This is to prevent regressions in modules that currently pass. I did also fix up a few trivial places where the module contained only one or two simple wrappers. In more complex cases we should try to ensure the `unsafe` blocks are appropriately scoped and have any appropriate safety comments.

This does not fix the windows bits of #127747 but it should help prevent regressions until that is done and also make it more obvious specifically which modules need attention.
2024-07-15 02:28:44 -07:00
Jubilee 99c5302d9f
Rollup merge of #127744 - workingjubilee:deny-unsafe-op-in-std, r=jhpratt
std: `#![deny(unsafe_op_in_unsafe_fn)]` in platform-independent code

This applies the `unsafe_op_in_unsafe_fn` lint in all places in std that _do not have platform-specific cfg in their code_. For all such places, the lint remains allowed, because they need further work to address the relevant concerns. This list includes:

- `std::backtrace_rs` (internal-only)
- `std::sys` (internal-only)
- `std::os`

Notably this eliminates all "unwrapped" unsafe operations in `std::io` and `std::sync`, which will make them much more auditable in the future. Such has *also* been left for future work. While I made a few safety comments along the way on interfaces I have grown sufficiently familiar with, in most cases I had no context, nor particular confidence the unsafety was correct.

In the cases where I was able to determine the unsafety was correct without having prior context, it was obviously redundant. For example, an unsafe function calling another unsafe function that has the exact same contract, forwarding its caller's requirements just as it forwards its actual call.
2024-07-15 02:28:44 -07:00
Jubilee 64495b5f94
Rollup merge of #127712 - ChrisDenton:raw-types, r=workingjubilee
Windows: Remove some unnecessary type aliases

Back in the olden days, C did not have fixed-width types so these type aliases were at least potentially useful. Nowadays, and especially in Rust, we don't need the aliases and they don't help with anything. Notably the windows bindings we use also don't bother with the aliases. And even when we have used aliases they're often only used once then forgotten about.

The only one that gives me pause is `DWORD` because it's used a fair bit. But it's still used inconsistently and we implicitly assume it's a `u32` anyway (e.g. `as` casting from an `i32`).
2024-07-15 02:28:43 -07:00