Commit Graph

24922 Commits

Author SHA1 Message Date
Jakub Beránek
7c93af02e3 Rollup merge of #145412 - tgross35:win-tid, r=ChrisDenton
Windows: Replace `GetThreadId`+`GetCurrentThread` with `GetCurrentThreadId`

Reference: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthreadid
2025-08-15 16:03:58 +02:00
Jakub Beránek
a676c4891e Rollup merge of #144210 - Gelbpunkt:thread-stack-size-musl, r=jhpratt
std: thread: Return error if setting thread stack size fails

Currently, when setting the thread stack size fails, it would be rounded up to the nearest multiple of the page size and the code asserts that the next call to `pthread_attr_setstacksize` succeeds.

This may be true for glibc, but it isn't true for musl, which not only enforces a minimum stack size, but also a maximum stack size of `usize::MAX / 4 - PTHREAD_STACK_MIN` [1], triggering the assert rather than erroring gracefully.

There isn't any way to handle this properly other than bailing out and letting the user know it didn't succeed.

[1]: https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_attr_setstacksize.c#n5
2025-08-15 16:03:55 +02:00
Stuart Cook
b672a2ad5c Rollup merge of #145331 - theemathas:std-prelude-2024, r=tgross35
Make std use the edition 2024 prelude

This seem to have been overlooked in <https://github.com/rust-lang/rust/pull/138162>
2025-08-15 16:16:40 +10:00
Stuart Cook
14e2886028 Rollup merge of #145322 - LorrensP-2158466:early-prelude-processing, r=petrochenkov
Resolve the prelude import in `build_reduced_graph`

This pr tries to resolve the prelude import at the `build_reduced_graph` stage.
Part of batched import resolution in rust-lang/rust#145108 (cherry picked commit) and maybe needed for rust-lang/rust#139493.

r? petrochenkov
2025-08-15 16:16:39 +10:00
Stuart Cook
df4f2aa171 Rollup merge of #145189 - rust-lang:cargo_update, r=clubby789
Weekly `cargo update`

Automation to keep dependencies in `Cargo.lock` current.
r? dep-bumps

The following is the output from `cargo update`:

```txt

compiler & tools dependencies:
     Locking 18 packages to latest compatible versions
    Updating anstream v0.6.19 -> v0.6.20
    Updating anstyle-query v1.1.3 -> v1.1.4
    Updating anstyle-svg v0.1.9 -> v0.1.10
    Updating anstyle-wincon v3.0.9 -> v3.0.10
    Updating camino v1.1.10 -> v1.1.11
    Updating clap v4.5.42 -> v4.5.43
    Updating clap_builder v4.5.42 -> v4.5.43
    Updating cxx v1.0.161 -> v1.0.166
    Updating cxx-build v1.0.161 -> v1.0.166
    Updating cxxbridge-cmd v1.0.161 -> v1.0.166
    Updating cxxbridge-flags v1.0.161 -> v1.0.166
    Updating cxxbridge-macro v1.0.161 -> v1.0.166
    Updating derive-where v1.5.0 -> v1.6.0
    Updating hashbrown v0.15.4 -> v0.15.5
    Updating indenter v0.3.3 -> v0.3.4
    Updating rustversion v1.0.21 -> v1.0.22
    Updating scratch v1.0.8 -> v1.0.9
    Updating zerovec v0.11.2 -> v0.11.4
note: pass `--verbose` to see 36 unchanged dependencies behind latest

library dependencies:
     Locking 1 package to latest compatible version
    Updating hashbrown v0.15.4 -> v0.15.5
note: pass `--verbose` to see 2 unchanged dependencies behind latest

rustbook dependencies:
     Locking 10 packages to latest compatible versions
    Updating anstream v0.6.19 -> v0.6.20
    Updating anstyle-query v1.1.3 -> v1.1.4
    Updating anstyle-wincon v3.0.9 -> v3.0.10
    Updating cc v1.2.31 -> v1.2.32
    Updating clap v4.5.42 -> v4.5.43
    Updating clap_builder v4.5.42 -> v4.5.43
    Updating clap_complete v4.5.55 -> v4.5.56
    Updating hashbrown v0.15.4 -> v0.15.5
    Updating rustversion v1.0.21 -> v1.0.22
    Updating zerovec v0.11.2 -> v0.11.4
```
2025-08-15 16:16:37 +10:00
Stuart Cook
65e2a8b6d8 Rollup merge of #144947 - tautschnig:remove-stray-checked_div-comment, r=Mark-Simulacrum
Fix description of unsigned `checked_exact_div`

