Commit graph

7646 commits

Author SHA1 Message Date
Thalia Archibald
bd49a4beb7 Implement optional methods for unsupported stdio
Match what `std::io::Empty` does, since it is very similar. However,
still evaluate the `fmt::Arguments` in `write_fmt` to be consistent with
other platforms.
2025-03-22 01:21:23 -07:00
Frank King
5016467a23 Implement UniqueArc 2025-03-22 15:14:49 +08:00
moxian
110f1fe17f Revert "Stabilize file_lock"
This reverts commit 82af73dd4c.
2025-03-21 20:24:31 -07:00
Matthias Krüger
809378bd2e
Rollup merge of #138650 - thaliaarchi:io-write-fmt-known, r=ibraheemdev
Optimize `io::Write::write_fmt` for constant strings

When the formatting args to `fmt::Write::write_fmt` are a statically known string, it simplifies to only calling `write_str` without a runtime branch. Do the same in `io::Write::write_fmt` with `write_all`.

Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-21 06:56:46 +01:00
Matthias Krüger
1530b03655
Rollup merge of #137357 - syvb:sv/log-docs, r=tgross35
Document results of non-positive logarithms

The integer versions of logarithm functions panic on non-positive numbers. The floating point versions have different, undocumented behaviour (-inf on 0, NaN on <0). This PR documents that.

try-job: aarch64-gnu
2025-03-21 06:56:45 +01:00
王宇逸
e5fc7d6a55 Fix Thread::set_name on cygwin 2025-03-21 12:50:27 +08:00
Sebastian Urban
38cf49dde8 wasm: increase default thread stack size to 1 MB
The default stack size for the main thread is 1 MB as specified by linker options.
However, the default stack size for threads was only 64 kB.

This is surprisingly small and thus we increase it to 1 MB to match the
main thread.
2025-03-20 19:08:16 +01:00
syvb
0199d0481d Document results of non-positive logarithms 2025-03-19 19:25:42 -04:00
Matthias Krüger
ce76292014
Rollup merge of #137051 - thaliaarchi:io-optional-impls/empty, r=m-ou-se
Implement default methods for `io::Empty` and `io::Sink`

Implements default methods of `io::Read`, `io::BufRead`, and `io::Write` for `io::Empty` and `io::Sink`. These implementations are equivalent to the defaults, except in doing less unnecessary work.

