Commit Graph

8027 Commits

Author SHA1 Message Date
Trevor Gross
a5f3b1e5df Make std/src/num mirror core/src/num
The float modules in `std` are currently top-level but for `core`, they
are nested within the `num` directory and referenced by `#[path = ...]`.
For consistency, adjust `std` to use the same structure as `core`.

Also change the `f16` and `f128` gates from outer attributes to inner
attributes like `core` has.
2025-05-29 13:10:32 +00:00
Jacob Pratt
e7ef07a523 Rollup merge of #141690 - Patrick-6:intercept-mutex, r=m-ou-se
Add `rustc_diagnostic_item` to `sys::Mutex` methods

For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes.

This PR adds diagnostic items to the relevant calls `lock`, `try_lock` and `unlock` for the `sys::Mutex` implementation on the targets we care about.
This PR also makes the internals of `pthread::Mutex` less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods.

r? ``@RalfJung``
2025-05-29 04:49:47 +02:00
Jacob Pratt
ffdd3b16dc Rollup merge of #141477 - tshepang:patch-1, r=ChrisDenton
Path::with_extension: show that it adds an extension where one did no…

…t exist

I think the times I encountered this, I had to check first if files without extensions were added, since all examples only had files with existing extensions.

Also, this replaced example already has a similar example below.
2025-05-29 04:49:41 +02:00
Jacob Pratt
d9ed86729b Rollup merge of #141104 - PaulDance:fix-win7-test_eq_windows_file_type, r=ChrisDenton
Test(fs): Fix `test_eq_windows_file_type` for Windows 7

Would otherwise fail on:

```
thread 'fs::tests::test_eq_windows_file_type' panicked at library/std/src/test_helpers.rs:53:20:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
```

This came from the read-only attribute set on the test file. In order to fix this, instead of simply disabling the test, the attribute is reset before the test's end so it may still run successfully.

`@rustbot` label T-libs A-filesystem A-testsuite O-windows-7 O-windows-msvc
2025-05-29 04:49:40 +02:00
Lukas Lueg
200d742984 Clarify &mut-methods' docs on sync::OnceLock 2025-05-28 18:31:28 +02:00
Orson Peters
9ffbc62cb6 When replacing an old value we may not drop it in place 2025-05-28 17:53:14 +02:00
Orson Peters
8785f7b122 Add same unsafe bound on get_or_init_slow 2025-05-28 17:10:50 +02:00
Patrick-6
8237107d88 Add comments to diagnostic items 2025-05-28 17:05:45 +02:00
Orson Peters
13bce27e37 Do not panic, maintain old behavior 2025-05-28 16:56:26 +02:00
Trevor Gross
7f5f29b663 Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

This PR splits `#[autodiff]` macro so `#[autodiff(df, Reverse, args)]` would become `#[autodiff_reverse(df, args)]` and `#[autodiff(df, Forward, args)]` would become `#[autodiff_forwad(df, args)]`.
2025-05-28 10:28:08 -04:00
Trevor Gross
5f17779a03 Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=Amanieu
Add data_ptr method to Mutex and RwLock

Implementation of https://github.com/rust-lang/rust/issues/140368 / https://github.com/rust-lang/libs-team/issues/531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

- Return a `LockResult` or not?
- Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
2025-05-28 10:28:07 -04:00
Patrick-6
149b5b2567 Make pthread Mutex internals less public 2025-05-28 15:13:38 +02:00
Patrick-6
2e99a880e2 Add diagnostic items to sys::Mutex 2025-05-28 15:12:56 +02:00
Orson Peters
f70cf59fc1 Improve safety comment, double-drop is not relevant here 2025-05-28 14:51:52 +02:00
Orson Peters
b0f6b69b81 Do not move thread-locals before dropping 2025-05-28 14:39:51 +02:00
Paul Mabileau
0dd5722d67 Test(fs): Fix test_eq_windows_file_type for Windows 7
Would otherwise fail on:

```
thread 'fs::tests::test_eq_windows_file_type' panicked at library/std/src/test_helpers.rs:53:20:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
```

