Commit Graph

7177 Commits

Author SHA1 Message Date
clubby789
f7c2d1194d doc: Point to methods on Command as alternatives to set/remove_var 2025-01-17 12:53:58 +00:00
Matthias Krüger
dbbbed0579
Rollup merge of #135556 - AeonSolstice:patch-1, r=tgross35
Clarify note in `std::sync::LazyLock` example

I doubt most people know what it means, as I did not until a week ago. In the current form, it seems like a `TODO:`.
2025-01-16 17:00:47 +01:00
Jiahao XU
efe888871c
Move std::pipe::* into std::io
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2025-01-17 01:30:05 +11:00
Ayush Singh
c1790b14bc
uefi: Implement path
UEFI paths can be of 4 types:
1. Absolute Shell Path: Uses shell mappings
2. Absolute Device Path: this is what we want
3: Relative root: path relative to the current root.
4: Relative

Absolute shell path can be identified with `:` and Absolute Device path
can be identified with `/`. Relative root path will start with `\`.

The algorithm is mostly taken from edk2 UEFI shell implementation and is
somewhat simple. Check for the path type in order.

For Absolute Shell path, use `EFI_SHELL->GetDevicePathFromMap` to
get a BorrowedDevicePath for the volume.

For Relative paths, we use the current working directory to construct
the new path.

BorrowedDevicePath abstraction is needed to interact with
`EFI_SHELL->GetDevicePathFromMap` which returns a Device Path Protocol
with the lifetime of UEFI shell.

Absolute Shell paths cannot exist if UEFI shell is missing.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-01-16 10:19:22 +05:30
Aeon
c4a5e12567
Clarify note in std::sync::LazyLock example 2025-01-15 16:08:22 -05:00
Guillaume Gomez
4c26dc5d3d
Rollup merge of #132654 - joboet:lazy_main, r=ChrisDenton
std: lazily allocate the main thread handle

https://github.com/rust-lang/rust/pull/123550 eliminated the allocation of the main thread handle, but at the cost of greatly increased complexity. This PR proposes another approach: Instead of creating the main thread handle itself, the runtime simply remembers the thread ID of the main thread. The main thread handle is then only allocated when it is used, using the same lazy-initialization mechanism as for non-runtime use of `thread::current`, and the `name` method uses the thread ID to identify the main thread handle and return the correct name ("main") for it.

Thereby, we also allow accessing `thread::current` before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from `name` will only be "main" after the runtime initialization code has run, but I think that is acceptable.

This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).

Reverts #123550, CC ``@GnomedDev``
2025-01-15 16:30:08 +01:00
Jacob Pratt
56eb7bd9a9
Rollup merge of #134678 - zachs18:offset-ptr-update, r=tgross35
Update `ReadDir::next` in `std::sys::pal::unix::fs` to use `&raw const (*p).field` instead of `p.byte_offset().cast()`

Since https://github.com/rust-lang/reference/pull/1387 and https://github.com/rust-lang/rust/pull/117572, `&raw mut (*p).field`/`addr_of!((*p).field)` is defined to have the same inbounds preconditions as `ptr::offset`/`ptr::byte_offset`. I.e. `&raw const (*p).field` does not require that `p: *const T` point to a full `size_of::<T>()` bytes of memory, only that `p.byte_add(offset_of!(T, field))` is defined.

The old comment "[...] we don't even get to use `&raw const (*entry_ptr).d_name` because that operation requires the full extent of *entry_ptr to be in bounds of the same allocation, which is not necessarily the case here [...]" is now outdated, and the code can be simplified to use `&raw const (*entry_ptr).field`.

-------

There should be no behavior differences from this PR.

The `: *const dirent64` on line 716 and the `const _: usize = mem::offset_of!(dirent64, $field);` and comment on lines 749-751 are just sanity checks and should not affect semantics.

Since the `offset_ptr!` macro is only called three times, and all with the same local variable entry_ptr, I just used the local variable directly in the macro instead of taking it as an input, and renamed the macro to `entry_field_ptr!`.

The whole macro could also be removed and replaced with just using `&raw const (*entry_ptr).field`  in the three places, but the comments on the macro seemed worthwhile to keep.
2025-01-15 04:08:12 -05:00
Zachary S
58d6301cad Update ReadDir::next in std::sys::pal::unix::fs to use &raw const (*ptr).field instead of ptr.offset(...).cast().
Also, the macro is only called three times, and all with the same local variable entry_ptr, so just use the local variable directly,
and rename the macro to entry_field_ptr.
2025-01-14 23:47:24 -06:00
Trevor Gross
f6a2db8e1b Update compiler-builtins to 0.1.143
0.1.142 fixes an issue parsing optimization flags, and 0.1.143 changes
`__rust_[ui]128_*` builtins to use a C-safe signature.
2025-01-15 04:02:19 +00:00
Trevor Gross
fcc34b2c44 Update compiler-builtins to 0.1.141
0.1.141 syncs changes from `libm`. Most of the `libm` changes are
testing- or configuration-related.
2025-01-14 18:36:45 +00:00
Ralf Jung
f3cf39f3be wasi/io: remove dead files 2025-01-14 17:28:33 +01:00
Ralf Jung
c2ed284435 remove unnecessary rustc_allowed_through_unstable_modules 2025-01-14 17:10:44 +01:00
Ralf Jung
9ac62f972f remove Rustc{En,De}codable from library and compiler 2025-01-14 16:16:38 +01:00
Ralf Jung
4df78a07e5 make rustc_encodable_decodable feature properly unstable 2025-01-14 16:16:38 +01:00
joboet
2c28cc45c8
add comments explaining main thread identification 2025-01-14 13:37:28 +01:00
joboet
14f7f4b7bf
std: lazily allocate the main thread handle
Thereby, we also allow accessing thread::current before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from name will only be "main" after the runtime initialization code has run, but I think that is acceptable.

This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).
2025-01-14 13:37:28 +01:00
joboet
0e5ee891b2
Revert "Remove the Arc rt::init allocation for thread info"
This reverts commit 0747f2898e.
2025-01-14 13:37:25 +01:00
bors
e491caec14 Auto merge of #135359 - RalfJung:lang-start-unwind, r=joboet
use a single large catch_unwind in lang_start

I originally planned to use `abort_unwind` but reading the comment in `thread_cleanup` it seems we are deliberately going for slightly nicer error messages here, so this preserves that. It still seems nice to not repeat `catch_unwind` so often.
2025-01-14 05:58:48 +00:00
bors
35c2908177 Auto merge of #135465 - jhpratt:rollup-7p93bct, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - #134498 (Fix cycle error only occurring with -Zdump-mir)
 - #134977 (Detect `mut arg: &Ty` meant to be `arg: &mut Ty` and provide structured suggestion)
 - #135390 (Re-added regression test for #122638)
 - #135393 (uefi: helpers: Introduce OwnedDevicePath)
 - #135440 (rm unnecessary `OpaqueTypeDecl` wrapper)
 - #135441 (Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024)
 - #135444 (Update books)
 - #135450 (Fix emscripten-wasm-eh with unwind=abort)
 - #135452 (bootstrap: fix outdated feature name in comment)
 - #135454 (llvm: Allow sized-word rather than ymmword in tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-14 03:08:59 +00:00
Jacob Pratt
954b06f257
Rollup merge of #135393 - Ayush1325:uefi-helper-path, r=thomcc
uefi: helpers: Introduce OwnedDevicePath

This PR is split off from #135368 to reduce noise.

No real functionality changes, just some quality of life improvements.

Also implement Debug for OwnedDevicePath for some quality of life
improvements.
2025-01-13 20:43:46 -05:00
Ayush Singh
6e67ffa4f2
uefi: helpers: Introduce OwnedDevicePath
This PR is split off from #135368 to reduce noise.

Rename DevicePath to OwnedDevicePath. This is to allow a non-owning
version of DevicePath in the future to work with UEFI shell APIs which
provide const pointers to device paths for UEFI shell fs mapping.

Also implement Debug for OwnedDevicePath for some quality of life
improvements.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-01-13 23:57:06 +05:30
klensy
3a0554a445 further improve panic_immediate_abort by removing rtprintpanic messages 2025-01-13 21:11:42 +03:00
Matthias Krüger
b8dab0ead0
Rollup merge of #135405 - Ayush1325:path-is-absolute, r=tgross35
path: Move is_absolute check to sys::path

I am working on fs support for UEFI [0], which similar to windows has prefix components, but is not quite same as Windows. It also seems that Prefix is tied closely to Windows and cannot really be extended [1].

This PR just tries to remove coupling between Prefix and absolute path checking to allow platforms to provide there own implementation to check if a path is absolute or not.

I am not sure if any platform other than windows currently uses Prefix, so I have kept the path.prefix().is_some() check in most cases.

[0]: https://github.com/rust-lang/rust/pull/135368
[1]: https://github.com/rust-lang/rust/issues/52331#issuecomment-2492796137
2025-01-13 15:57:10 +01:00
Ayush Singh
1107382a18
path: Move is_absolute check to sys::path
I am working on fs support for UEFI [0], which similar to windows has prefix
components, but is not quite same as Windows. It also seems that Prefix
is tied closely to Windows and cannot really be extended [1].

This PR just tries to remove coupling between Prefix and absolute path
checking to allow platforms to provide there own implementation to check
if a path is absolute or not.

I am not sure if any platform other than windows currently uses Prefix,
so I have kept the path.prefix().is_some() check in most cases.

[0]: https://github.com/rust-lang/rust/pull/135368
[1]: https://github.com/rust-lang/rust/issues/52331#issuecomment-2492796137

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-01-13 11:52:03 +05:30
ltdk
e37daf0c86 Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
Ralf Jung
471d830106 avoid nesting the user-defined main so deeply on the stack 2025-01-11 15:53:42 +01:00
Ralf Jung
9f7fe81d53 use a single large catch_unwind in lang_start 2025-01-11 15:50:53 +01:00
Jacob Pratt
46222ce6f8
Rollup merge of #135347 - samueltardieu:push-qvyxtxsqyxyr, r=jhpratt
Use `NonNull::without_provenance` within the standard library

This API removes the need for several `unsafe` blocks, and leads to clearer code. It uses feature `nonnull_provenance` (#135243).

Close #135343
2025-01-11 01:55:09 -05:00
Jacob Pratt
23c22a6627
Rollup merge of #135324 - Ayush1325:uefi-fs-unsupported, r=joboet
Initial fs module for uefi

- Just a copy of unsupported fs right now to reduce the noise from future PRs to allow for easier review.
- For the full working version of fs on uefi, see [0]
- This is an effort to break the original PR (#129700) into much smaller chunks for faster upstreaming.

[0]: https://github.com/Ayush1325/rust/tree/uefi-file-full
2025-01-11 01:55:07 -05:00
Jacob Pratt
351e6188a8
Rollup merge of #135236 - scottmcm:more-mcp807-library-updates, r=ChrisDenton
Update a bunch of library types for MCP807

This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3:
```
library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]
```

Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.

r? ghost
2025-01-11 01:55:05 -05:00
Josh Triplett
2808977e05 Implement ByteStr and ByteString types
Approved ACP: https://github.com/rust-lang/libs-team/issues/502
Tracking issue: https://github.com/rust-lang/rust/issues/134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, `Borrow`,
`From`, and `PartialOrd`, when those would be the second implementation
for a type (counting the `T` impl) or otherwise may cause inference
failures. These impls are important, but we can attempt to add them
later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (@BurntSushi).
2025-01-11 06:35:21 +02:00
Samuel Tardieu
9ab77f1ccb Use NonNull::without_provenance within the standard library
This API removes the need for several `unsafe` blocks, and leads to
clearer code.
2025-01-10 23:23:10 +01:00
Jacob Pratt
5eec2b0610
Rollup merge of #132607 - YohDeadfall:pthread-name-fn-with-result, r=tgross35
Used pthread name functions returning result for FreeBSD and DragonFly

`pthread_getname_np` and `pthread_setname_np` received a wider adoption in past years and was added to:
* FreeBSD by June 11 2020 via [`2ef84b7da9a6c3e23b4a135e6e863581f16d46e1`](2ef84b7da9),
* DargonFly by March 8 2021 via [`ab5dc9aceb34419d1c4b6006739e61acee8ee999`](https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ab5dc9aceb34419d1c4b6006739e61acee8ee999).

There's not so much advantage except that the result can be checked in debug builds. Ideally it should be unified with Linux' implementation, but it trims the input.
2025-01-10 03:55:18 -05:00
Scott McMurray
6f2a78345e Update a bunch of library types for MCP807
This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3:
```
library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]
```

Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.
2025-01-09 23:47:11 -08:00
Ayush Singh
e21d12527b
Initial fs module for uefi
- Just a copy of unsupported fs right now to reduce the noise from
  future PRs to allow for easier review.
- For the full working version of fs on uefi, see [0]

[0]: https://github.com/Ayush1325/rust/tree/uefi-file-full

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-01-10 12:25:45 +05:30
Yoh Deadfall
8795750d43 Used pthread name functions returning result for FreeBSD and DragonFly 2025-01-09 21:25:55 +03:00
bors
251206c27b Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrum
Master bootstrap update

Part of the release process.

r? `@Mark-Simulacrum`
2025-01-09 13:33:16 +00:00
Esteban Küber
eb917ea24d Remove some unnecessary .into() calls 2025-01-08 21:19:28 +00:00
Pietro Albini
d894ce8827
fmt 2025-01-08 22:11:33 +01:00
Pietro Albini
2af3ba9a8a
update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
Pietro Albini
4ae92b7adb
update version placeholders 2025-01-08 20:02:18 +01:00
Jacob Pratt
5fa7c6a97a
Rollup merge of #135176 - kornelski:env-example, r=cuviper
More compelling env_clear() examples

`ls` isn't a command that people usually set env vars for, and `PATH` in particular isn't even used by `ls`.
2025-01-08 00:52:48 -05:00
Jacob Pratt
5ed1fa84a5
Rollup merge of #134389 - rust-wasi-web:condvar-no-threads, r=m-ou-se
Condvar: implement wait_timeout for targets without threads

This always falls back to sleeping since there is no way to notify a condvar on a target without threads.

Even on a target that has no threads the following code is a legitimate use case:

```rust
use std::sync::{Condvar, Mutex};
use std::time::Duration;

