8357 Commits

Author SHA1 Message Date
Stuart Cook
d0fa5c7af7
Rollup merge of #144960 - raoulstrackx:raoul/rte-513-disable_sleep_tests_on_sgx, r=Mark-Simulacrum
[RTE-513] Ignore sleep_until test on SGX

rust-lang/rust#141829 added a test for `sleep_until`: it checks whether its specification holds:
> Puts the current thread to sleep until the specified deadline has passed.

but in SGX there's no secure time source. There's only the ability to request the `insecure_time` from outside of the enclave through a [usercall](https://github.com/fortanix/rust-sgx/blob/master/intel-sgx/fortanix-sgx-abi/src/lib.rs#L590-L592) and the ability to [wait](https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/sgx/abi/usercalls/mod.rs#L173-L179) for a certain event or timeout. But both are under the control of an attacker; users should not depend on the accuracy nor correctness of this time. We try to even enforce this by adding a +/-10% time interval to wait usercalls.

The current `thread::sleep_until` implementation uses this `wait` usercall. When a negative randomization interval is added to the timeout passed in `wait`, the test fails. As users should not rely on the correctness of any time inside the enclave, it should be considered an incorrect test on SGX. This PR ignores this test.
2025-08-19 14:18:21 +10:00
Stuart Cook
2beb54c451
Rollup merge of #140956 - Kixunil:impl-partialeq-str-for-path, r=Amanieu
`impl PartialEq<{str,String}> for {Path,PathBuf}`

This is a revival of #105877

Comparison of paths and strings is expected to be possible and needed e.g. in tests. This change adds the impls os `PartialEq` between strings and paths, both owned and unsized, in both directions.

ACP: https://github.com/rust-lang/libs-team/issues/151
2025-08-19 14:18:14 +10:00
bors
9eb4a26520 Auto merge of #145489 - joshtriplett:cfg-if-not, r=Amanieu
library: Migrate from `cfg_if` to `cfg_select`

Migrate the standard library from using the external `cfg_if` crate to using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from `library/std/Cargo.toml`, because while the standard library itself no longer uses `cfg_if`, it also incorporates the `backtrace` crate, which does.

Migration assisted by the following vim command (after selecting the full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This prompts for confirmation on the `} else {` since that can also appear inside one of the arms. This also requires manual intervention to handle any multi-line conditions.
2025-08-18 19:37:33 +00:00
binarycat
aa3008d52e implement std::fs::set_permissions_nofollow on unix 2025-08-18 11:37:19 -05:00
Jakub Beránek
a6a760edaf
Remove the From derive macro from prelude
To avoid backwards compatibility problems.
2025-08-18 13:12:19 +02:00
binarycat
ab19755630 bufreader::Buffer::backshift: don't move the uninit bytes
previous code was perfectly sound because of MaybeUninit,
but it did waste cycles on copying memory that is
known to be uninitialized.
2025-08-17 14:13:05 -05:00
Varun Gandhi
be9cd3cc0a stdlib: Replace typedef -> type alias in doc comment 2025-08-17 17:44:06 +08:00
Sebastien Marie
8792010768 Rust build fails on OpenBSD after using file_lock feature
PR 130999 added the file_lock feature, but doesn't included OpenBSD in the supported targets (Tier 3 platform), leading to a compilation error ("try_lock() not supported").
2025-08-17 09:01:28 +02:00
binarycat
2050a3b297 std: fix more typos 2025-08-16 13:36:29 -05:00
binarycat
1cb4fd7dd1 tidy now installs typos-cli as-needed via cargo 2025-08-16 13:36:29 -05:00
binarycat
e31fed054b run spellcheck as a tidy extra check in ci 2025-08-16 09:51:44 -05:00
Josh Triplett
1ae4a0cc34 library: Migrate from cfg_if to cfg_select
Migrate the standard library from using the external `cfg_if` crate to
using the now-built-in `cfg_select` macro.

This does not yet eliminate the dependency from
`library/std/Cargo.toml`, because while the standard library itself no
longer uses `cfg_if`, it also incorporates the `backtrace` crate, which
does.

Migration assisted by the following vim command (after selecting the
full `cfg_if!` invocation):

```
'<,'>s/\(cfg_if::\)\?cfg_if/cfg_select/ | '<,'>s/^\( *\)} else {/\1}\r\1_ => {/c | '<,'>s/^\( *\)} else if #\[cfg(\(.*\))\] /\1}\r\1\2 => /e | '<,'>s/if #\[cfg(\(.*\))\] {/\1 => {/e
```

This is imperfect, but substantially accelerated the process. This
prompts for confirmation on the `} else {` since that can also appear
inside one of the arms. This also requires manual intervention to handle
any multi-line conditions.
2025-08-16 05:28:31 -07:00
Alan Urmancheev
9fab380839
Fix typo in doc for library/std/src/fs.rs#set_permissions
"privalage" -> "privilege"
2025-08-16 02:30:18 +04:00
Kivooeo
b951b5dca1 stabilize strict provenance atomic ptr 2025-08-15 16:56:11 +00:00
Kivooeo
b79ab4461d stabilize const pathbuf osstring new 2025-08-15 16:36:06 +00:00
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
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
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
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
Hanna Kruppe
52063ae248 stabilize path_add_extension 2025-08-13 19:03:13 +02:00
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
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
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
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
Mara Bos
bd44d855f5 Link to payload_as_str() from payload(). 2025-08-12 12:50:48 +02: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
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
Josh Triplett
c503487a6f 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-09 15:01:58 -07:00
Ada Alakbarova
06e43655bc
HashMap: also add "Usage with custom key types" heading 2025-08-09 19:41:41 +02:00
Ada Alakbarova
c0a3e4802a
{BTree,Hash}Map: add "Entry API" section heading 2025-08-09 19:41:32 +02:00
Chris Denton
89b366955e
Replace unsafe function with safe 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.
2025-08-09 07:05:12 +00:00
Connor Tsui
ad499d076a
add nonpoison and poison rwlock tests
Adds tests for the `nonpoison::RwLock` variant by using a macro to
duplicate the existing `poison` tests.

Note that all of the tests here are adapted from the existing `poison`
tests.
2025-08-09 08:41:27 +02:00
Connor Tsui
d8a0df075d
reorganize rwlock tests
This commit simply helps discern the actual changes needed to test both
poison and nonpoison `rwlock`s.
2025-08-09 08:41:27 +02:00
Connor Tsui
4b7e904fa4
add nonpoison::rwlock implementation
Adds the equivalent `nonpoison` types to the `poison::rwlock` module.
These types and implementations are gated under the `nonpoison_rwlock`
feature gate.

Also blesses the ui tests that now have a name conflicts (because these
types no longer have unique names). The full path distinguishes the
different types.
2025-08-09 08:41:26 +02:00
Connor Tsui
d710a8e8d7
reorganize rwlock file
This commit is a purely cosmetic change to the documentation and
ordering of items in the `rwlock.rs` file, which will help discern the
actual difference between the `nonpoison` and `poison` variants of
`rwlock`.

List of changes (lots of small things):

- Clean up some of the existing field doc comments
- Add documentation for every field in struct definitions
- Consolidate related implementation blocks (1 implementation block per
  guard instead of 2)
- Use the lifetime name `'rwlock` instead of `'a`
- Reorder implementation blocks to be consistent across the entire file
  (follows the order `ReadGuard`, `WriteGuard`, `MappedReadGuard`,
  MappedWriteGuard`)
- Move simple trait implementations to the bottom of the file
- Rename the `poison` field in `MappedRwLockWriteGuard` to
  posion_guard`
- Cut off comments at 100 columns
- Update the documentation of `downgrade` to match stabilization PR #
  143191
2025-08-09 08:16:51 +02:00
Stuart Cook
f47557c4a7
Rollup merge of #145096 - Spxg:w/wasm_atomic, r=tgross35
Fix wasm target build with atomics feature

Introduced by https://github.com/rust-lang/rust/pull/115746

close https://github.com/rust-lang/rust/issues/145101
2025-08-09 13:58:51 +10:00
Jakub Beránek
8fcfbcd868
Revert "Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-items, r=RalfJung"
This reverts commit 71f04692c32e181ab566c01942f1418dec8662d4, reversing
changes made to 995ca3e532b48b689567533e6b736675e38b741e.
2025-08-08 19:16:48 +02:00
Spxg
c3e504d399 Fix wasm target build with atomics feature 2025-08-08 22:45:25 +08:00