Commit Graph

7464 Commits

Author SHA1 Message Date
Matthias Krüger
458095aa17
Rollup merge of #137107 - thaliaarchi:io-optional-methods/cursors, r=joboet
Override default `Write` methods for cursor-like types

Override the default `io::Write` methods for cursor-like types to provide more efficient versions.

Writes to resizable containers already write everything, so implement `write_all` and `write_all_vectored` in terms of those. For fixed-sized containers, cut out unnecessary error checking and looping for those same methods.

| `impl Write for T`              | `vectored` | `all` | `all_vectored` | `fmt`   |
| ------------------------------- | ---------- | ----- | -------------- | ------- |
| `&mut [u8]`                     | Y          | Y     | new            |         |
| `Vec<u8>`                       | Y          | Y     | new            | #137762 |
| `VecDeque<u8>`                  | Y          | Y     | new            | #137762 |
| `std::io::Cursor<&mut [u8]>`    | Y          | new   | new            |         |
| `std::io::Cursor<&mut Vec<u8>>` | Y          | new   | new            | #137762 |
| `std::io::Cursor<Vec<u8>>`      | Y          | new   | new            | #137762 |
| `std::io::Cursor<Box<[u8]>>`    | Y          | new   | new            |         |
| `std::io::Cursor<[u8; N]>`      | Y          | new   | new            |         |
| `core::io::BorrowedCursor<'_>`  | new        | new   | new            |         |

Tracked in https://github.com/rust-lang/rust/issues/136756.

# Open questions

Is it guaranteed by `Write::write_all` that the maximal write is performed when not everything can be written? Its documentation describes the behavior of the default implementation, which writes until a 0-length write is encountered, thus implying that a maximal write is expected. In contrast, `Read::read_exact` declares that the contents of the buffer are unspecified for short reads. If it were allowed, these cursor-like types could bail on the write altogether if it has insufficient capacity.
2025-03-07 10:02:20 +01:00
Thalia Archibald
988eb19970 library: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-06 20:20:38 -08:00
Santiago Pastorino
a68db7e3a8
Add examples in stdlib demonstrating the use syntax 2025-03-06 17:58:34 -03:00
Michael Goulet
071bc46880
Rollup merge of #138038 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.151

This enables `f16` builtins for loongarch [1] and adds support for Cygwin [2].

[1]: https://github.com/rust-lang/compiler-builtins/pull/770
[2]: https://github.com/rust-lang/compiler-builtins/pull/774

try-job: dist-loongarch64-linux
try-job: dist-loongarch64-musl
2025-03-06 12:22:29 -05:00
Michael Goulet
978893ac40
Rollup merge of #137327 - arlosi:home-dir, r=Mark-Simulacrum
Undeprecate env::home_dir

#132515 fixed the implementation of `env::home_dir`, but didn't remove the deprecation.

