std: Fix size returned by UEFI tcp4 read operations
The read and read_vectored methods were returning the length of the input buffer, rather than the number of bytes actually read. Fix by changing read_inner to return the correct value, and have both read and read_vectored return that.
Removes the double subject "it" in the safety documentation of
`core::ptr::split_at_mut` for raw slice pointers, as it does not refer
to anything.
Reported-by: Johnathan Van Why <jrvanwhy@betterbytes.org>
The read and read_vectored methods were returning the length of the
input buffer, rather than the number of bytes actually read. Fix by
changing read_inner to return the correct value, and have both read and
read_vectored return that.
std: sys: fs: uefi: Implement copy
- Using the implementation from sys::fs::common since ther is no built-in copy implementation in UEFI.
- Tested with OVMF on QEMU.
@rustbot label +O-UEFI
std: sys: fs: uefi: Implement File::flush
- Also forward fsync and datasync to flush. UEFI does not have anything separate for metadata sync.
@rustbot label +O-UEFI
Use `rand` crate more idiomatically
Small cleanup, found while working on something else.
We were using `rand` un-idiomatically in a couple of places, and it was bugging me...
Fix the connect_error test on FreeBSD 15+
On FreeBSD 15, the error code returned in this situation changed. It's now ENETUNREACH. I think that error code is reasonable, and it's documented for connect(2), so we should expect that it might be returned.
Reword the collect() docs
Update the `Iterator::collect` docs so they explain that the return type, not the iterator itself, determines which collection is built.
Follow up on rust-lang/rust#121140
stabilize `Peekable::next_if_map` (`#![feature(peekable_next_if_map)]`)
# Stabilization report
## Summary
`#![feature(peekable_next_if_map)]` is a variation of `next_if` on peekable iterators that can transform the peeked item. This creates a way to take ownership of the next item in an iterator when some condition holds, but put the item back when the condition doesn't hold. This pattern would otherwise have needed unwraps in many cases.
[Tracking issue](https://github.com/rust-lang/rust/issues/143702)
### What is stabilized
```rust
impl<I: Iterator> Peekable<I> {
pub fn next_if_map<R>(
&mut self,
f: impl FnOnce(I::Item) -> Result<R, I::Item>,
) -> Option<R> {
..
}
pub fn next_if_map_mut<R>(
&mut self,
f: impl FnOnce(&mut I::Item) -> Option<R>,
) -> Option<R> {
..
}
}
```
Example usage adapted from the ACP:
```rust
let mut it = Peekable::new("123".chars());
while let Some(digit) = it.next_if_map(|c| c.to_digit(10).ok_or(c)) {
codepoint = codepoint * 10 + digit;
}
```
or with `next_if_map_mut`:
```rust
let mut it = Peekable::new("123".chars());
while let Some(digit) = iter.next_if_map_mut(|c| c.to_digit(10)) {
line_num = line_num * 10 + digit;
}
```
Note that the major difference here is that `next_if_map_mut` does not get owned items from the iterator, but mutable references. With that api, the closure can return an `Option` which avoids an `ok_or`. This may require cloning or copying the iterator elements, so if that is expensive, the owned version, `next_if_map`, may be preferable.
### Nightly use
At the moment, this feature is barely used in nightly, though I've found multiple good uses for it in my own projects, hence my pushing for stabilization. It makes the kind of patterns used in recursive descent parsing super concise and maybe with its stabilization it will find more use.
### Test coverage
Besides a quite comprehensive doctest, this feature is tested (including panicking in the closure) here:
c880acdd31/library/coretests/tests/iter/adapters/peekable.rs (L275-L359)
## History
- ACP: https://github.com/rust-lang/libs-team/issues/613 accepted with https://github.com/rust-lang/libs-team/issues/613#issuecomment-3049844223
- implementation: https://github.com/rust-lang/rust/pull/143725 with tests, and no issues reported since july.
## Acknowledgments
ACP, implementation and tracking issue for this feature all by @kennytm <3
- Using the implementation from sys::fs::common since ther is no
built-in copy implementation in UEFI.
- Tested with OVMF on QEMU.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
Remove std_detect_file_io and std_detect_dlsym_getauxval features
They were introduced back when std_detect was a standalone crate published to crates.io. The [motivation](https://github.com/rust-lang/stdarch/issues/655) for `std_detect_dlsym_getauxval` was to allow using `getauxval` without `dlopen` when statically linking musl, which we now unconditionally do for musl. And for `std_detect_file_io` to allow `no_std` usage, which std_detect now supports even with that feature enabled as it directly uses libc. This also prevents accidentally disabling runtime feature detection when using `cargo build -Zbuild-std -Zbuild-std-features=`
Implement create_dir_all() to operate iteratively instead of recursively
The current implementation of `create_dir_all(...)` in std::fs operates recursively. As mentioned in rust-lang/rust#124309, this could run into a stack overflow with big paths. To avoid this stack overflow issue, this PR implements the method in an iterative manner, preserving the documented behavior of:
```
Recursively create a directory and all of its parent components if they are missing.
This function is not atomic. If it returns an error, any parent components it was able to create will remain.
If the empty path is passed to this function, it always succeeds without creating any directories.
```
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150269 (Remove inactive nvptx maintainer)
- rust-lang/rust#150713 (mgca: Type-check fields of struct expr const args)
- rust-lang/rust#150765 (rustc_parse_format: improve error for missing `:` before `?` in format args)
- rust-lang/rust#150847 (Fix broken documentation links to SipHash)
- rust-lang/rust#150867 (rustdoc_json: Remove one call to `std::mem::take` in `after_krate`)
- rust-lang/rust#150872 (Fix some loop block coercion diagnostics)
- rust-lang/rust#150874 (Ignore `rustc-src-gpl` in fast try builds)
- rust-lang/rust#150875 (Refactor artifact keep mode in bootstrap)
- rust-lang/rust#150876 (Mention that `rustc_codegen_gcc` is a subtree in `rustc-dev-guide`)
- rust-lang/rust#150882 (Supress unused_parens lint for guard patterns)
- rust-lang/rust#150884 (Update bors email in CI postprocessing step)
Failed merges:
- rust-lang/rust#150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)
r? @ghost
Reflection MVP
I am opening this PR for discussion about the general design we should start out with, as there are various options (that are not too hard to transition between each other, so we should totally just pick one and go with it and reiterate later)
r? @scottmcm and @joshtriplett
project goal issue: https://github.com/rust-lang/rust-project-goals/issues/406
tracking issue: https://github.com/rust-lang/rust/issues/146922
The design currently implemented by this PR is
* `TypeId::info` (method, usually used as `id.info()` returns a `Type` struct
* the `Type` struct has fields that contain information about the type
* the most notable field is `kind`, which is a non-exhaustive enum over all possible type kinds and their specific information. So it has a `Tuple(Tuple)` variant, where the only field is a `Tuple` struct type that contains more information (The list of type ids that make up the tuple).
* To get nested type information (like the type of fields) you need to call `TypeId::info` again.
* There is only one language intrinsic to go from `TypeId` to `Type`, and it does all the work
An alternative design could be
* Lots of small methods (each backed by an intrinsic) on `TypeId` that return all the individual information pieces (size, align, number of fields, number of variants, ...)
* This is how C++ does it (see https://lemire.me/blog/2025/06/22/c26-will-include-compile-time-reflection-why-should-you-care/ and https://isocpp.org/files/papers/P2996R13.html#member-queries)
* Advantage: you only get the information you ask for, so it's probably cheaper if you get just one piece of information for lots of types (e.g. reimplementing size_of in terms of `TypeId::info` is likely expensive and wasteful)
* Disadvantage: lots of method calling (and `Option` return types, or "general" methods like `num_fields` returning 0 for primitives) instead of matching and field accesses
* a crates.io crate could implement `TypeId::info` in terms of this design
The backing implementation is modular enough that switching from one to the other is probably not an issue, and the alternative design could be easier for the CTFE engine's implementation, just not as nice to use for end users (without crates wrapping the logic)
One wart of this design that I'm fixing in separate branches is that `TypeId::info` will panic if used at runtime, while it should be uncallable
Fix broken documentation links to SipHash
The documentation of `SipHasher` previously linked to a page about SipHash on https://131002.net, a domain registered to Jean-Philippe Aumasson, one of the co-authors of the original SipHash paper (alongside Daniel J Bernstein).
That domain now redirects to another of Mr Aumasson's domains, https://www.aumasson.jp, but which does not host a similar page dedicated to SipHash. Instead, his site links to a GitHub repository containing a C implementation together with links to the original research paper. Mr Bernstein's own site, https://cr.yp.to, only hosts a copy of the research paper.
Therefore the GitHub repository appears to be the most official and complete reference to which we can link.
Fixesrust-lang/rust#150806
r? reddevilmidzy
Fix std::fs::copy on WASI by setting proper OpenOptions flags
When PR rust-lang/rust#147572 switched WASI to use Unix-style filesystem APIs, the open_to_and_set_permissions function for WASI was implemented to call OpenOptions::new().open() without setting any access mode flags.
This causes std::fs::copy to fail with the error:
"must specify at least one of read, write, or append access"
The fix is to explicitly set .write(true), .create(true), and .truncate(true) on the OpenOptions, matching the behavior of the non-WASI Unix implementation but without the permission handling that WASI doesn't support.
Minimal reproduction:
```rs
fn main() {
std::fs::write("/src.txt", b"test").unwrap();
match std::fs::copy("/src.txt", "/dst.txt") {
Ok(_) => println!("PASS: fs::copy works!"),
Err(e) => println!("FAIL: {}", e),
}
}
```
# Compile and run:
rustc +nightly --target wasm32-wasip2 test.rs -o test.wasm
wasmtime -S cli --dir . test.wasm
# Before fix: FAIL: must specify at least one of read, write, or append access
# After fix: PASS: fs::copy works!
Note: The existing test library/std/src/fs/tests.rs::copy_file_ok would have caught this regression if the std test suite ran on WASI targets. Currently std tests don't compile for wasm32-wasip2 due to Unix-specific test code in library/std/src/sys/fd/unix/tests.rs.
Fixes the regression introduced in nightly-2025-12-10.
r? @alexcrichton
- Make flush a noop since it is only for buffered writers.
- Also forward fsync to datasync. UEFI does not have anything
separate for metadata sync.
Signed-off-by: Ayush Singh <ayush@beagleboard.org>
When PR #147572 switched WASI to use Unix-style filesystem APIs, the
open_to_and_set_permissions function for WASI was implemented to call
OpenOptions::new().open() without setting any access mode flags.
This causes std::fs::copy to fail with the error:
"must specify at least one of read, write, or append access"
The fix is to explicitly set .write(true), .create(true), and
.truncate(true) on the OpenOptions, matching the behavior of the
non-WASI Unix implementation but without the permission handling
that WASI doesn't support.
Minimal reproduction:
fn main() {
std::fs::write("/src.txt", b"test").unwrap();
match std::fs::copy("/src.txt", "/dst.txt") {
Ok(_) => println!("PASS: fs::copy works!"),
Err(e) => println!("FAIL: {}", e),
}
}
# Compile and run:
rustc +nightly --target wasm32-wasip2 test.rs -o test.wasm
wasmtime -S cli --dir . test.wasm
# Before fix: FAIL: must specify at least one of read, write, or append access
# After fix: PASS: fs::copy works!
Note: The existing test library/std/src/fs/tests.rs::copy_file_ok
would have caught this regression if the std test suite ran on WASI
targets. Currently std tests don't compile for wasm32-wasip2 due to
Unix-specific test code in library/std/src/sys/fd/unix/tests.rs.
Fixes the regression introduced in nightly-2025-12-10.
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#150272 (docs(core): update `find()` and `rfind()` examples)
- rust-lang/rust#150385 (fix `Expr::can_have_side_effects` for `[x; N]` style array literal and binary expressions)
- rust-lang/rust#150561 (Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`)
- rust-lang/rust#150574 (Clarify `MoveData::init_loc_map`.)
- rust-lang/rust#150762 (Use functions more in rustdoc GUI tests)
- rust-lang/rust#150808 (rename the `derive_{eq, clone_copy}` features to `*_internals`)
- rust-lang/rust#150816 (Fix trait method anchor disappearing before user can click on it)
- rust-lang/rust#150821 (tests/ui/borrowck/issue-92157.rs: Remove (bug not fixed))
- rust-lang/rust#150829 (make attrs actually use `Target::GenericParam`)
- rust-lang/rust#150834 (Add tracking issue for `feature(multiple_supertrait_upcastable)`)
- rust-lang/rust#150864 (The aarch64-unknown-none target requires NEON, so the docs were wrong.)
r? @ghost
rename the `derive_{eq, clone_copy}` features to `*_internals`
Features like `derive_from` and `derive_coerce_pointee` refer to actual unstable derive macros, but the `derive_eq` and `derive_clone_copy` features are internal hacks. Rename them accordingly by adding the suffix `_internals`.
Finish transition from `semitransparent` to `semiopaque` for `rustc_macro_transparency`
Since it's a bit annoying to have different names for the same thing.
My understanding is that this is just internal stuff that is not part of any public API even tough rust-analyzer knows about it.
Continuation of
- https://github.com/rust-lang/rust/pull/139084.
Discovered while investigating
- https://github.com/rust-lang/rust/issues/150514