Like its signed counterpart, this function does not panic. Also, fix the examples to document how it returns Some/None.
2025-08-15 16:16:33 +10:00
Stuart Cook
e3a178234d Rollup merge of #142640 - Sa4dUs:ad-intrinsic, r=ZuseZ4
Implement autodiff using intrinsics

This PR aims to move autodiff logic to `autodiff` intrinsic. Allowing us to delete a great part of our frontend code and overall, simplify the compilation pipeline of autodiff functions.
2025-08-15 16:16:30 +10:00
Stuart Cook
324bf2b9fd Rollup merge of #118087 - GrigorenkoPV:refcell_try_map, r=Mark-Simulacrum
Add Ref/RefMut try_map method

Tracking issue:  rust-lang/rust#143801

A more generalized version of [`filter_map`](https://doc.rust-lang.org/stable/core/cell/struct.Ref.html#method.filter_map), which allows to return some data on failure.

## Safety

As far as I can tell, `E` cannot contain any `'b` data, so it is impossible to duplicate the `&'b [mut]` reference into the `RefCell`'s  data.

Other than this `E`, everything is analogous to the already stable `filter_map`.

## `Try` / `Residual`

I have considered generalizing this to use the `Try` & `Residual` just like rust-lang/rust#79711 does for `array::try_map`, but it does not seem to be possible: we want to essentially `.map_err(|e| (orig, e))` but this does not seem to be supported with `Try`. (Plus I am not even sure if it is possible to express the fact that `&U` in `Try::Output` would have to have the same lifetime as the `&T` input of `F`.)

## ACP

~As far as I can tell, this [is not mandatory](https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html#suitability-for-the-standard-library), and the implementation is small enough to probably be smaller than the doc I would have to write.~

~https://github.com/rust-lang/libs-team/issues/341~

https://github.com/rust-lang/libs-team/issues/586
2025-08-15 16:16:29 +10:00
Trevor Gross
2355563e0a Windows: Replace GetThreadId+GetCurrentThread with GetCurrentThreadId
Reference: https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentthreadid
2025-08-14 20:05:31 -05:00
Jakub Beránek
01bd889098 Rollup merge of #145233 - joshtriplett:cfg-select-expr, r=jieyouxu
cfg_select: Support unbraced expressions

Tracking issue for `cfg_select`: rust-lang/rust#115585

When operating on expressions, `cfg_select!` can now handle expressions
without braces. (It still requires braces for other things, such as
items.)

Expand the test coverage and documentation accordingly.

---

I'm not sure whether deciding to extend `cfg_select!` in this way is T-lang or T-libs-api. I've labeled for both, with the request that both teams don't block on each other. :)
2025-08-14 21:48:42 +02:00
Jens Reidel
5d01d90ad6 std: thread: Return error if setting thread stack size fails
Currently, when setting the thread stack size fails, it would be rounded
up to the nearest multiple of the page size and the code asserts that
the next call to pthread_attr_setstacksize succeeds.

This may be true for glibc, but it isn't true for musl, which not only
enforces a minimum stack size, but also a maximum stack size of
usize::MAX / 4 - PTHREAD_STACK_MIN [1], triggering the assert rather
than erroring gracefully.

There isn't any way to handle this properly other than bailing out and
letting the user know it didn't succeed.

[1]: https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_attr_setstacksize.c#n5

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-08-14 20:37:05 +02:00
Marcelo Domínguez
250d77e5d7 Complete functionality and general cleanup 2025-08-14 16:30:15 +00:00
Marcelo Domínguez
5c631041aa Basic implementation of autodiff intrinsic 2025-08-14 16:29:58 +00:00
bors
be00ea1968 Auto merge of #144542 - sayantn:stabilize-sse4a-tbm, r=Amanieu,traviscross
Stabilize `sse4a` and `tbm` target features

This PR stabilizes the feature flag `sse4a_target_feature` and `tbm_target_feature` (tracking issue rust-lang/rust#44839).

# Public API
The 2 `x86` target features `sse4a` and `tbm`

Also, these were added in LLVM2.6 and LLVM3.4-rc1, respectively, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too!

As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now. The intrinsics were stabilized *long* ago, in 1.27.0

Reference PR:

- https://github.com/rust-lang/reference/pull/1949

cc `@rust-lang/lang`

`@rustbot` label I-lang-nominated
r? lang
2025-08-14 14:01:12 +00:00
LorrensP-2158466
ff560d3c9a resolve prelude import at build_reduced_graph phase 2025-08-14 15:28:35 +02:00
Guillaume Gomez
f493f804d7 Rollup merge of #145299 - eval-exec:exec-fix-145293, r=tgross35
doc test: fix mpsc.rs try_send doc test

This Pr want to fix the doctest, to make https://github.com/rust-lang/rust/pull/145293 's CI pass:

r? ``@Zalathar``

https://github.com/rust-lang/rust/actions/runs/16903356990/job/47887354221

```bash
2025-08-12T10:19:32.3873237Z test library/std/src/thread/scoped.rs - thread::scoped::ScopedJoinHandle<'scope,T>::join (line 302) ... ok
2025-08-12T10:19:32.4370250Z test library/std/src/time.rs - time::SystemTimeError::duration (line 688) ... ok
2025-08-12T10:19:32.5121966Z test library/std/src/time.rs - time::UNIX_EPOCH (line 664) ... ok
2025-08-12T10:19:32.5122586Z
2025-08-12T10:19:32.5122738Z failures:
2025-08-12T10:19:32.5122973Z
2025-08-12T10:19:32.5123482Z ---- library/std/src/sync/mpsc.rs - sync::mpsc::SyncSender<T>::try_send (line 691) stdout ----
2025-08-12T10:19:32.5124286Z Test executable failed (exit status: 1).
2025-08-12T10:19:32.5124518Z
2025-08-12T10:19:32.5124605Z stdout:
2025-08-12T10:19:32.5124810Z message 3 received
2025-08-12T10:19:32.5125043Z message 1 received
2025-08-12T10:19:32.5125288Z the third message was never sent
2025-08-12T10:19:32.5125497Z
2025-08-12T10:19:32.5125581Z stderr:
2025-08-12T10:19:32.5125701Z
2025-08-12T10:19:32.5125935Z thread '<unnamed>' (203874) panicked at library/std/src/sync/mpsc.rs:14:25:
2025-08-12T10:19:32.5126459Z called `Result::unwrap()` on an `Err` value: SendError { .. }
2025-08-12T10:19:32.5126836Z stack backtrace:
2025-08-12T10:19:32.5127568Z ␛[0m␛[1m␛[38;5;9merror␛[0m␛[0m␛[1m: the main thread terminated without waiting for all remaining threads␛[0m
2025-08-12T10:19:32.5127971Z
2025-08-12T10:19:32.5128335Z ␛[0m␛[1m␛[38;5;10mnote␛[0m␛[0m␛[1m: set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check␛[0m
2025-08-12T10:19:32.5128694Z
2025-08-12T10:19:32.5128943Z ␛[0m␛[1m␛[38;5;9merror␛[0m␛[0m␛[1m: aborting due to 1 previous error␛[0m
2025-08-12T10:19:32.5129519Z
2025-08-12T10:19:32.5129527Z
2025-08-12T10:19:32.5129532Z
2025-08-12T10:19:32.5129537Z
2025-08-12T10:19:32.5129631Z failures:
2025-08-12T10:19:32.5130018Z     library/std/src/sync/mpsc.rs - sync::mpsc::SyncSender<T>::try_send (line 691)
2025-08-12T10:19:32.5130396Z
2025-08-12T10:19:32.5130713Z test result: FAILED. 999 passed; 1 failed; 16 ignored; 0 measured; 344 filtered out; finished in 105.92s
```
2025-08-14 11:39:39 +02:00
Guillaume Gomez
c1f9e2ab50 Rollup merge of #145179 - joshtriplett:number, r=RalfJung
Avoid abbreviating "numerator" as "numer", to allow catching typo "numer" elsewhere

`typos.toml` has an exception for "numer", to avoid flagging its use as an abbreviation for "numerator". Remove the use of that abbrevation, spelling out "numerator" instead, and remove the exception, so that typo checks can find future instances of "numer" as a typo for "number".
2025-08-14 11:39:36 +02:00
Guillaume Gomez
31d8277abe Rollup merge of #144515 - scottmcm:ptr_cast_array, r=Mark-Simulacrum
Implement `ptr_cast_array`

ACP: https://github.com/rust-lang/libs-team/issues/602
Tracking Issue: https://github.com/rust-lang/rust/issues/144514
2025-08-14 11:39:34 +02:00
Guillaume Gomez
4bc1eb737d Rollup merge of #142741 - a1phyr:fix_unsoundness, r=Mark-Simulacrum
Fix unsoundness in some tests

These tests were marked uninit bytes as initilized, which is unsound. Use initialized `MaybeUninit` instead.
2025-08-14 11:39:33 +02:00
sayantn
100d19ce5b Stabilize sse4a and tbm target features
- remove some stabilized target features from `gate.rs`
2025-08-14 02:07:40 +05:30
Eval EXEC
a0eea23317 doc test: fix mpsc.rs try_send doc test
Signed-off-by: Eval EXEC <execvy@gmail.com>
2025-08-13 21:09:32 +08:00
Jakub Beránek
8cb78fe3b6 Rollup merge of #145325 - clarfonthey:cast-init, r=scottmcm
Add `cast_init` and `cast_uninit` methods for pointers

ACP: rust-lang/libs-team#627
Tracking issue: rust-lang/rust#145036

This includes an incredibly low-effort search to find uses that could be switched to using these methods. I only searched for `cast::<\w>` and `cast::<MaybeUninit` because there would otherwise be way too much to look through, and I also didn't modify anything inside submodules/subtrees.
2025-08-13 07:03:52 +02:00
Jakub Beránek
b60d5b3672 Rollup merge of #145308 - giltho:dangling-doc, r=scottmcm
Adjust documentation of `dangling`

I believe the current doc of `dangling` is slightly off as it indicates:
`Note that the pointer value may potentially represent a valid pointer to a T`

The returned pointer has no provenance, so it may not be a valid pointer (except in the case of ZSTs, but I don't think this is what the documentation is trying to warn about).

See: https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Dangling.20pointers.3A.20definition

The value returned by dangling may never be used to dereference a value that isn't a ZST, even if address equality is detected with that of a valid pointer.
This is a minor fix, but this doc still got me confused for a second
2025-08-13 07:03:51 +02:00
Jakub Beránek
a0ed0889bb Rollup merge of #145303 - m-ou-se:payload-as-str-doc, r=jhpratt
Docs: Link to payload_as_str() from payload().
2025-08-13 07:03:50 +02:00
Jakub Beránek
4b1deef096 Rollup merge of #145269 - epage:test-env, r=jhpratt
Deprecate RUST_TEST_* env variables

Like with rust-lang/rust#139224, this is a documentation-only deprecation for now. Over time, we can
- warn and then remove on use of unstable environment variables
- warn on use of stable environment variables (no plan to remove due to compatibility)

Longer term, we expect test runners, like `cargo test`, to provide the necessary mechanisms for environmental or persistent configuration (e.g. using cargo config which supports `.cargo/config.toml` as well as environment variables).

This would include:
- `RUST_TEST_THREADS`
- `RUST_TEST_NOCAPTURE`
- `RUST_TEST_SHUFFLE` (unstable)
- `RUST_TEST_SHUFFLE_SEED` (unstable)

The primary outcomes for this change are
- Reducing the scope of what is expected for custom test harnesses to implement
- Reduce the mechanisms that test runners, like `cargo test`, are expected to track when they are being bypassed to protect against negative interactions, e.g.  `RUST_TEST_NOCAPTURE=1` when json output is being read.

For testing-devex FCP, see rust-lang/testing-devex-team#10

Fixes rust-lang/testing-devex-team#10

History
-------

At each step, I could not find evidence of design discussions on whether to support CLI, env, or both.  The first env variable seems to come from the fact that it was being forked out of an existing env variable that had a much wider scope.

At best, this seems like a way to offer a more persistent configuration for these flags but environment variables hidden away in libtest is a bit clunky and this seems like the wrong layer to handle this problem.

**Originally:** `RUST_THREADS` was respected by the Rust runtime and libextra/test got this for free

**2013:** rust-lang/rust#7335 suggested splitting `RUST_TEST_TASKS` out of `RUST_THREADS`.  In that issue and the implementation (rust-lang/rust#8823).

**2014:** rust-lang/rust#13374 ask for support to disable capturing of stdout/stderr.  `--nocapture` and `RUST_TEST_NOCAPTURE` were added together.

**2015:** rust-lang/rust#23525 renamed `RUST_TEST_TASKS` to `RUST_TEST_THREADS`

**2016:** rust-lang/rust#25636 asked to configure `RUST_TEST_THREADS` via `--test-threads` which was implemented in rust-lang/rust#35414

**2021:** rust-lang/rust#85440 asked for test randomization which was implemented in rust-lang/rust#89082, adding `--shuffle` / RUST_TEST_SHUFFLE` and `--shuffle-seed SEED` / `RUST_TEST_SHUFFLE_SEED`

Potentially relevant issues
---------------------------

- rust-lang/rust#74845
2025-08-13 07:03:48 +02:00
Jakub Beránek
ff44871be5 Rollup merge of #144870 - Kivooeo:file_prefix-stabilize, r=tgross35
Stabilize `path_file_prefix` feature

This stabilises `Path::file_prefix`, following the FCP in [tracking issue ](https://github.com/rust-lang/rust/issues/86319)

(FCP ended almost a year ago, so if it's needed for proccess we could rerun it)

Closes: https://github.com/rust-lang/rust/issues/86319
2025-08-13 07:03:47 +02:00
Jakub Beránek
bd2db284fd Rollup merge of #144519 - clarfonthey:const-system-time, r=jhpratt
Constify `SystemTime` methods

This is separated out from rust-lang/rust#143949 due to the fact that it touches nontrivial system code. While the same arithmetic methods on `Instant` could be made const, since that type explicitly cannot be constructed at const-time, we don't bother. However, due to the fact that `SystemTime::UNIX_EPOCH` exists, it can be useful to create other anchors at other points in time, and thus these methods should be possible to use in const context.

> Side comment: I would honestly like to just move every single implementation which is a thin wrapper over `Duration` or some integer clock into their own module which is tested on all targets, so that we don't have to worry about code for lower-tier targets not being tested. However, the comments in `std::sys_common` pointing out the desire to move things to `std::sys::common` confused me, particularly due to the fact that `std::sys::common` is taken from the hellish asterisk-import of `std::sys::pal::common` and others.
>
> I think that, for trivial types like this, we should just have a platform-independent module that can be tested on all platforms, to both ensure that the code is properly tested regardless of whether higher-tier platforms needed, and to avoid the extreme mental gymnastics required to determine where in the code it lies.
>
> However, since I'm not on any of the teams maintaining this code and am not involved, I'll settle for just copy-pasting like everyone else has been doing. I just want to express how I'm not happy about that.

**Reviewer note: please only pay attention to the last commit of this PR, until its blocker is merged.**

Since this depends on the previous PR:
`@rustbot` blocked
2025-08-13 07:03:46 +02:00
Jakub Beránek
fb9cd24d2e Rollup merge of #143467 - ChaiTRex:ascii_char_is_ascii, r=tgross35
Add ASCII-related methods from `u8` and `MIN`/`MAX` to `core::ascii::Char`

* Add ASCII-related methods from `u8` to `core::ascii::Char`.
* Add `core::ascii::Char::MIN` and `core::ascii::Char::MAX`.
2025-08-13 07:03:46 +02:00
Tim (Theemathas) Chirananthavat
605621224f Make std use the edition 2024 prelude
This seem to have been overlooked in <https://github.com/rust-lang/rust/pull/138162>
2025-08-13 11:16:00 +07:00
ltdk
d6945f6d8c Add cast_init and cast_uninit methods for pointers 2025-08-12 16:57:56 -04:00
ltdk
7ce620dd7c Constify SystemTime methods 2025-08-12 14:05:47 -04:00
Sacha Ayoun
427be23b22 Address dangling doc
Signed-off-by: Sacha Ayoun <sachaayoun@gmail.com>
2025-08-12 13:18:48 +01:00
Mara Bos
bd44d855f5 Link to payload_as_str() from payload(). 2025-08-12 12:50:48 +02:00
Stuart Cook
7c4bedc962 Rollup merge of #145292 - ada4a:patch-2, r=tgross35
Fix a typo in range docs
2025-08-12 20:38:00 +10:00
Stuart Cook
30ed54e3e4 Rollup merge of #145260 - SabrinaJewson:vec-allocator-docs, r=dtolnay
Make explicit guarantees about `Vec`’s allocator

This commit amends the documentation of `Vec::as_mut_ptr` and `Vec::into_raw_parts` to make it explicit that such calls may be paired with calls to `dealloc` with a suitable layout. This guarantee was effectively already provided by the docs of `Vec::from_raw_parts` mentioning `alloc`.

Additionally, we copy-paste and adjust the “Memory layout” section from the documentation of `std::boxed` to `std::vec`. This explains the allocator guarantees in more detail.
2025-08-12 20:37:56 +10:00
Ada Alakbarova
5e4f465655 fix typo 2025-08-12 09:43:17 +02:00
SabrinaJewson
1ce4b370e4 Handle the capacity == 0 case 2025-08-12 05:12:34 +01:00
Ed Page
c1a31d8103 Deprecate RUST_TEST_* env variables
This is a documentation-only deprecation for now.
Over time, we can
- warn and then remove on use of unstable environment variables
- warn on use of stable environment variables (no plan to remove due to
  compatibility)

Longer term, we expect test runners, like `cargo test`, to provide the
necessary mechanisms for environmental or persistent configuration (e.g.
using cargo config which supports `.cargo/config.toml` as well as
environment variables).

This would include:
- `RUST_TEST_THREADS`
- `RUST_TEST_NOCAPTURE`
- `RUST_TEST_SHUFFLE` (unstable)
- `RUST_TEST_SHUFFLE_SEED` (unstable)

The primary outcomes for this change are
- Reducing the scope of what is expected for custom test harnesses to
  implement
- Reduce the mechanisms that test runners, like `cargo test`, are
  expected to track when they are being bypassed to protect against
  negative interactions, e.g.  `RUST_TEST_NOCAPTURE=1` when json output
  is being read.
2025-08-11 15:06:32 -05:00
SabrinaJewson
45e2449b2a Respond to review comments 2025-08-11 19:02:00 +01:00
SabrinaJewson
19df24b3b8 Make explicit guarantees about Vec’s allocator
This commit amends the documentation of `Vec::as_mut_ptr` and
`Vec::into_raw_parts` to make it explicit that such calls may be paired
with calls to `dealloc` with a suitable layout. This guarantee was
effectively already provided by the docs of `Vec::from_raw_parts`
mentioning `alloc`.

Additionally, we copy-paste and adjust the “Memory layout” section from
the documentation of `std::boxed` to `std::vec`. This explains the allocator
guarantees in more detail.
2025-08-11 17:15:53 +01:00
Ayush Singh
35906eaabc std: sys: pal: uefi: tests: Add systemtime tests
Add tests to ensure that extream system times are still representable.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-08-11 19:10:10 +05:30
Ayush Singh
0ccbe8fc71 std: sys: pal: uefi: Overhaul Time
Use a time representation with 1900-01-01-00:00:00 at timezone -1440 min as
anchor. This is the earliest time supported in UEFI.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-08-11 18:58:34 +05:30
Stuart Cook
fd7d724559 Rollup merge of #145228 - estebank:unnecessary-parens, r=joshtriplett
Remove unnecessary parentheses in `assert!`s
2025-08-11 12:21:10 +10:00
Stuart Cook
3724e13cc7 Rollup merge of #144350 - Ayush1325:uefi-io, r=tgross35,nicholasbishop
std: sys: io: io_slice: Add UEFI types

UEFI networking APIs do support vectored read/write. While the types for UDP4, UDP6, TCP4 and TCP6 are defined separately, they are essentially the same C struct. So we can map IoSlice and IoSliceMut to have the same binary representation.

Since all UEFI networking types for read/write are DSTs, `IoSlice` and `IoSliceMut` will need to be copied to the end of the transmit/receive structures. So having the same binary representation just allows us to do a single memcpy instead of having to loop and set the DST.

cc ``@nicholasbishop``
2025-08-11 12:21:07 +10:00
Stuart Cook
2c314f93d3 Rollup merge of #144330 - gewitternacht:document-clone-eq, r=Amanieu
document assumptions about `Clone` and `Eq` traits

Most standard library collections break if `Clone` has a non-standard implementation which violates `x.clone() == x`. [Here](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b7fc6dfa8410cbb673eb8d38393d81de) the resulting broken behaviour of different collections is shown. I originally created an issue at https://github.com/rust-lang/hashbrown/issues/629, but the conclusion there was that `x.clone()` resulting in an object that compares equal to the original one is probably a very universal assumption. However, this assumption is (to my knowledge) not documented anywhere.

I propose to make this assumption explicit in the `Clone` trait documentation. The property that seems the most reasonable to me is the following: When implementing both `Clone` and `PartialEq`, then
```text
x == x -> x.clone() == x
```
is expected to hold. This way, when also implementing `Eq`, it automatically follows that `x.clone() == x` has to hold, which should be enough for the collections to not break. At the same time, the property also works for the "normal" elements of a type with `PartialEq`. For the wording, I tried to follow the [`Hash` and `Eq`](https://doc.rust-lang.org/std/hash/trait.Hash.html#hash-and-eq) documentation.

As I am fairly new to Rust, it might well be that this property cannot be generally expected – it seems reasonable to me, but any counter-examples or critique, both content- and wording-wise, would be very welcome. If the property turns out to be too general, I would suggest to at least document the assumption of `x.clone() == x` for the collections somehow.

An additional thought of mine:
If it is indeed generally expected that `x == x -> x.clone() == x`, then, for the sake of completeness, one could also define that `x != x -> y != y for y = x.clone()` should hold, i.e., that an object that did not compare equal to itself before cloning, should also not compare equal to itself afterwards.
2025-08-11 12:21:07 +10:00
Stuart Cook
d06b3b432f Rollup merge of #143949 - clarfonthey:const-arith-ops, r=Amanieu
Constify remaining traits/impls for `const_ops`

Tracking issue: rust-lang/rust#143802

This is split into two commits for ease of reviewability:

1. Updates the `forward_ref_*` macros to accept multiple attributes (in anticipation of needing `rust_const_unstable` attributes) and also *require* attributes in these macros. Since the default attribute only helps for the initial implementations, it means it's easy to get wrong for future implementations, as shown for the saturating implementations which were incorrect before.
2. Actually constify the traits/impls.

A few random other notes on the implementation specifically:

* I unindented the attributes that were passed to the `forward_ref_*` macro calls because in some places rustfmt wanted them to be unindented, and in others it was allowed because they were themselves inside of macro bodies. I chose the consistent indenting even though I (personally) think it looks worse.

----

As far as the actual changes go, this constifies the following additional traits:

* `Neg`
* `Not`
* `BitAnd`
* `BitOr`
* `BitXor`
* `Shl`
* `Shr`
* `AddAssign`
* `SubAssign`
* `MulAssign`
* `DivAssign`
* `RemAssign`
* `BitAndAssign`
* `BitOrAssign`
* `BitXorAssign`
* `ShlAssign`
* `ShrAssign`

In terms of constified implementations of these traits, it adds the reference-forwarded versions of all the arithmetic operators, which are defined by the macros in `library/core/src/internal_macros.rs`. I'm not going to fully enumerate these because we'd be here all day, but sufficed to say, it effectively allows adding an `&` to one or both sides of an operator for primitives.

Additionally, I constified the implementations for `Wrapping`, `Saturating`, and `NonZero` as well, since all of them forward to already-const-stable methods. (potentially via intrinsics, to avoid extra overhead)

There are three "non-primitive" types which implement these traits, listed below. Note that I put "non-primitive" in quotes since I'm including `Wrapping`, `Saturating`, and `NonZero`, which are just wrappers over primitives.

* `Duration` (arithmetic operations)
* `SystemTime` (arithmetic operations)
* `Ipv4Addr` (bit operations)
* `Ipv6Addr` (bit operations)

Additionally, because the methods on `SystemTime` needed to make these operations const were not marked const, a separate tracking issue for const-stabilising those methods is rust-lang/rust#144517.

Stuff left out of this PR:

* `Assume` (this could trivially be made const, but since the docs indicate this is still under heavy design, I figured I'd leave it out)
* `Instant` (this could be made const, but cannot reasonably be constructed at constant time, so, isn't useful)
* `SystemTime` (will submit separate PR)
* SIMD types (I'm tackling these all at once later; see rust-lang/portable-simd#467)

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_CONCERN-ISSUE_START -->

> [!NOTE]
> # Concerns (0 active)
>
> - ~~[May break Clippy](https://github.com/rust-lang/rust/pull/143949#issuecomment-3081466077)~~ resolved in [this comment](https://github.com/rust-lang/rust/pull/143949#issuecomment-3083628215)
>
> *Managed by ```@rustbot`—see`` [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*

<!-- TRIAGEBOT_CONCERN-ISSUE_END -->
<!-- TRIAGEBOT_END -->
2025-08-11 12:21:06 +10:00
Josh Triplett
38df15805b cfg_select: Support unbraced expressions
When operating on expressions, `cfg_select!` can now handle expressions
without braces. (It still requires braces for other things, such as
items.)

Expand the test coverage and documentation accordingly.
2025-08-10 16:18:01 -07:00
gewitternacht
fadc961d99 mention Hash and Ord; refine description of derive 2025-08-11 00:05:47 +02:00
Esteban Küber
74c3727b1f Remove unnecessary parentheses in assert!s 2025-08-10 21:59:04 +00:00
Jacob Pratt
adf522cefb Rollup merge of #145150 - ChrisDenton:inherit, r=Mark-Simulacrum
Replace unsafe `security_attributes` function with safe `inherit_handle` alternative

The `security_attributes` function is marked as safe despite taking a raw pointer which will later be used. Fortunately this function is only used internally and only in one place that has been basically the same for a decade now. However, we only ever set one bool so it's easy enough to replace with something that's actually safe.

In the future we might want to expose the ability for users to set security attributes. But that should be properly designed (and safe!).
2025-08-10 15:43:54 -04:00