fn main() {
    let cv = Condvar::new();
    let mutex = Mutex::new(());
    let mut guard = mutex.lock().unwrap();

    cv.notify_one();

    let res;
    (guard, res) = cv.wait_timeout(guard, Duration::from_secs(3)).unwrap();
    assert!(res.timed_out());
}
```
2025-01-08 00:52:45 -05:00
Joseph Perez
8ec7bae57b
Outline panicking code for LocalKey::with
See https://github.com/rust-lang/rust/pull/115491 for prior related
modifications.

https://godbolt.org/z/MTsz87jGj shows a reduction of the code size
for TLS accesses.
2025-01-08 00:29:20 +01:00
Josh Triplett
bb6bbfa13f Avoid naming variables str
This renames variables named `str` to other names, to make sure `str`
always refers to a type.

It's confusing to read code where `str` (or another standard type name)
is used as an identifier. It also produces misleading syntax
highlighting.
2025-01-07 14:30:02 +02:00
Kornel
85a71ea0c7
More compelling env_clear() examples 2025-01-06 23:39:53 +00:00
Matthias Krüger
7d4b6dc861
Rollup merge of #135153 - crystalstall:master, r=workingjubilee
chore: remove redundant words in comment
2025-01-06 20:59:35 +01:00
crystalstall
591bf63439 chore: remove redundant words in comment
Signed-off-by: crystalstall <crystalruby@qq.com>
2025-01-06 15:47:49 +08:00
Matthias Krüger
b36962db55
Rollup merge of #135111 - tgross35:float-doc-aliases, r=Noratrieb
Add doc aliases for `libm` and IEEE names

Searching "fma" in the Rust documentation returns results for `intrinsics::fma*`, but does not point to the user-facing `mul_add`. Add aliases for `fma*` and the IEEE operation name `fusedMultiplyAdd`. Add the IEEE name to `sqrt` as well, `squareRoot`.
2025-01-06 08:09:04 +01:00
Jubilee
dcb8be8934
Rollup merge of #134996 - bdbai:uwp-support, r=jieyouxu,ChrisDenton
Add UWP (msvc) target support page

- Added Platform Support page for `x86_64-uwp-windows-msvc`, `i686-uwp-windows-msvc`, `thumbv7a-uwp-windows-msvc` and `aarch64-uwp-windows-msvc`
  - Adding myself as a maintainer
  - Removing the ticks for `thumbv7a-pc-windows-msvc` and `thumbv7a-uwp-windows-msvc` as they do not currently build due to #134565 and https://github.com/rust-lang/backtrace-rs/pull/685
- Fixed a few minor issues to let most of the UWP targets compile
- Happy new year to all!

r? jieyouxu
2025-01-04 17:23:16 -08:00
Trevor Gross
37f2875588 Add doc aliases for libm and IEEE names
Searching "fma" in the Rust documentation returns results for
`intrinsics::fma*`, but does not point to the user-facing `mul_add`. Add
aliases for `fma*` and the IEEE operation name `fusedMultiplyAdd`. Add
the IEEE name to `sqrt` as well, `squareRoot`.
2025-01-05 01:03:32 +00:00
Jubilee
6adcdc368a
Rollup merge of #135070 - klensy:backtrace-deps, r=workingjubilee
std: sync to dep versions of backtrace

Minor versions from backtrace desynced with std (they still differs in patch numbers, but still better):
4d7906bb24/Cargo.toml (L44-L48)

There is hidden bug here, let's see if CI can find it.

cc `@workingjubilee`
2025-01-04 07:57:34 -08:00
Matthias Krüger
4cd289550f
Rollup merge of #133420 - thesummer:rtems-unwind, r=workingjubilee
Switch rtems target to panic unwind

Switch the RTEMS target to `panic_unwind`.

Relates to https://github.com/rust-lang/backtrace-rs/pull/682
2025-01-03 22:12:41 +01:00
klensy
31ffc66fa8 sync to actual dep verions of backtrace 2025-01-03 15:26:18 +03:00
bors
319f5292a1 Auto merge of #135059 - matthiaskrgr:rollup-0ka9o3h, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #131729 (Make the `test` cfg a userspace check-cfg)
 - #134241 (more concrete source url of std docs [V2])
 - #135042 (taint fcx on selection errors during unsizing)
 - #135049 (Remove unused fields from RepeatElementCopy obligation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-03 09:34:23 +00:00
Matthias Krüger
e11d5f88a2
Rollup merge of #134241 - liigo:patch-16, r=dtolnay
more concrete source url of std docs [V2]

r? jhpratt
since you have reivewed https://github.com/rust-lang/rust/pull/134193

> If someone is looking to contribute, they will want the repository as a whole, not the lib.rs for std.

Now the repository url is reserved, I just add another concrete url as an example, to help people finding target page more quickly&easily.
2025-01-03 07:57:25 +01:00
bors
ac00fe89a1 Auto merge of #134692 - GrigorenkoPV:sync_poision, r=tgross35
Move some things to `std::sync::poison` and reexport them in `std::sync`

Tracking issue: #134646

r? `@tgross35`

I've used `sync_poison_mod` feature flag instead, because `sync_poison` had already been used back in 1.2.

try-job: x86_64-msvc
2025-01-03 06:40:28 +00:00
bdbai
2389daab1b Fix UWP build 2025-01-03 11:14:03 +08:00
bors
ab3924b298 Auto merge of #122565 - Zoxc:atomic-panic-msg, r=the8472
Try to write the panic message with a single `write_all` call

This writes the panic message to a buffer before writing to stderr. This allows it to be printed with a single `write_all` call, preventing it from being interleaved with other outputs. It also adds newlines before and after the message ensuring that only the panic message will have its own lines.

Before:
```
thread 'thread 'thread 'thread 'thread '<unnamed>thread 'thread 'thread 'thread '<unnamed><unnamed>thread '<unnamed>' panicked at ' panicked at <unnamed><unnamed><unnamed><unnamed><unnamed>' panicked at <unnamed>' panicked at src\heap.rssrc\heap.rs'
panicked at ' panicked at ' panicked at ' panicked at ' panicked at src\heap.rs' panicked at src\heap.rs::src\heap.rssrc\heap.rssrc\heap.rssrc\heap.rssrc\heap.rs:src\heap.rs:455455:::::455:455::455455455455455:455:99:::::9:9:
:
999:
999:
assertion failed: size <= (*queue).block_size:
:
assertion failed: size <= (*queue).block_size:
assertion failed: size <= (*queue).block_size:
:
:
assertion failed: size <= (*queue).block_sizeassertion failed: size <= (*queue).block_sizeassertion failed: size <= (*queue).block_size