`Read::read_to_string` and `BufRead::read_line` both have a redundant call to `str::from_utf8` which can't be inlined from `core` and `Write::write_all_vectored` has slicing logic which can't be simplified (See on [Compiler Explorer](https://rust.godbolt.org/z/KK6xcrWr4)). The rest are optimized to the minimal with `-C opt-level=3`, but this PR gives that benefit to unoptimized builds.

This includes an implementation of `Write::write_fmt` which just ignores the `fmt::Arguments<'_>`. This could be problematic whenever a user formatting impl is impure, but the docs do not guarantee that the args will be expanded.

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

r? `@m-ou-se`
2025-03-19 16:52:53 +01:00
Matthias Krüger
d46cc71f54
Rollup merge of #135394 - clarfonthey:uninit-slices-part-2, r=tgross35
`MaybeUninit` inherent slice methods part 2

These were moved out of #129259 since they require additional libs-api approval. Tracking issue: #117428.

New API surface:

```rust
impl<T> [MaybeUninit<T>] {
    // replacing fill; renamed to avoid conflict
    pub fn write_filled(&mut self, value: T) -> &mut [T] where T: Clone;

    // replacing fill_with; renamed to avoid conflict
    pub fn write_with<F>(&mut self, value: F) -> &mut [T] where F: FnMut() -> T;

    // renamed to remove "fill" terminology, since this is closer to the write_*_of_slice methods
    pub fn write_iter<I>(&mut self, iter: I) -> (&mut [T], &mut Self) where I: Iterator<Item = T>;
}
```

Relevant motivation for these methods; see #129259 for earlier methods' motiviations.

* I chose `write_filled` since `filled` is being used as an object here, whereas it's being used as an action in `fill`.
* I chose `write_with` instead of `write_filled_with` since it's shorter and still matches well.
* I chose `write_iter` because it feels completely different from the fill methods, and still has the intent clear.

In all of the methods, it felt appropriate to ensure that they contained `write` to clarify that they are effectively just special ways of doing `MaybeUninit::write` for each element of a slice.

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

r? libs-api
2025-03-19 16:52:52 +01:00
bors
a7fc463dd8 Auto merge of #138693 - matthiaskrgr:rollup-ejq8mwp, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #136177 (clarify BufRead::{fill_buf, consume} docs)
 - #138654 (Remove the regex dependency from coretests)
 - #138655 (rustc-dev-guide sync)
 - #138656 (Remove double nesting in post-merge workflow)
 - #138658 (CI: mirror alpine and centos images to ghcr)
 - #138659 (coverage: Don't store a body span in `FunctionCoverageInfo`)
 - #138661 (Revert: Add *_value methods to proc_macro lib)
 - #138670 (Remove existing AFIDT implementation)
 - #138674 (Various codegen_llvm cleanups)
 - #138684 (use then in docs for `fuse` to enhance readability)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-19 12:39:34 +00:00
Mara Bos
f23e76e0d2 Allow spawning threads after TLS destruction. 2025-03-19 12:49:18 +01:00
bors
c4b38a5967 Auto merge of #138653 - matthiaskrgr:rollup-fwwqmr7, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #136320 (exit: document interaction with C)
 - #138080 (Leave a breadcrumb towards bootstrap config documentation in `bootstrap.toml`)
 - #138301 (Implement `read_buf` for Hermit)
 - #138569 (rustdoc-json: Add tests for `#[repr(...)]`)
 - #138635 (Extract `for_each_immediate_subpat` from THIR pattern visitors)
 - #138642 (Unvacation myself)
 - #138644 (Add `#[cfg(test)]` for Transition in dfa in `rustc_transmute`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-19 09:28:24 +00:00
Matthias Krüger
b52275fd01
Rollup merge of #136177 - hkBst:patch-24, r=ibraheemdev
clarify BufRead::{fill_buf, consume} docs

Fixes #85394
2025-03-19 08:17:14 +01:00
Andrei Damian
e41cce03a0 fix pthread-based tls on apple targets 2025-03-18 20:31:52 +02:00
Chris Denton
6b2fa32f14
Windows: fix FileType PartialEq implementation 2025-03-18 17:39:38 +00:00
Taiki Endo
68267d0aed Fix build failure on Trusty 2025-03-19 02:05:01 +09:00
Chris Denton
3bfb6af978
Test windows file type equality 2025-03-18 16:46:56 +00:00
Berrysoft
2a0cd874a9 Add stack overflow handler for cygwin 2025-03-18 23:00:33 +08:00
Ayush Singh
9fa158d70a
std: uefi: fs: Implement mkdir
- Since there is no direct mkdir in UEFI, first check if a file/dir with
  same path exists and then create the directory.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-18 19:32:46 +05:30
Marijn Schouten
e5b86e2c73
Apply suggestions from code review
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-03-18 11:16:18 +01:00
Matthias Krüger
800b8fbe39
Rollup merge of #138301 - thaliaarchi:io-optional-methods/hermit, r=tgross35
Implement `read_buf` for Hermit

Following https://github.com/hermit-os/kernel/pull/1606, it is now safe to implement `Read::read_buf` for file descriptors on Hermit.

cc ```@mkroening```
2025-03-18 10:09:29 +01:00
Matthias Krüger
098db784c7
Rollup merge of #136320 - RalfJung:exit, r=the8472
exit: document interaction with C

Cc https://github.com/rust-lang/rust/issues/126600
2025-03-18 10:09:28 +01:00
bors
75530e9f72 Auto merge of #135368 - Ayush1325:uefi-fs-2, r=jhpratt,nicholasbishop
uefi: fs: Implement exists

Also adds the initial file abstractions.

The file opening algorithm is inspired from UEFI shell. It starts by classifying if the Path is Shell mapping, text representation of device path protocol, or a relative path and converts into an absolute text representation of device path protocol.

After that, it queries all handles supporting
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and opens the volume that matches the device path protocol prefix (similar to Windows drive). After that, it opens the file in the volume using the remaining pat.

It also introduces OwnedDevicePath and BorrowedDevicePath abstractions to allow working with the base UEFI and Shell device paths efficiently.

DevicePath in UEFI behaves like an a group of nodes laied out in the memory contiguously and thus can be modeled using iterators.

This is an effort to break the original PR (https://github.com/rust-lang/rust/pull/129700) into much smaller chunks for faster upstreaming.
2025-03-18 09:09:12 +00:00
Thalia Archibald
a0c3dd4df4 Optimize io::Write::write_fmt for constant strings
When the formatting args to `fmt::Write::write_fmt` are a statically
known string, it simplifies to only calling `write_str` without a
runtime branch. Do the same in `io::Write::write_fmt` with `write_all`.

Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-18 01:40:27 -07:00
Ayush Singh
2e70cfc04d
uefi: fs: Implement exists
Also adds the initial file abstractions.

The file opening algorithm is inspired from UEFI shell. It starts by
classifying if the Path is Shell mapping, text representation of device
path protocol, or a relative path and converts into an absolute text
representation of device path protocol.

After that, it queries all handles supporting
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL and opens the volume that matches the
device path protocol prefix (similar to Windows drive). After that, it
opens the file in the volume using the remaining pat.

It also introduces OwnedDevicePath and BorrowedDevicePath abstractions
to allow working with the base UEFI and Shell device paths efficiently.

DevicePath in UEFI behaves like an a group of nodes laied out in the
memory contiguously and thus can be modeled using iterators.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-18 08:11:16 +05:30
Thalia Archibald
bcac931956 Update test for SGX now implementing read_buf
In #108326, `read_buf` was implemented for a variety of types, but SGX
was saved for later. Update a test from then, now that #137355
implemented it for SGX types.
2025-03-17 17:18:05 -07:00
Thalia Archibald
c5fc1931a0 Implement read_buf for Hermit 2025-03-17 16:53:37 -07:00
Ralf Jung
c133e22f7c move new section into platform-specific behavior, as it is unix-specific 2025-03-17 17:56:22 +01:00
bjorn3
42de015549 Mark imports of #[rustc_std_internal_symbol] items with this attribute
This ensures that they will be correctly mangled in a future commit.
2025-03-17 14:06:56 +00:00
Jacob Pratt
62c2a7b93b
Rollup merge of #137793 - NobodyXu:stablise-annoymous-pipe, r=joshtriplett
Stablize anonymous pipe

Since #135822 is staled, I create this PR to stablise anonymous pipe

Closes #127154

try-job: test-various
2025-03-17 05:47:50 -04:00
Jacob Pratt
b3b7a3b8d2
Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboet
Add std support to cygwin target
2025-03-17 05:47:49 -04:00
bors
10bcdad7df Auto merge of #138583 - jhpratt:rollup-h699hty, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #136293 (document capacity for ZST as example)
 - #136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove)
 - #136816 (refactor `notable_traits_button` to use iterator combinators  instead of for loop)
 - #138552 (Misc print request handling cleanups + a centralized test for print request stability gating)
 - #138573 (Make `_Unwind_Action` a type alias, not enum)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-17 03:45:06 +00:00
Jacob Pratt
5144055055
Rollup merge of #138573 - Noratrieb:no-unsound-bad-bonk-bonk, r=workingjubilee
Make `_Unwind_Action` a type alias, not enum

It's bitflags in practice, so an enum is unsound, as an enum must only have the described values. The x86_64 psABI declares it as a `typedef int _Unwind_Action`, which seems reasonable. I made a newtype first but that was more annoying than just a typedef. We don't really use this value for much other than a short check.

I ran `x check library --target aarch64-unknown-linux-gnu,x86_64-pc-windows-gnu,x86_64-fortanix-unknown-sgx,x86_64-unknown-haiku,x86_64-unknown-fuchsi
a,x86_64-unknown-freebsd,x86_64-unknown-dragonfly,x86_64-unknown-netbsd,x86_64-unknown-openbsd,x86_64-unknown-redox,riscv64-linux-android,armv7-unknown-freebsd` (and some more but they failed to build for other reasons :D)

fixes #138558

r? workingjubilee have fun
2025-03-16 21:47:45 -04:00
bors
c3dd4eefd6 Auto merge of #138363 - beetrees:f16-f128-integer-convert, r=Amanieu
Add `From<{integer}>` for `f16`/`f128` impls

This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`.

The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example:
```rust
fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}
```
None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`.

This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of #125198).

cc `@bjoernager`
r? `@tgross35`

Tracking issue: #116909
2025-03-17 00:33:36 +00:00
Noratrieb
f20a6c70fb make _Unwind_Action a type alias, not enum
It's bitflags in practice, so an enum is unsound, as an enum must only
have the described values. The x86_64 psABI declares it as a `typedef
int _Unwind_Action`, which seems reasonable. I made a newtype first but
that was more annoying than just a typedef. We don't really use this
value for much other than a short check.
2025-03-16 21:32:41 +01:00
Ayush Singh
aa2c24b03b
uefi: Add OwnedEvent abstraction
- Events are going to become quite important for Networking, so needed
  owned abstractions.
- Switch to OwnedEvent abstraction for Exit boot services event.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-17 01:14:14 +05:30
许杰友 Jieyou Xu (Joe)
c29a29e717
Rollup merge of #137538 - tapanprakasht:fix-doc-path, r=thomcc
fix doc path in std::fmt macro

fixes https://github.com/rust-lang/rust/issues/137519
2025-03-16 13:19:52 +08:00
许杰友 Jieyou Xu (Joe)
26dea1d944
Rollup merge of #137492 - nabijaczleweli:master, r=thomcc
libstd: rustdoc: correct note on fds 0/1/2 pre-main

Closes: #137490
2025-03-16 13:19:52 +08:00
许杰友 Jieyou Xu (Joe)
8210b84aaf
Rollup merge of #138275 - folkertdev:expose-is-s390x-feature-detected, r=Mark-Simulacrum
expose `is_s390x_feature_detected!` from `std::arch`

tracking issue: https://github.com/rust-lang/rust/issues/135413
implementation: https://github.com/rust-lang/stdarch/pull/1699 (more features added in https://github.com/rust-lang/stdarch/pull/1720)

This macro was part of the recent `stdarch` synchronization, but not yet exposed via `std::arch`.

r? libs
2025-03-16 09:40:05 +08:00
许杰友 Jieyou Xu (Joe)
f16ce2ae6c
Rollup merge of #137890 - lolbinarycat:docs-bufreader-peek-consume, r=Mark-Simulacrum
doc: clarify that consume can be called after BufReader::peek

tracking issue #128405
2025-03-16 09:40:03 +08:00
bors
cb50d4d856 Auto merge of #137424 - Ayush1325:uefi-path-node, r=nicholasbishop,cuviper
uefi: helpers: Add DevicePathNode abstractions

- UEFI device path is a series of nodes layed out in a contiguous memory region. So it makes sense to use Iterator abstraction for modeling DevicePaths
- This PR has been split off from #135368 for easier review. The allow dead_code will be removed in #135368

cc `@nicholasbishop`
2025-03-14 13:55:32 +00:00
Tobias Bucher
bdaf23b4cd Forward stream_position in Arc<File> as well
It was missed in #137165.
2025-03-14 12:36:00 +01:00
Jacob Pratt
f6fcae0015
Rollup merge of #138457 - bjorn3:redox_scheme_paths, r=Noratrieb
Remove usage of legacy scheme paths on RedoxOS

The `name:/path` path syntax is getting phased out[^1] in favor of `/scheme/name/path`. Also using `null:` is no longer necessary as `/dev/null` is available on Redox OS too.

[^1]: https://gitlab.redox-os.org/redox-os/rfcs/-/blob/master/text/0006-scheme-path.md

cc `@jackpot51`
2025-03-14 01:37:36 -04:00
Jacob Pratt
936e51ee12
Rollup merge of #137870 - karolzwolak:lazylock-const-hashmaps-137566, r=cuviper
Improve HashMap docs for const and static initializers

Closes #137566.
I clarified the HashMap usage in const and static initializers.
I also added examples of how to construct such HashMaps wrapped in LazyLock.
2025-03-14 01:37:30 -04:00
Jacob Pratt
c62707eb74
Rollup merge of #136001 - hkBst:patch-21, r=cuviper
Overhaul examples for PermissionsExt

This fixes #91707 by including one overarching example, instead of the small examples that can be misleading.
2025-03-14 01:37:28 -04:00
bjorn3
43499bfe2e Remove has_redox_scheme
Redox OS is moving away from name:/path style paths to /scheme/name/path
style paths which are already handled correctly without has_redox_scheme.
2025-03-13 20:09:07 +00:00
Matthias Krüger
883f00ce34
Rollup merge of #138425 - cuviper:remove-hash_raw_entry, r=jhpratt
Remove `feature = "hash_raw_entry"`

The `hash_raw_entry` feature finished [fcp-close](https://github.com/rust-lang/rust/issues/56167#issuecomment-2293805510) back in August, and its remaining uses in the compiler have now been removed, so we should be all clear to remove it from `std`.

Closes #56167
2025-03-13 17:44:11 +01:00
bjorn3
83ee034d03 Remove usage of legacy scheme paths on RedoxOS
The name:/path path syntax is getting phased out in favor of
/scheme/name/path. Also using null: is no longer necessary as /dev/null
is available on Redox OS too.
2025-03-13 16:17:50 +00:00
Jiahao XU
6863a99841
Mv os-specific trait impl of Pipe* into std::os::*
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-03-14 01:03:56 +11:00