This came from the read-only attribute set on the test file. In order to
fix this, instead of simply disabling the test, the attribute is reset
before the test's end so it may still run successfully.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-28 12:06:25 +02:00
Matthias Krüger
88b12f3649 Rollup merge of #141312 - cberner:filelock_from, r=joshtriplett
Add From<TryLockError> for io::Error

Adds a `From` impl to make error propagation easier, as discussed in the tracking issue

`TryLockError` is unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/issues/130994

This PR also cleanups the Windows implementation of `try_lock()` and `try_lock_shared()` as [discussed here](https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485)
2025-05-27 20:57:53 +02:00
Jacob Pratt
a49ae1c40f Rollup merge of #141472 - fluiderson:dev, r=workingjubilee
Attempt to improve the `std::fs::create_dir_all` docs related to atomicity

The original paragraph was added in rust-lang/rust#124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" _(which also implies directories)_ "have been created already". The code is as follows:

e88e854634/library/std/src/fs.rs (L3146)
e88e854634/library/std/src/fs.rs (L3160)

These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.
2025-05-26 03:38:18 +02:00
Jacob Pratt
9aae60befc Rollup merge of #140936 - teor2345:wtf-surrogate-docs, r=workingjubilee
Clarify WTF-8 safety docs

This PR is a follow-up to PR #140159, which clarifies ~~two things~~:
- the WTF-8 safety comment [was confusing](https://github.com/rust-lang/rust/pull/140159#discussion_r2082766965), either surrogate condition is actually sufficient for safety, both are not required
- ~~the private `os_str::Slice` type name is easily confused with `std::slice`~~

~~Happy to bikeshed the `OsSlice` name, other alternatives are `OsStrSlice` and `StrSlice`. Now it's got a distinct name from `std::slice`, it's easy to search and replace.~~

cc ``@thaliaarchi`` ``@workingjubilee``
2025-05-26 03:38:17 +02:00
Jacob Pratt
6341f4ef23 Rollup merge of #134696 - ChrisDenton:normalize-lexically, r=workingjubilee
Implement `normalize_lexically`

Implements #134694

This is, I think, the most straightforward implementation I could do, which will hopefully more easily allow experimentation if we decide to change the design here.
2025-05-26 03:38:15 +02:00
Chris Denton
c299e297ee Implement normalize lexically 2025-05-25 08:11:41 +00:00
Jacob Pratt
3338ff7dcf Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-Simulacrum
Docs(lib): Fix `extract_if` docs

Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change.

`@rustbot` label T-libs A-collections A-docs
2025-05-25 04:00:56 +02:00
Fluid
6d47489e56 improve the std::fs::create_dir_all docs related to atomicity 2025-05-25 00:34:56 +03:00
cyrgani
fab206bf58 make OsString::new and PathBuf::new unstably const 2025-05-24 22:33:11 +02:00
Tshepang Mbambo
248f4b2ad2 reduce clutter... too many imports 2025-05-24 22:17:55 +02:00
Tshepang Mbambo
a3bd12b88a Path::with_extension: improve examples 2025-05-24 22:12:15 +02:00
Guillaume Gomez
76ca0e2d62 Rollup merge of #141505 - RalfJung:catch_unwind, r=Noratrieb
rename internal panicking::try to catch_unwind

The public function is called `catch_unwind`, the intrinsic at some point got renamed to `catch_unwind` -- there's no reason to have the internal implementation of this still be called `try`, so let's rename it to match the rest.
2025-05-24 21:23:49 +02:00
Guillaume Gomez
284aaee0c1 Rollup merge of #141105 - GrantBirki:grantbirki/path-tests, r=jhpratt
additional edge cases tests for `path.rs` 🧪

This pull request adds a few new edge case tests to the `std::path` module. The new tests cover scenarios such as paths with only separators, non-ASCII and Unicode characters, embedded new lines, etc. Each new test is documented with some helpful in-line comments as well.
2025-05-24 21:23:48 +02:00
Ralf Jung
1827bc0f39 rename internal panicking::try to catch_unwind 2025-05-24 16:32:00 +02:00
Matthias Krüger
d29204071b Rollup merge of #139254 - Ayush1325:uefi-tcp4-connect, r=joboet
std: sys: net: uefi: Implement TCP4 connect

- Implement TCP4 connect using EFI_TCP4_PROTOCOL.
- Tested on QEMU setup with connecting to TCP server on host.
2025-05-24 16:08:46 +02:00
Matthias Krüger
48c4a46c8e Rollup merge of #141405 - RalfJung:GetUserProfileDirectoryW, r=ChrisDenton
GetUserProfileDirectoryW is now documented to always store the size

Update to match https://github.com/MicrosoftDocs/sdk-api/pull/1810

Also fix a bug in the Miri implementation while I am starting at that code...

r? ```@ChrisDenton```
Fixes #141254
2025-05-24 09:23:39 +02:00
Ralf Jung
587653a2fc GetUserProfileDirectoryW is now documented to always store the size 2025-05-23 22:36:40 +02:00
Matthias Krüger
be2705caf2 Rollup merge of #141398 - Dannyyy93:typos, r=Noratrieb
chore: fix typos in comment

## Fix Typos in Comments

This PR addresses several typos in the Rust standard library's documentation comments:

- In `library/std/src/sync/mpmc/list.rs`: Corrected "attemped" to "attempted"
- In `library/std/src/sys/thread_local/guard/key.rs`: Fixed "defering" to "deferring"
- In `library/std/src/sys/thread_local/guard/key.rs`: Fixed "futher" to "further"

These changes improve documentation readability and consistency without affecting any functional code.
2025-05-23 20:30:11 +02:00
Matthias Krüger
c66c8e6b9c Rollup merge of #138896 - joboet:process_noalias, r=Noratrieb
std: fix aliasing bug in UNIX process implementation

`CStringArray` contained both `CString`s and their pointers. Unfortunately, since `CString` uses `Box`, moving the `CString`s into the `Vec` can (under stacked borrows) invalidate the pointer to the string, meaning the resulting `Vec<*const c_char>` was, from an opsem perspective, unusable. This PR removes removes the `Vec<CString>` from `CStringArray`, instead recreating the `CString`/`CStr` from the pointers when necessary. Also,`CStringArray` is now used for the process args as well, the old implementation was suffering from the same kind of bug.
2025-05-23 20:30:08 +02:00
Ayush Singh
e21aab5b5c std: sys: net: uefi: Implement TCP4 connect
- Implement TCP4 connect using EFI_TCP4_PROTOCOL.
- Tested on QEMU setup with connecting to TCP server on host.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-05-23 23:49:33 +05:30
joboet
8bf515330f std: abort the process on failure to allocate a TLS key
The panic machinery uses TLS, so panicking if no TLS keys are left can lead to infinite recursion (see https://github.com/rust-lang/rust/issues/140798#issuecomment-2872307377). Rather than having separate logic for the panic count and the thread name, just always abort the process if a TLS key allocation fails. This also has the benefit of aligning the key-based TLS implementation with the documentation, which does not mention that a panic could also occur because of resource exhaustion.
2025-05-23 18:00:09 +02:00
joboet
89a90d6640 std: add safety comments to CStringArray 2025-05-23 17:09:02 +02:00
joboet
a467516c22 std: fix aliasing bug in UNIX process implementation
`CStringArray` contained both `CString`s and their pointers. Unfortunately, since `CString` uses `Box`, moving the `CString`s into the `Vec` can (under stacked borrows) invalidate the pointer to the string, meaning the resulting `Vec<*const c_char>` was, from an opsem perspective, unusable. This PR removes removes the `Vec<CString>` from `CStringArray`, instead recreating the `CString`/`CStr` from the pointers when necessary. Also,`CStringArray` is now used for the process args as well, the old implementation was suffering from the same kind of bug.
2025-05-23 17:09:00 +02:00
Matthias Krüger
dfa3110ed4 Rollup merge of #141109 - oconnor663:pipe_example, r=Mark-Simulacrum
discuss deadlocks in the std::io::pipe() example

I think it's important to discuss deadlocks in examples of how to use pipes. The current example does include an explicit `drop()`, but it also implicitly relies on the fact that the `Command` object is temporary, so that it drops its copy of `pong_tx`. This sort of thing tends to trip people up when they use pipes for the first time. I might've gone overboard with the comments in this version, but I'm curious what folks think.
2025-05-23 13:34:19 +02:00
Matthias Krüger
036607ebba Rollup merge of #141019 - ehuss:android-doctest-xcompile, r=Mark-Simulacrum
Update std doctests for android

This updates some doctests that fail to run on android. We will soon be supporting cross-compiled doctests, and the `arm-android` job fails to run these tests.

In summary:
- Android re-exports some traits from linux under a different path.
- Android doesn't seem to have common unix utilities like `true`, `false`, or `whoami`, so these are disabled.
2025-05-23 13:34:18 +02:00
Dannyyy93
d6dc08c3f4 docs: fix typos 2025-05-22 22:47:36 +08:00
Matthias Krüger
c385715806 Rollup merge of #141130 - mejrs:use_self, r=compiler-errors
rustc_on_unimplemented cleanups

Addresses some of the fixmes from https://github.com/rust-lang/rust/pull/139091 and https://github.com/rust-lang/rust/pull/140307.

- switch from `_Self` to `Self` in library
- properly validate that arguments in the `on` filter and the format strings are actually valid

See https://github.com/rust-lang/rustc-dev-guide/pull/2357 for the relevant documentation.
2025-05-22 16:02:30 +02:00
bors
6eef33bb39 Auto merge of #137198 - tgross35:cfg-match-rename, r=Amanieu
Rename `cfg_match!` to `cfg_select!`

[`@Nemo157` pointed out](https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605) that `cfg_match!` syntax does not actually align well with match syntax, which is a possible source of confusion. The comment points out that usage is instead more similar to ecosystem `select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

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

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-22 02:14:23 +00:00
Matthias Krüger
b9c6b337ce Rollup merge of #141341 - folkertdev:limit-VaArgSafe-impls, r=workingjubilee
limit impls of `VaArgSafe` to just types that are actually safe

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

Retrieving 8- or 16-bit integer arguments from a `VaList` is not safe, because such types are subject to upcasting. See https://github.com/rust-lang/rust/issues/61275#issuecomment-2193942535 for more detail.

This PR also makes the instances of `VaArgSafe` visible in the documentation, and uses a private sealed trait to make sure users cannot create additional impls of `VaArgSafe`, which would almost certainly cause UB.

r? `@workingjubilee`
2025-05-21 22:14:58 +02:00
Folkert de Vries
d8a22a281c limit impls of VaArgSafe to just types that are actually safe
8 and 16-bit integers are subject to upcasting in C, and hence are not reliably safe. users should perform their own casting and deal with the consequences
2025-05-21 15:36:29 +02:00
Matthias Krüger
7b4f7a376b Rollup merge of #137759 - joshtriplett:command-chroot, r=Amanieu
Add `std::os::unix::process::CommandExt::chroot` to safely chroot a child process

This adds a `chroot` method to the `CommandExt` extension trait for the
`Command` builder, to set a directory to chroot into. This will chroot
the child process into that directory right before calling chdir for the
`Command`'s working directory.

To avoid allowing a process to have a working directory outside of the
chroot, if the `Command` does not yet have a working directory set,
`chroot` will set its working directory to "/".

---

ACP: https://github.com/rust-lang/libs-team/issues/551

This PR currently has the tracking issue set to "none"; if the ACP is approved,
I'll file a tracking issue and update the PR.
2025-05-21 11:28:44 +02:00
Marcelo Domínguez
b725cf6af8 Disable autodiff bootstrapping 2025-05-21 07:24:33 +00:00
Jonas Platte
20589bd605 Add ReentrantLock::data_ptr 2025-05-21 08:07:43 +02:00
Jonas Platte
9d6c5a88a1 Add more docs to new data_ptr methods 2025-05-21 08:07:43 +02:00
Jonas Platte
9efad3a87b Add data_ptr method to Mutex and RwLock 2025-05-21 08:07:43 +02:00