assertion failed: size <= (*queue).block_size
assertion failed: size <= (*queue).block_sizeassertion failed: size <= (*queue).block_sizeerror: process didn't exit successfully: `target\debug\direct_test.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
```
After:
```

thread '<unnamed>' panicked at src\heap.rs:455:9:
assertion failed: size <= (*queue).block_size

thread '<unnamed>' panicked at src\heap.rs:455:9:
assertion failed: size <= (*queue).block_size

thread '<unnamed>' panicked at src\heap.rs:455:9:
assertion failed: size <= (*queue).block_size

error: process didn't exit successfully: `target\debug\direct_test.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
```

---

try-jobs: x86_64-gnu-llvm-18
2025-01-02 22:06:09 +00:00
Liigo Zhuang
862fc62208 path in detail 2025-01-02 22:30:56 +08:00
Pavel Grigorenko
ee2ad4dfb1 Move some things to std::sync::poison and reexport them in std::sync 2025-01-02 15:21:41 +03:00
John Kåre Alsaker
4bf85c25ec Try to write the panic message with a single write_all call 2025-01-01 15:58:29 +01:00
Kleis Auke Wolthuizen
b6af0c4836 std::fs::DirEntry.metadata(): prefer use of lstat() on Emscripten
Align it with musl, which also prefers using lstat() here.
2025-01-01 13:21:19 +01:00
Kleis Auke Wolthuizen
ef58e8b989 Avoid use of LFS64 symbols on Emscripten
Since Emscripten uses musl libc internally.

Non-functional change: all LFS64 symbols were aliased to their non-LFS64
counterparts in rust-lang/libc@7c952dceaa.
2025-01-01 13:21:19 +01:00
bors
7a0cde96f8 Auto merge of #134620 - ChrisDenton:line-writer, r=tgross35
Avoid short writes in LineWriter

If the bytes written to `LineWriter` contains at least one new line but doesn't end in a new line (e.g. `"abc\ndef"`) then we:

- write up to the last new line direct to the underlying `Writer`.
- copy as many of the remaining bytes as will fit into our internal buffer.

That last step is inefficient if the remaining bytes are larger than our buffer. It will needlessly split the bytes in two, requiring at least two writes to the underlying `Writer` (one to flush the buffer, one more to write the rest). This PR skips the extra buffering if the remaining bytes are larger than the buffer.
2024-12-31 13:21:27 +00:00
Matthias Krüger
344a61e69b
Rollup merge of #134884 - calciumbe:patch1, r=jieyouxu
Fix typos

Hello, I fix some typos in docs and comments. Thank you very much.
2024-12-29 21:18:07 +01:00
calciumbe
4f8bebd6b5
fix: typos
Signed-off-by: calciumbe <192480234+calciumbe@users.noreply.github.com>
2024-12-29 21:35:02 +08:00
bors
3c1e750364 Auto merge of #134547 - SUPERCILEX:unify-copy, r=thomcc
Unify fs::copy and io::copy on Linux

Currently, `fs::copy` first tries a regular file copy (via copy_file_range) and then falls back to userspace read/write copying. We should use `io::copy` instead as it tries copy_file_range, sendfile, and splice before falling back to userspace copying. This was discovered here: https://github.com/SUPERCILEX/fuc/issues/40

Perf impact: `fs::copy` will now have two additional statx calls to decide which syscall to use. I wonder if we should get rid of the statx calls and only continue down the next fallback when the relevant syscalls say the FD isn't supported.
2024-12-28 13:49:45 +00:00
Trevor Gross
68bd853bb6 Update compiler-builtins to 0.1.140
Nothing significant here, just syncing the following small changes:

- https://github.com/rust-lang/compiler-builtins/pull/727
- https://github.com/rust-lang/compiler-builtins/pull/730
- https://github.com/rust-lang/compiler-builtins/pull/736
- https://github.com/rust-lang/compiler-builtins/pull/737
2024-12-27 22:26:08 +00:00
bors
6d3db555e6 Auto merge of #134822 - jieyouxu:rollup-5xuaq82, r=jieyouxu
Rollup of 8 pull requests

Successful merges:

 - #134606 (ptr::copy: fix docs for the overlapping case)
 - #134622 (Windows: Use WriteFile to write to a UTF-8 console)
 - #134759 (compiletest: Remove the `-test` suffix from normalize directives)
 - #134787 (Spruce up the docs of several queries related to the type/trait system and const eval)
 - #134806 (rustdoc: use shorter paths as preferred canonical paths)
 - #134815 (Sort triples by name in platform_support.md)
 - #134816 (tools: fix build failure caused by PR #134420)
 - #134819 (Fix mistake in windows file open)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-27 13:01:07 +00:00
许杰友 Jieyou Xu (Joe)
5544091054
Rollup merge of #134819 - ChrisDenton:trunc, r=Mark-Simulacrum
Fix mistake in windows file open

In #134722 this should have been `c::FileAllocationInfo` not `c::FileEndOfFileInfo`. Oops.
2024-12-27 20:44:15 +08:00
许杰友 Jieyou Xu (Joe)
7bbbfc650d
Rollup merge of #134622 - ChrisDenton:write-file-utf8, r=Mark-Simulacrum
Windows: Use WriteFile to write to a UTF-8 console

If the console code page is UTF-8 then we can simply write to it without needing to convert to UTF-16 and calling `WriteConsole`.
2024-12-27 20:44:11 +08:00
bors
42591a4cc0 Auto merge of #134786 - ChrisDenton:fix-rename-symlink, r=tgross35
Fix renaming symlinks on Windows

Previously we only detected mount points and not other types of links when determining reparse point behaviour.

Also added some tests to avoid this regressing again in the future.
2024-12-27 10:14:53 +00:00
Chris Denton
54b130afa2
Fix renaming symlinks on Windows
Previously we only detected mount points and not other types of links when determining reparse point behaviour.
2024-12-27 10:07:10 +00:00
Chris Denton
0af396f183
Fix mistake in windows file open 2024-12-27 09:20:37 +00:00
Jacob Pratt
c1447e3449
Rollup merge of #134791 - notriddle:notriddle/inline-ffi-error-types, r=tgross35
docs: inline `std::ffi::c_str` types to `std::ffi`

Rustdoc has no way to show that an item is stable, but only at a different path. `std::ffi::c_str::NulError` is not stable, but `std::ffi::NulError` is.

To avoid marking these types as unstable when someone just wants to follow a link from `CString`, inline them into their stable paths.

Fixes #134702

r? `@tgross35`
2024-12-26 21:56:51 -05:00
Jacob Pratt
50c3696735
Rollup merge of #134728 - deltragon:barrier-doc, r=tgross35
Use scoped threads in `std::sync::Barrier` examples

This removes boilerplate around `Arc`s and makes the code more clear.
2024-12-26 21:56:50 -05:00
Jacob Pratt
0521d6cf2c
Rollup merge of #134649 - SUPERCILEX:statx-remember, r=thomcc
Fix forgetting to save statx availability on success

Looks like we forgot to save the statx state on success which means the first failure (common when checking if a file exists) will always require spending an invalid statx to confirm the failure is real.

r? `@thomcc`
2024-12-26 21:56:49 -05:00
Jacob Pratt
9551808f42
Rollup merge of #134644 - kpreid:duplicates, r=Mark-Simulacrum
Document collection `From` and `FromIterator` impls that drop duplicate keys.

This behavior is worth documenting because there are other plausible alternatives, such as panicking when a duplicate is encountered, and it reminds the programmer to consider whether they should, for example, coalesce duplicate keys first.

Followup to #89869.
2024-12-26 21:56:48 -05:00
Michael Howell
40b0026a2f docs: inline std::ffi::c_str types to std::ffi
Rustdoc has no way to show that an item is stable,
but only at a different path. `std::ffi::c_str::NulError` is
not stable, but `std::ffi::NulError` is.

To avoid marking these types as unstable when someone just
wants to follow a link from `CString`, inline them into their
stable paths.
2024-12-26 08:58:17 -07:00
Alex Saveau
96cc078878
Fix compilation issues on other unixes
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-24 10:58:31 -08:00
deltragon
6a89f8789a Use scoped threads in std::sync::Barrier examples
This removes boilerplate around `Arc`s and makes the code more clear.
2024-12-24 14:39:02 +01:00
Chris Denton
ca56dc8537
Windows: Use FILE_ALLOCATION_INFO for truncation
But fallback to FILE_END_OF_FILE_INFO for WINE
2024-12-24 11:04:12 +00:00
Matthias Krüger
95c33e303b
Rollup merge of #134363 - estebank:derive-default, r=SparrowLii
Use `#[derive(Default)]` instead of manual `impl` when possible