Based on [this comment](https://github.com/rust-lang/rust/pull/132515#discussion_r1829715262), libs-api decided to undeprecate in the next release. Let's do that!

cc #132650
2025-03-06 12:22:11 -05:00
许杰友 Jieyou Xu (Joe)
24d481cc29
Rollup merge of #137477 - Ayush1325:uefi-service-binding, r=Noratrieb
uefi: Add Service Binding Protocol abstraction

- Some UEFI protocols such as TCP4, TCP6, UDP4, UDP6, etc are managed by service binding protocol.
- A new instance of such protocols is created and destroyed using the corresponding service binding protocol.
- This PR adds abstractions to make using such protocols simpler using Rust Drop trait.
- The reason to add these abstractions in a seperate PR from TCP4 Protocol is to make review easier.

[EFI_SERVICE_BINDING_PROTCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol)

cc ````@nicholasbishop````
2025-03-05 21:46:40 +08:00
许杰友 Jieyou Xu (Joe)
fde23c87a5
Rollup merge of #137463 - sunshowers:illumos-posix-spawn, r=Mark-Simulacrum
[illumos] attempt to use posix_spawn to spawn processes

illumos has `posix_spawn`, and the very newest versions also have `_addchdir`, so use that. POSIX standardized this function so I also added a weak symbol lookup for the non `_np` version. (illumos has both.)

This probably also works on Solaris, but I don't have access to an installation to validate this so I decided to focus on illumos instead.

This is a nice ~4x performance improvement for process creation. My go-to as usual is nextest against the clap repo, which acts as a stress test for process creation -- with [this commit]:

```console
$ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)'
before: Summary [   1.747s] 879 tests run: 879 passed, 2 skipped
after:  Summary [   0.445s] 879 tests run: 879 passed, 2 skipped
```

[this commit]: fde45f9aea
2025-03-05 21:46:40 +08:00
许杰友 Jieyou Xu (Joe)
4f1a0479a7
Rollup merge of #137240 - jieyouxu:remove_dir_all, r=Mark-Simulacrum
Slightly reformat `std::fs::remove_dir_all` error docs

To make the error cases easier to spot on a quick glance, as I've been bitten by this a couple of times already 💀

cc #137230.
2025-03-05 21:46:38 +08:00
许杰友 Jieyou Xu (Joe)
6c4ce3ad95
Rollup merge of #136798 - pcorwin:master, r=tgross35
Added documentation for flushing per #74348

Resolves #74348
2025-03-05 21:46:34 +08:00
bors
4559163ccb Auto merge of #138031 - workingjubilee:rollup-5bsotpz, r=workingjubilee
Rollup of 15 pull requests

Successful merges:

 - #137829 (Stabilize [T]::split_off... methods)
 - #137850 (Stabilize `box_uninit_write`)
 - #137912 (Do not recover missing lifetime with random in-scope lifetime)
 - #137913 (Allow struct field default values to reference struct's generics)
 - #137923 (Simplify `<Postorder as Iterator>::size_hint`)
 - #137949 (Update MSVC INSTALL.md instructions to recommend VS 2022 + recent Windows 10/11 SDK)
 - #137963 (Add ``dyn`` keyword to `E0373` examples)
 - #137975 (Remove unused `PpMode::needs_hir`)
 - #137981 (rustdoc search: increase strictness of typechecking)
 - #137986 (Fix some typos)
 - #137991 (Add `avr-none` to SUMMARY.md and platform-support.md)
 - #137993 (Remove obsolete comment from DeduceReadOnly)
 - #137996 (Revert "compiler/rustc_data_structures/src/sync/worker_local.rs: delete "unsafe impl Sync"")
 - #138019 (Pretty-print `#[deprecated]` attribute in HIR.)
 - #138026 (Make CrateItem::body() function return an option)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-05 06:59:11 +00:00
Trevor Gross
7923031e7e Update compiler-builtins to 0.1.151
This enables `f16` builtins for loongarch [1] and adds support for
Cygwin [2].

[1]: https://github.com/rust-lang/compiler-builtins/pull/770
[2]: https://github.com/rust-lang/compiler-builtins/pull/774
2025-03-05 01:35:02 -05:00
Jubilee
dd594f642e
Rollup merge of #137634 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.149

Includes a change to make a subset of math symbols available on all platforms [1], and disables `f16` on aarch64 without neon [2].

[1]: https://github.com/rust-lang/compiler-builtins/pull/763
[2]: https://github.com/rust-lang/compiler-builtins/pull/775

try-job: aarch64-gnu
try-job: aarch64-gnu-debug
try-job: armhf-gnu
try-job: dist-various-1
try-job: dist-various-2
try-job: dist-aarch64-linux
try-job: dist-arm-linux
try-job: dist-armv7-linux
try-job: dist-x86_64-linux
try-job: test-various
2025-03-04 14:50:40 -08:00
pcorwin
c392cf7690 Added documentation for flushing 2025-03-04 12:21:12 -05:00
Henry Jiang
2a7ad952a7 Fix test hangs on AIX 2025-03-04 10:06:28 -05:00
fuyangpengqi
4febd273e5 Fix some typos
Signed-off-by: fuyangpengqi <995764973@qq.com>
2025-03-04 16:05:32 +08:00
Matthias Krüger
8152da82b5
Rollup merge of #137873 - tgross35:disable-f16-without-neon, r=workingjubilee
Disable `f16` on Aarch64 without `neon`

LLVM has crashes at some `half` operations when built with assertions enabled if fp-armv8 is not available [1]. Things seem to usually work, but we are reaching LLVM undefined behavior so this needs to be disabled.

[1]: https://github.com/llvm/llvm-project/issues/129394
2025-03-02 22:44:26 +01:00
Matthias Krüger
f47c7e8564
Rollup merge of #137375 - steffahn:clarify-read_line-comment, r=Mark-Simulacrum
Minor internal comments fix for `BufRead::read_line`

Just a little fix that came up while I was reading through this source code, and had to search for a few minutes to find out what was actually *meant* here.
2025-03-02 22:44:23 +01:00
Trevor Gross
c51b229140 Disable f16 on Aarch64 without neon
LLVM has crashes at some `half` operations when built with assertions
enabled if fp-armv8 is not available [1]. Things seem to usually work,
but we are reaching LLVM undefined behavior so this needs to be
disabled.

[1]: https://github.com/llvm/llvm-project/issues/129394
2025-03-01 23:10:21 +00:00
Trevor Gross
8b4007a91d Update compiler-builtins to 0.1.150
Includes a change to make a subset of math symbols available on all
platforms [1], and disables `f16` on aarch64 without neon [2].

[1]: https://github.com/rust-lang/compiler-builtins/pull/763
[2]: https://github.com/rust-lang/compiler-builtins/pull/775
2025-03-01 20:02:51 +00:00
Ayush Singh
86aae8e2d6
uefi: Add Service Binding Protocol abstraction
- Some UEFI protocols such as TCP4, TCP6, UDP4, UDP6, etc are managed by
  service binding protocol.
- A new instance of such protocols is created and destroyed using the
  corresponding service binding protocol.
- This PR adds abstractions to make using such protocols simpler using
  Rust Drop trait.
- The reason to add these abstractions in a seperate PR from TCP4
  Protocol is to make review easier.

[EFI_SERVICE_BINDING_PROTCOL](https://uefi.org/specs/UEFI/2.11/11_Protocols_UEFI_Driver_Model.html#efi-service-binding-protocol)

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-02 01:02:42 +05:30
Matthias Krüger
bc89ab19c3
Rollup merge of #137809 - Noratrieb:io-error-casing, r=thomcc
Use correct error message casing for `io::const_error`s

Error messages are supposed to start with lowercase letters, but a lot of `io::const_error` messages did not. This fixes them to start with a lowercase letter.
I did consider adding a const check for this to the macro, but some of them start with proper nouns that make sense to uppercase them.

See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-03-01 16:03:13 +01:00
Will Woods
6d07144613 Fix logic error in Buffer::read_more()
Buffer::read_more() is supposed to refill the buffer without discarding
its contents, which are in the range `pos .. filled`.

It mistakenly borrows the range `pos ..`, fills that, and then
increments `filled` by the amount read. This overwrites the buffer's
existing contents and sets `filled` to a too-large value that either
exposes uninitialized bytes or walks off the end of the buffer entirely.

This patch makes it correctly fill only the unfilled portion of the
buffer, which should maintain all the type invariants and fix the test
failure introduced in commit b1196717fc.
2025-02-28 17:36:19 -08:00
Will Woods
b1196717fc Tweak BufReader::peek() doctest to expose bug in Buffer::read_more()
This patch makes BufReader::peek()'s doctest call read_more() to refill
the buffer before the inner reader hits EOF. This exposes a bug in
read_more() that causes an out-of-bounds slice access and segfault.
2025-02-28 17:30:53 -08:00
Thalia Archibald
83407b828b Specialize constructing OsString from strings
The WTF-8 version of `OsString` tracks whether it is known to be valid
UTF-8 with its `is_known_utf8` field. Specialize `From<AsRef<OsStr>>` so
this can be set for UTF-8 string types.
2025-02-28 13:50:31 -08:00
Thalia Archibald
a8d78fec52 Specialize OsString::push for strings
When concatenating two WTF-8 strings, surrogate pairs at the boundaries
need to be joined. However, since UTF-8 strings cannot contain surrogate
halves, this check can be skipped when one string is UTF-8. Specialize
`OsString::push` to use a more efficient concatenation in this case.

Unfortunately, a specialization for `T: AsRef<str>` conflicts with
`T: AsRef<OsStr>`, so stamp out string types with a macro.
2025-02-28 13:42:31 -08:00
Noratrieb
cdef38812d Use correct error message casing for io::const_errors
Error messages are supposed to start with lowercase letters, but a lot
of `io::const_error` messages did not. This fixes them to start with a
lowercase letter.
I did consider adding a const check for this to the macro, but some of
them start with proper nouns that make sense to uppercase them.

See https://doc.rust-lang.org/1.85.0/std/error/trait.Error.html
2025-02-28 17:50:38 +01:00
许杰友 Jieyou Xu (Joe)
4606610b21
Rollup merge of #137673 - ChrisDenton:search-path-bug, r=dtolnay
Fix Windows `Command` search path bug

Currently `Command::new` on Windows works differently depending on whether any environment variable is set. For example,

```rust
// Searches for "myapp" in the application and system paths first (aka Windows native behaviour).
Command::new("myapp").spawn();

// Search for "myapp" in `PATH` first
Command::new("myapp").env("a", "b").spawn();
```

This is a bug because the search path should only change if `PATH` is changed for the child (i.e. `.env("PATH", "...")`).

This was discussed in a libs-api meeting where the exact semantics of `Command::new` was not decided but there seemed to be broad agreement that this particular thing is just a bug that can be fixed.

r? libs-api
2025-02-28 22:29:53 +08:00
Thalia Archibald
41bdd2b74a Override default Write methods for cursor-like types 2025-02-27 17:09:09 -08:00
Thalia Archibald
67cc82a704 Inline VecDeque<u8> and BorrowedCursor methods
All other methods in this file have #[inline] and these methods are very
similar to those of &[u8] which are already inlined here.
2025-02-27 17:07:20 -08:00
Matthias Krüger
f19d4b5f97
Rollup merge of #137480 - fuzzypixelz:fix/124466, r=workingjubilee
Return unexpected termination error instead of panicing in `Thread::join`

There is a time window during which the OS can terminate a thread before stdlib can retreive its `Packet`. Currently the `Thread::join` panics with no message in such an event, which makes debugging difficult; fixes #124466.
2025-02-27 08:56:39 +01:00
León Orell Valerian Liehr
c5d57274c0
Rollup merge of #137620 - SergioGasquez:fix/espidf-maybeunit, r=ChrisDenton
Fix `attr` cast for espidf

https://github.com/rust-lang/rust/pull/136826 broke ESP-IDF builds with: https://github.com/esp-rs/esp-idf-template/actions/runs/13516221587/job/37765336588.

This PR fixes it.

cc: ``@ivmarkov`` ``@xizheyin``
2025-02-26 19:03:55 +01:00
Chris Denton
4fcebee60a
Fix Windows Command search path bug 2025-02-26 13:56:47 +00:00
WANG Rui
30703af6f3 Enable f16 for LoongArch 2025-02-26 21:40:14 +08:00
León Orell Valerian Liehr
49249eae11
Rollup merge of #137311 - martn3:enable-f16-mips, r=tgross35
Enable `f16` for MIPS

Blocked on https://github.com/rust-lang/compiler-builtins/pull/762

It seems as if `f16` works on MIPS now according to my testing on Rust master with LLVM 20, and I was asked [here](https://github.com/rust-lang/rust/pull/137167#issuecomment-2669387820) to create PRs with my changes.

I only tested on the flavour of `mipsel-unknown-linux-gnu` hardware that happens to be available to me, so I can't say anything about other MIPS hardware, but from a casual skimming of the LLVM code ([1], [2]) it seems like `f16` should work on all MIPS hardware. So enable it for all MIPS hardware.

[1]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/Target/Mips/MipsISelLowering.h#L370
[2]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1367-L1388

`@rustbot` label +O-MIPS +F-f16_and_f128 +S-blocked

Tracking issue for f16: https://github.com/rust-lang/rust/issues/116909

r? `@tgross35`
2025-02-26 04:15:03 +01:00
León Orell Valerian Liehr
e121dcffbe
Rollup merge of #137154 - thaliaarchi:wtf8-fast-paths, r=ChrisDenton
Add UTF-8 validation fast paths in `Wtf8Buf`

This adds two more fast paths for UTF-8 validation in `Wtf8Buf`, making use of the `is_known_utf8` flag added in https://github.com/rust-lang/rust/pull/96869 (Optimize `Wtf8Buf::into_string` for the case where it contains UTF-8).

r? `@ChrisDenton`
2025-02-26 04:15:02 +01:00
Sergio Gasquez
622b4fac82 fix: attr cast for espidf 2025-02-25 16:07:05 +01:00
León Orell Valerian Liehr
86fa9f895c
Rollup merge of #137515 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.148

Includes `f16` symbols on MIPS [1], updates for `libm` [2], and reapplies the patch that drops the `public_test_deps!` macro [3].

[1]: https://github.com/rust-lang/compiler-builtins/pull/762
[2]: https://github.com/rust-lang/compiler-builtins/pull/765
[3]: https://github.com/rust-lang/compiler-builtins/pull/766

try-job: aarch64-gnu
try-job: i686-mingw-1
try-job: i686-mingw-2
try-job: test-various
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
try-job: x86_64-rust-for-linux
2025-02-25 13:32:55 +01:00
Mahmoud Mazouz
7058f62d0a
Use .expect(..) instead 2025-02-25 13:11:03 +01:00
bors
ad27045c31 Auto merge of #137571 - tgross35:rollup-i1tcnv1, r=tgross35
Rollup of 8 pull requests

Successful merges:

 - #134655 (Stabilize `hash_extract_if`)
 - #135933 (Explain how Vec::with_capacity is faithful)
 - #136668 (Stabilize `core::str::from_utf8_mut` as `const`)
 - #136775 (Update `String::from_raw_parts` safety requirements)
 - #137109 (stabilize extract_if)
 - #137349 (Implement `read_buf` for zkVM stdin)
 - #137493 (configure.py: don't instruct user to run nonexistent program)
 - #137516 (remove some unnecessary rustc_const_unstable)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-25 05:41:34 +00:00
Michael Goulet
74e5366020
Rollup merge of #137543 - petrochenkov:wintest, r=ChrisDenton
std: Fix another new symlink test on Windows

Checking for `got_symlink_permission` first is a standard procedure for such tests.
2025-02-24 19:21:48 -05:00
Michael Goulet
1cd083d73f
Rollup merge of #137321 - aviraxp:patch-1, r=cuviper
Correct doc about `temp_dir()` behavior on Android

Since commit d5ccb038f6, `TMPDIR` will be set to application's cache dir when app starts.
2025-02-24 19:21:46 -05:00
Trevor Gross
50940109cc
Rollup merge of #137349 - thaliaarchi:io-optional-methods/zkvm, r=Noratrieb
Implement `read_buf` for zkVM stdin

For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See https://github.com/risc0/risc0/issues/2853.

cc `@bobbobbio,` `@flaub`

r? `@Noratrieb`

Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-24 18:46:36 -05:00
Trevor Gross
23e113200d
Rollup merge of #134655 - GrigorenkoPV:hash_extract_if, r=cuviper
Stabilize `hash_extract_if`

FCP complete: https://github.com/rust-lang/rust/issues/59618#issuecomment-2674880530

Tracking issue: #59618
Closes #59618
2025-02-24 18:46:33 -05:00
David Wood
d6bb98e757
span: add a "future" edition
It's hard to implement edition migrations without having a perma-unstable
"future" edition to target.
2025-02-24 14:35:30 +00:00
Vadim Petrochenkov
9c65672397 std: Fix another new symlink test on Windows 2025-02-24 17:12:37 +03:00
Mahmoud Mazouz
1ccdc06136
Remove speculation on cause of error
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-02-24 09:50:46 +01:00
Trevor Gross
fb5f804f52 Update compiler-builtins to 0.1.148
Includes `f16` symbols on MIPS [1], updates for `libm` [2], and
reapplies the patch that drops the `public_test_deps!` macro [3].

[1]: https://github.com/rust-lang/compiler-builtins/pull/762
[2]: https://github.com/rust-lang/compiler-builtins/pull/765
[3]: https://github.com/rust-lang/compiler-builtins/pull/766
2025-02-24 07:46:55 +00:00
Jacob Pratt
56fca2638f
Rollup merge of #137482 - rust9x:win-file-open-truncate, r=ChrisDenton
Windows: use existing wrappers in `File::open_native`

Just a small improvement I've noticed - prevents accidents regarding `SetFileInformationByHandle` parameters.

Probably ``@ChrisDenton`` since we talked about it on discord :)
2025-02-24 02:11:34 -05:00
Trevor Gross
fb54acd700
Rollup merge of #137297 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.147

Removes an ABI hack that used `<2 x i64>` to return `i128` in `xmm0` on Windows [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/759
Link: https://github.com/rust-lang/rust/issues/116558
Link: https://github.com/rust-lang/compiler-builtins/issues/758

try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
2025-02-23 14:30:27 -05:00
Trevor Gross
a2bb4d748d
Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35
intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic

LLVM has three intrinsics here that all do the same thing (when used in the default FP environment). There's no reason Rust needs to copy that historically-grown mess -- let's just have one intrinsic and leave it up to the LLVM backend to decide how to lower that.

Suggested by `@hanna-kruppe` in https://github.com/rust-lang/rust/issues/136459; Cc `@tgross35`

try-job: test-various
2025-02-23 14:30:25 -05:00
Dennis Duda
87c0380799 Win: use existing wrappers for SetFileInformationByHandle in File::open_native 2025-02-23 14:19:58 +01:00
Mahmoud Mazouz
db1f0d0458
Return error on unexpected termination in Thread::join.
There is a time window during which the OS can terminate a thread before stdlib
can retreive its `Packet`. Currently the `Thread::join` panics with no message
in such an event, which makes debugging difficult; fixes #124466.
2025-02-23 12:26:16 +01:00
bors
b880760977 Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrum
Master bootstrap update

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday

r? `@Mark-Simulacrum`
2025-02-23 11:12:56 +00:00
Jacob Pratt
2ff53a293e
Rollup merge of #137194 - kornelski:ftls, r=tgross35
More const {} init in thread_local

`const {}` in `thread_local!` gets an optimization just based on the syntax, rather than the expression being const-compatible. This is easy to miss, so I've added more examples to the docs.

I've also added `const {}` in a couple of places in std where this optimization has been missed.
2025-02-23 02:44:17 -05:00
Jacob Pratt
4493159b35
Rollup merge of #136826 - xizheyin:issue-136737, r=thomcc
Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in Unix

As discussion in #136737.

- Replace `mem::zeroed()` with `MaybeUninit::uninit()` for `sockaddr_storage` in `accept()` and `recvfrom()` since these functions fill in the address structure
- Replace `mem::zeroed()` with `MaybeUninit::uninit()` for `pthread_attr_t` in thread-related functions since `pthread_attr_init()` initializes the structure
- Add references to man pages to document this behavior
2025-02-23 02:44:16 -05:00
Rain
b340545114 [illumos] attempt to use posix_spawn to spawn processes
illumos has `posix_spawn`, and the very newest versions also have `_addchdir`,
so use that.

This is a nice ~4x performance improvement for process creation. My go-to as
usual is nextest against the clap repo, which acts as a stress test for process
creation -- with [this commit]:

```console
$ cargo nextest run -E 'not test(ui_tests) and not test(example_tests)'
before: Summary [   1.747s] 879 tests run: 879 passed, 2 skipped
after:  Summary [   0.445s] 879 tests run: 879 passed, 2 skipped
```

[this commit]: fde45f9aea
2025-02-23 06:49:59 +00:00
Trevor Gross
08f1086bf0 Update compiler-builtins to 0.1.147
Removes an ABI hack that used `<2 x i64>` to return `i128` in `xmm0` on
Windows [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/759
Link: https://github.com/rust-lang/rust/issues/116558
Link: https://github.com/rust-lang/compiler-builtins/issues/758
2025-02-23 06:13:09 +00:00
Matthias Krüger
1610bfb6af
Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3
Inject `compiler_builtins` during postprocessing and ensure it is made private

Follow up of https://github.com/rust-lang/rust/pull/135278

Do the following:

* Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST
* Do not make dependencies of `std` private by default (this was added in #135278)
* Make sure sysroot crates correctly mark their dependencies private/public
* Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified
* Do the `compiler_builtins` update that has been blocked on this

There is more detail in the commit messages. This includes the changes I was working on in https://github.com/rust-lang/rust/pull/136226.

try-job: test-various
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
try-job: i686-mingw-1
try-job: i686-mingw-2
2025-02-23 00:16:18 +01:00
Ralf Jung
d1b34acb3b make the new intrinsics safe 2025-02-22 14:12:55 +01:00
Matthias Krüger
d3e46d2e72
Rollup merge of #137388 - PaulDance:disable-rename-posix-semantics-tests-under-win7, r=ChrisDenton
Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7

Would otherwise fail there. The Windows7-specific parts were left pretty much untouched by the changes introduced by
51df98ddb0, so it is expected that these tests fail under Windows 7 as they were probably written to run under Windows 10+ only.
2025-02-22 11:36:46 +01:00
Paul Mabileau
6ed53a624b
Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7
Would otherwise fail there. The Windows7-specific parts were left pretty
much untouched by the changes introduced by
51df98ddb0, so it is expected that these
tests fail under Windows 7 as they were probably written to run under
Windows 10+ only.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-02-21 20:49:04 +01:00
Matthias Krüger
ef14e9a6d0
Rollup merge of #137353 - thaliaarchi:io-optional-methods/wasi-stdin, r=alexcrichton
Implement `read_buf` for WASI stdin

`WasiFd::read_buf` already exists. Simply use it in `Stdin`.

cc `@alexcrichton`

Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-21 19:01:15 +01:00
Matthias Krüger
2dc7573edd
Rollup merge of #137336 - riverbl:stabilise-os-str-display, r=tgross35
Stabilise `os_str_display`

Closes #120048.
2025-02-21 19:01:14 +01:00
Matthias Krüger
28164f1229
Rollup merge of #136148 - kpreid:type-str, r=joboet
Optionally add type names to `TypeId`s.

This feature is intended to provide expensive but thorough help for developers who have an unexpected `TypeId` value and need to determine what type it actually is. It causes `impl Debug for TypeId` to print the type name in addition to the opaque ID hash, and in order to do so, adds a name field to `TypeId`. The cost of this is the increased size of `TypeId` and the need to store type names in the binary; therefore, it is an optional feature. It does not expose any new public API, only change the `Debug` implementation.

It may be enabled via `cargo -Zbuild-std -Zbuild-std-features=debug_typeid`. (Note that `-Zbuild-std-features` disables default features which you may wish to reenable in addition; see
<https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features>.)

Example usage and output:

```
fn main() {
    use std::any::{Any, TypeId};
    dbg!(TypeId::of::<usize>(), drop::<usize>.type_id());
}
```

```
TypeId::of::<usize>() = TypeId(0x763d199bccd319899208909ed1a860c6 = usize)
drop::<usize>.type_id() = TypeId(0xe6a34bd13f8c92dd47806da07b8cca9a = core::mem::drop<usize>)
```

Also added feature declarations for the existing `debug_refcell` feature so it is usable from the `rust.std-features` option of `config.toml`.

Related issues:

* #68379
* #61533
2025-02-21 19:01:12 +01:00
Trevor Gross
93925809eb Replace some instances of pub with pub(crate)
The recent fixes to private dependencies exposed some cases in the UEFI
module where private dependencies are exposed in a public interface.
These do not need to be crate-public, so change them to `pub(crate)`.
2025-02-21 17:37:03 +00:00
Kornel
4742dbc765
Use faster thread_local! for stdout 2025-02-21 13:09:16 +00:00
Kornel
ad566646cf
Use faster thread_local in current_thread_id() 2025-02-21 13:09:16 +00:00
Kornel
b94162078d
Highlight thread_local! const init in docs 2025-02-21 13:02:42 +00:00
bors
9f48dedc97 Auto merge of #137192 - kornelski:windows-tls-lto, r=ChrisDenton
Remove obsolete Windows ThinLTO+TLS workaround

The bug #109797 has been fixed by #129079, so this workaround is no longer needed.
2025-02-21 11:43:00 +00:00
Frank Steffahn
bf26f24423 Clarify/update comments in BufRead::read_line's default body
with where to *actually* look for more details
2025-02-21 03:56:49 +01:00
Thalia Archibald
d32eeb86b2 Implement read_buf for WASI stdin 2025-02-20 17:06:33 -07:00
Thalia Archibald
98b0f050cf Implement read_buf for zkVM stdin
For the zkVM, even when a guest buffer is uninitialized, from the host's
perspective it is just a normal piece of memory which was initialized
before letting the guest write into it. This makes `sys_read` safe to
use with an uninitialized buffer. See
https://github.com/risc0/risc0/issues/2853.
2025-02-20 16:07:12 -07:00
Jubilee
f24b140976
Rollup merge of #137270 - QianNangong:master, r=ChrisDenton
Fix `*-win7-windows-msvc` target since 26eeac1a1e

That commit make it failed to build `std` with `*-win7-windows-msvc` so fix it.
2025-02-20 14:58:18 -08:00
riverbl
5112ecb8ca Stabilise os_str_display 2025-02-20 19:12:06 +00:00
Arlo Siemsen
2c752bcf55 Undeprecate env::home_dir 2025-02-20 11:47:14 -06:00
Wang Han
0d4d752e83
Correct doc about temp_dir() behavior on Android
Since commit d5ccb038f6, `TMPDIR` will be set to application's cache dir when app starts.
2025-02-21 00:13:55 +08:00
Martin Nordholts
cf1242c461 Enable f16 for MIPS
It seems as if `f16` works on MIPS now according to my
testing on Rust master with LLVM 20, and I was asked to
create PRs with my changes.

I only tested on the flavour of `mipsel-unknown-linux-gnu`
hardware that happens to be available to me, so I can't say
anything about other MIPS hardware, but from a casual
skimming of the LLVM code ([1], [2]) it seems like `f16`
should work on all MIPS hardware. So enable it for all MIPS
hardware.

[1]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/Target/Mips/MipsISelLowering.h#L370
[2]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1367-L1388
2025-02-20 11:34:48 +01:00
Thalia Archibald
eb14652770 Skip scanning for surrogates when not known valid 2025-02-19 18:43:24 -08:00
Thalia Archibald
0842f2c65c Add fast path for displaying pre-validated Wtf8Buf 2025-02-19 18:43:24 -08:00
bors
4e1356b959 Auto merge of #137290 - matthiaskrgr:rollup-a7xdbi4, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #120580 (Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants)
 - #132268 (Impl TryFrom<Vec<u8>> for String)
 - #136093 (Match Ergonomics 2024: update old-edition behavior of feature gates)
 - #136344 (Suggest replacing `.` with `::` in more error diagnostics.)
 - #136690 (Use more explicit and reliable ptr select in sort impls)
 - #136815 (CI: Stop /msys64/bin from being prepended to PATH in msys2 shell)
 - #136923 (Lint `#[must_use]` attributes applied to methods in trait impls)
 - #137155 (Organize `OsString`/`OsStr` shims)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-19 23:29:37 +00:00
Matthias Krüger
3964bb131b
Rollup merge of #137155 - thaliaarchi:wtf8-organize, r=ChrisDenton
Organize `OsString`/`OsStr` shims

Synchronize the `bytes.rs` and `wtf8.rs` shims for `OsString`/`OsStr` so they're easier to diff between each other. This is mostly ordering items the same between the two. I tried to minimize moves and went for the average locations between the files.

With them in the same order, it is clear that `FromInner<_>` is not implemented for `bytes::Buf` and `Clone::clone_from` is not implemented for `wtf8::Buf`, but they are for the other. Fix that.

I added #[inline] to all inherent methods of the `OsString`/`OsStr` shims, because it seemed that was already the rough pattern. `bytes.rs` has more inlining than `wtf8.rs`, so I added the corresponding ones to `wtf8.rs`. Then, the common missing ones have no discernible pattern to me. They're not divided by non-allocating/allocating. Perhaps the pattern is that UTF-8 validation isn't inlined? Since these types are merely the inner values in `OsStr`/`OsString`, I put inline on all methods and let those public types dictate inlining. I have not inspected codegen or run benchmarks.

Also, touch up some (private) documentation comments.

r? ``````@ChrisDenton``````
2025-02-19 21:16:12 +01:00
Matthias Krüger
84e9f29007
Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=m-ou-se
Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants

This pull request adds the `MAX_LEN_UTF8` and `MAX_LEN_UTF16` constants as per #45795, gated behind the `char_max_len` feature.

The constants are currently applied in the `alloc`, `core` and `std` libraries.
2025-02-19 21:16:01 +01:00
Matthias Krüger
ce72b8d91e
Rollup merge of #136794 - cberner:stabilize, r=joshtriplett
Stabilize file_lock

Closes #130994
2025-02-19 18:52:06 +01:00
Matthias Krüger
e6406ad4dd
Rollup merge of #136347 - allevo:patch-1, r=Amanieu
Add a bullet point to `std::fs::copy`

I needed to copy a file but I got the following error:
```
Os { code: 2, kind: NotFound, message: "No such file or directory" }
```
After read the documentation, I though the error was generated by the `from` parameter, forgetting the `to` part. Anyway, I got the error because the parent folder of `to` didn't exist.
Even if the documentation explicitly saying `but is not limited to just these cases`, I would like to add this case because I spent 3 hours around it.

This PR just wants to put a mention about it.
2025-02-19 18:52:05 +01:00
Matthias Krüger
2c1e1bd2cb
Rollup merge of #136301 - hkBst:patch-33, r=thomcc
Improve instant docs

This should be enough to close #79881.
2025-02-19 18:52:04 +01:00
xizheyin
70f11ee0c0
fix by comments
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-19 20:16:28 +08:00
Li Keqing
35febd7a6d Fix *-win7-windows-msvc target since 26eeac1a1e 2025-02-19 18:05:37 +08:00
Tommaso Allevi
3ad847779e
Update library/std/src/fs.rs
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-02-19 09:17:18 +01:00
xizheyin
604364fcf4
remove assume_init in stack_overflow
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-19 13:20:03 +08:00
bors
f44efbf9e1 Auto merge of #137235 - matthiaskrgr:rollup-2kjua2t, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #135711 (Do not ICE on default_field_value const with lifetimes)
 - #136599 (librustdoc: more usages of `Joined::joined`)
 - #136876 (Locking documentation updates)
 - #137000 (Deeply normalize item bounds in new solver)
 - #137126 (fix docs for inherent str constructors)
 - #137161 (Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions)
 - #137191 (Update mdbook and move error_index_generator)
 - #137203 (Improve MIR modification)
 - #137206 (Make E0599 a structured error)
 - #137218 (misc `layout_of` cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-18 21:08:58 +00:00
Josh Stone
e61cac20c8 Remove outdated target unexpected_cfgs 2025-02-18 10:22:46 -08:00
许杰友 Jieyou Xu (Joe)
477a2eeb3d std::fs: slightly reformat remove_dir_all error docs
To make the error cases easier to spot on a quick glance.
2025-02-19 02:00:02 +08:00
Matthias Krüger
5a942d67a6
Rollup merge of #136876 - joshtriplett:locking-might-not-be-advisory, r=Amanieu
Locking documentation updates

- Reword file lock documentation to clarify advisory vs mandatory. Remove the
  word "advisory", and make it more explicit that the lock may be advisory or
  mandatory depending on platform.

- Document that locking a file fails on Windows if the file is opened only for append
2025-02-18 18:40:50 +01:00
Urgau
b7c2da2231
Rollup merge of #137214 - cyrgani:clippy_diagnostic_items, r=compiler-errors
add last std diagnostic items for clippy

Part of https://github.com/rust-lang/rust-clippy/issues/5393.
Add diagnostic item attributes to the items in `std` and `core` where clippy currently uses hardcoded paths (https://github.com/rust-lang/rust-clippy/blob/master/clippy_utils/src/paths.rs).
2025-02-18 18:34:18 +01:00
Urgau
73e5abd175
Rollup merge of #137205 - thaliaarchi:remove-wasi-fileext-tell, r=alexcrichton
Remove `std::os::wasi::fs::FileExt::tell`

Following #137165 (Use `tell` for `<File as Seek>::stream_position`), `tell` is now directly exposed via `stream_position`, making `<File as FileExt>::tell` redundant. Remove it.

`std::os::wasi::fs::FileExt::tell` is currently unstable and tracked in https://github.com/rust-lang/rust/issues/71213.

``@rustbot`` ping wasi
2025-02-18 18:34:17 +01:00
Urgau
14fb84a5bb
Rollup merge of #137167 - martn3:reliable_f16_math-f16-erfc, r=tgross35
tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg

In #136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid:

    rust_out.71e2e529d20ea47d-cgu.0:\
    (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \
    undefined reference to `__gnu_h2f_ieee'

on MIPS (and maybe other architectures).

r? tgross35
2025-02-18 18:34:15 +01:00
Josh Stone
3c45324e67 update cfg(bootstrap) 2025-02-18 09:32:44 -08:00
Josh Stone
fdba8a7c47 update version placeholders
(cherry picked from commit e4840ce59b)
2025-02-18 08:50:21 -08:00
Josh Triplett
ec2034d53d Reorder "This lock may be advisory or mandatory." earlier in the lock docs 2025-02-18 17:31:10 +01:00
Josh Triplett
35674eff6f Clarify that locking on Windows also works for files opened with .read(true) 2025-02-18 17:26:33 +01:00