While working on #134175 I noticed a few manual `Default` `impl`s that could be `derive`d instead. These likely predate the existence of the `#[default]` attribute for `enum`s.
2024-12-23 14:44:20 +01:00
Esteban Küber
1f82b45b6a Use #[derive(Default)] instead of manually implementing it 2024-12-23 03:01:29 +00:00
Marti Raudsepp
edfdfbe832 docs: Permissions.readonly() also ignores root user special permissions
The root user can write to files without any (write) access bits set. But this is not taken into account by `std::fs::Permissions.readonly()`.
2024-12-22 20:47:41 +02:00
Kevin Reid
6a43716ada Specify only that duplicates are discarded, not the order. 2024-12-22 08:16:54 -08:00
Alex Saveau
f19ba15a2c
Fix forgetting to save statx availability on success
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21 22:50:08 -08:00
Kevin Reid
b5e8a5d393 Document collection From and FromIterator impls that drop duplicate keys.
This behavior is worth documenting because there are other plausible
alternatives, such as panicking when a duplicate is encountered, and
it reminds the programmer to consider whether they should, for example,
coalesce duplicate keys first.
2024-12-21 19:57:42 -08:00
Alex Saveau
e0a1549e44
Eliminate redundant statx syscalls
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2024-12-21 15:22:28 -08:00
Matthias Krüger
51df98ddb0
Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, r=ChrisDenton
Win: Use POSIX rename semantics for `std::fs::rename` if available

Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming and renaming if the target file is has already been opened with `FILE_SHARE_DELETE`, in which case the file gets renamed on disk while the open file handle still refers to the old file, just like in POSIX. This resolves #123985, where atomic renaming proved difficult to impossible due to race conditions.

If `FileRenameInfoEx` isn't available due to missing support from the underlying filesystem or missing OS support, the renaming is retried with `FileRenameInfo`, which matches the behavior of `MoveFileEx`.

This PR also manually replicates parts of `MoveFileEx`'s internal logic, as reverse-engineered from the disassembly: If the source file is a reparse point and said reparse point is a mount point, the mount point itself gets renamed; otherwise the reparse point is resolved and the result renamed.

Notes:
- Currently, the `win7` target doesn't bother with `FileRenameInfoEx` at all; it's probably desirable to remove that special casing and try `FileRenameInfoEx` anyway if it doesn't exist, in case the binary is run on newer OS versions.

Fixes #123985
2024-12-21 22:16:02 +01:00
Alex Saveau
73b41fbcfa
Unify fs::copy and io::copy 2024-12-21 12:20:58 -08:00
Chris Denton
1e3ecd5e4d
Windows: Use WriteFile to write to a UTF-8 console 2024-12-21 15:59:56 +00:00
Chris Denton
fdb43ef0c4
Avoid short writes in LineWriter
Also update the tests to avoid testing implementation details.
2024-12-21 15:13:22 +00:00
Jacob Pratt
cc27e3f08b
Rollup merge of #134593 - kornelski:less-unwrap, r=jhpratt
Less unwrap() in documentation

I think the common use of `.unwrap()` in examples makes it overrepresented, looking like a more typical way of error handling than it really is in real programs.

Therefore, this PR changes a bunch of examples to use different error handling methods, primarily the `?` operator. Additionally, `unwrap()` docs warn that it might abort the program.
2024-12-21 01:18:43 -05:00
Kornel
7b42bc0c79
Less unwrap() in documentation 2024-12-21 01:26:47 +00:00
Matthias Krüger
758ad53005
Rollup merge of #123604 - michaelvanstraten:proc_thread_attribute_list, r=ChrisDenton
Abstract `ProcThreadAttributeList` into its own struct

As extensively discussed in issue #114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer.

This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads.

try-job: x86_64-mingw
2024-12-21 01:30:13 +01:00
Ralf Jung
8b2b6359f9 mri: add track_caller to thread spawning methods for better backtraces 2024-12-20 15:03:51 +01:00
Sergio Gasquez
c28e3e36b5 build: Update libc version 2024-12-19 10:08:29 +01:00
Sebastian Urban
45c7ddfea6 Implement Condvar::wait_timeout for targets without threads
This always falls back to sleeping since there is no way
to notify a condvar on a target without threads.
2024-12-18 11:33:15 +01:00