Commit Graph

18482 Commits

Author SHA1 Message Date
Pavel Grigorenko
7475a3416b Stabilize std::io::ErrorKind::InvalidFilename 2025-03-11 14:07:31 +03:00
bors
705421b522 Auto merge of #135651 - arjunr2:master, r=davidtwco
Support for `wasm32-wali-linux-musl` Tier-3 target

Adding a new target -- `wasm32-wali-linux-musl` -- to the compiler can target the [WebAssembly Linux Interface](https://github.com/arjunr2/WALI) according to MCP rust-lang/compiler-team#797
Preliminary support involves minimal changes, primarily

* A new target spec for `wasm32_wali_linux_musl` that bridges linux options with supported wasm options. Right now, since there is no canonical Linux ABI for Wasm, we use `wali` in the vendor field, but this can be migrated in future version.
* Dependency patches to the following crates are required and these crates can be updated to bring target support:
  - **stdarch** rust-lang/stdarch#1702
  - **libc** rust-lang/libc#4244
  - **cc** rust-lang/cc-rs#1373
* Minimal additions for FFI support

cc `@tgross35` for libc-related changes

Tier-3 policy:
> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

I will take responsibility for maintaining this target as well as issues

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

The target name is consistent with naming patterns from currently supported targets for arch (wasm32), OS, (linux) and env (musl)

> Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.

No naming confusion is introduced.

> If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo.

Compliant

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.

It's fully open source

> The target must not introduce license incompatibilities. Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

Noted

> The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

Compliant

> Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

All tools are open-source

> "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

No terms present

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.
This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

I am not a reviewer

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

This target supports the full standard library with appropriate configuration stubs where necessary (however, similar to all existing wasm32 targets, it excludes dynamic linking or hardware-specific features)

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

Preliminary documentation is provided at https://github.com/arjunr2/WALI. Further detailed docs (if necessary) can be added once this PR lands

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

Understood

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

To the best of my knowledge, it does not break any existing target in the ecosystem -- only minimal configuration-specific additions were made to support the target.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

We can upstream LLVM target support
2025-03-11 07:21:45 +00:00
bors
374ce1f909 Auto merge of #136932 - m-ou-se:fmt-width-precision-u16, r=scottmcm
Reduce formatting `width` and `precision` to 16 bits

This is part of https://github.com/rust-lang/rust/issues/99012

This is reduces the `width` and `precision` fields in format strings to 16 bits. They are currently full `usize`s, but it's a bit nonsensical that we need to support the case where someone wants to pad their value to eighteen quintillion spaces and/or have eighteen quintillion digits of precision.

By reducing these fields to 16 bit, we can reduce `FormattingOptions` to 64 bits (see https://github.com/rust-lang/rust/pull/136974) and improve the in memory representation of `format_args!()`. (See additional context below.)

This also fixes a bug where the width or precision is silently truncated when cross-compiling to a target with a smaller `usize`. By reducing the width and precision fields to the minimum guaranteed size of `usize`, 16 bits, this bug is eliminated.

This is a breaking change, but affects almost no existing code.

---

Details of this change:

There are three ways to set a width or precision today:

1. Directly a formatting string, e.g. `println!("{a:1234}")`
2. Indirectly in a formatting string, e.g. `println!("{a:width$}", width=1234)`
3. Through the unstable `FormattingOptions::width` method.

This PR:

- Adds a compiler error for 1. (`println!("{a:9999999}")` no longer compiles and gives a clear error.)
- Adds a runtime check for 2. (`println!("{a:width$}, width=9999999)` will panic.)
- Changes the signatures of the (unstable) `FormattingOptions::[get_]width` methods to use a `u16` instead.

---

Additional context for improving `FormattingOptions` and `fmt::Arguments`:

All the formatting flags and options are currently:

- The `+` flag (1 bit)
- The `-` flag (1 bit)
- The `#` flag (1 bit)
- The `0` flag (1 bit)
- The `x?` flag (1 bit)
- The `X?` flag (1 bit)
- The alignment (2 bits)
- The fill character (21 bits)
- Whether a width is specified (1 bit)
- Whether a precision is specified (1 bit)
- If used, the width (a full usize)
- If used, the precision (a full usize)

Everything except the last two can simply fit in a `u32` (those add up to 31 bits in total).

If we can accept a max width and precision of u16::MAX, we can make a `FormattingOptions` that is exactly 64 bits in size; the same size as a thin reference on most platforms.

If, additionally, we also limit the number of formatting arguments, we can also reduce the size of `fmt::Arguments` (that is, of a `format_args!()` expression).
2025-03-11 04:07:05 +00:00
Arjun Ramesh
336a327f7c Target definition for wasm32-wali-linux-musl to support the Wasm Linux
Interface

This commit does not patch libc, stdarch, or cc
2025-03-10 21:26:45 -04:00
Nicole L
2b3b0bd50b Remove unused file 2025-03-10 14:19:27 -07:00
Nicole L
f5dd3d13fc Update Trusty support to account for recent libstd reorganization 2025-03-10 12:54:59 -07:00
Nicole LeGare
0b1a7ab339 Remove custom TLS implementation for Trusty targets 2025-03-10 10:00:25 -07:00
Nicole LeGare
22fea97c9d Disable unsupported tests
Unclear why this needs to be done manually and is not done by the existing Trusty patches.
2025-03-10 10:00:25 -07:00
Nicole LeGare
d633d8e074 Format after patches have been applied 2025-03-10 10:00:25 -07:00
Nicole LeGare
7f6ee12526 Apply rustc-0054-Add-std-os-fd-support-for-Trusty.patch 2025-03-10 10:00:24 -07:00
Nicole LeGare
87ca2dbb00 Apply rustc-0023-Add-Trusty-OS-support-to-Rust-std.patch 2025-03-10 10:00:24 -07:00
Mara Bos
2647cf17e7 Add #[track_caller] to from_usize. 2025-03-10 12:20:06 +01:00
Mara Bos
7677567e54 Remove unnecessary semicolon. 2025-03-10 12:20:06 +01:00
Mara Bos
4374d5461e Update tests. 2025-03-10 12:20:05 +01:00
Mara Bos
fb9ce02976 Limit formatting width and precision to 16 bits. 2025-03-10 12:20:05 +01:00
Bastian Kersting
e5dc1e3786 Add comments for #[no_sanitize(cfi)] in stdlib 2025-03-10 08:59:24 +00:00
Bastian Kersting
02bb2d4410 Disable CFI for weakly linked syscalls
Currently, when enabling CFI via -Zsanitizer=cfi and executing e.g.
std::sys::random::getrandom, we can observe a CFI violation. This is
the case for all consumers of the std::sys::pal::weak::weak macro,
as it is defining weak functions which don't show up in LLVM IR
metadata. CFI fails for all these functions.

Similar to other such cases in
https://github.com/rust-lang/rust/issues/115199, this change stops
emitting the CFI typecheck for consumers of the macro via the
\#[no_sanitize(cfi)] attribute.
2025-03-10 08:51:04 +00:00
Matthias Krüger
2f1908df61
Rollup merge of #138074 - thaliaarchi:hermit-seek, r=ChrisDenton
Support `File::seek` for Hermit

`lseek` was added in `hermit-abi` in commit [87dd201](87dd201a14) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc ``@mkroening,`` ``@stlankes``

Fixes https://github.com/hermit-os/hermit-rs/issues/652
2025-03-10 09:32:13 +01:00
Matthias Krüger
2270979935
Rollup merge of #137585 - xizheyin:issue-135801, r=workingjubilee
Update documentation to consistently use 'm' in atomic synchronization example

Fixes #135801
2025-03-10 09:32:11 +01:00
Thalia Archibald
8c7a94e4cd Implement read_buf and vectored read/write for SGX stdio 2025-03-10 00:48:13 -07:00
Jethro Beekman
b52666868f Copy from userspace to MaybeUninit
Co-authored-by: Thalia Archibald <thalia@archibald.dev>
2025-03-10 00:45:19 -07:00
Ayush Singh
e0a9dd31c1
uefi: fs: Partially implement FileAttr
- Just the permission and file type.
- FileTimes will need some new conversion functions and thus will come
  with a future PR. Trying to keep things simple here.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10 08:16:56 +05:30
Ayush Singh
c717cc7cd2
uefi: fs: Implement FileType
- Similar to FilePermissions, using bool to represent the bitfield.
- FileType cannot be changed, so no need to worry about converting back
  to attribute.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10 08:16:56 +05:30
Ayush Singh
1833737e16
uefi: fs: Implement FilePermission
- UEFI file permissions are indicated using a u64 bitfield used for
  readonly/filetype, etc.
- Using normal bool with to and from attribute conversions to
  FilePermission from overriding some other bitfields.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-03-10 08:16:55 +05:30
joboet
c52e0596c5
std: move stdio to sys
As per #117276, this moves the platform definitions of `Stdout` and friends into `sys`. This PR also unifies the UNIX and Hermit implementations and moves the `__rust_print_err` function needed by libunwind on SGX into the dedicated module for such helper functions.
2025-03-09 23:42:13 +01:00
Thalia Archibald
1abaacd375 Support File::seek for Hermit 2025-03-09 15:38:30 -07:00
Thalia Archibald
32d0c4ed86 Update hermit-abi to 0.5.0 2025-03-09 15:38:29 -07:00
Matthias Krüger
33530e4cb9
Rollup merge of #138276 - bdbai:fix-uwp-ntopenfile, r=ChrisDenton
Lazy load NtOpenFile for UWP

Lazily load `NtOpenFile` to allow libraries targeting UWP to build and link.

Fixes #138257 .

r? `@ChrisDenton`
2025-03-09 16:41:54 +01:00
Matthias Krüger
980a529164
Rollup merge of #138233 - smmalis37:no-advapi32, r=ChrisDenton
Windows: Don't link std (and run-make) against advapi32, except on win7

Std no longer depends on any functionality provided by advapi32, so we can remove it from the list of external libraries we link against. Except, the win7 targets do still rely on advapi32-provided functionality. This PR therefore moves linking against it to only occur on win7 targets, so that no new uses of it slip in without being noticed.
2025-03-09 16:41:52 +01:00
Matthias Krüger
2460fc68b9
Rollup merge of #138228 - TDecking:master, r=jhpratt
Use `disjoint_bitor` inside `borrowing_sub`

This makes the definition of `borrowing_sub` consistent with that of `carrying_add`.
2025-03-09 16:41:51 +01:00
Matthias Krüger
3bc41aa3e6
Rollup merge of #137650 - thaliaarchi:move-fs-pal, r=Noratrieb
Move `fs` into `sys`

Move platform definitions of `fs` into `std::sys`, as part of https://github.com/rust-lang/rust/issues/117276.

cc `@joboet`
2025-03-09 16:41:49 +01:00
bdbai
33c6c3a1e9 Lazy load NtOpenFile for UWP 2025-03-09 22:42:17 +08:00
Marijn Schouten
506c304654 Clarify iterator by_ref docs 2025-03-09 13:24:46 +01:00
Thalia Archibald
685619e4c9 Move fs into sys 2025-03-08 16:22:37 -08:00
Martin Habovstiak
50ea503d9d Stabilize const_vec_string_slice
This feature was approved for stabilization in
https://github.com/rust-lang/rust/issues/129041#issuecomment-2508940661
so this change stabilizes it.
2025-03-08 17:03:52 +01:00
Steven Malis
9278a3ebd6 Don't link against advapi32, except on win7. 2025-03-08 10:55:47 -05:00
Tobias Decking
8d37f38873
Use disjoint_bitor inside borrowing_sub 2025-03-08 15:45:03 +01:00
ltdk
ffa86bf6eb Reword documentation about SocketAddr having varying layout 2025-03-08 08:19:22 -05:00
Jacob Pratt
6576d35aef
Rollup merge of #138189 - GuillaumeGomez:env-var, r=joshtriplett
Mention `env` and `option_env` macros in `std::env::var` docs

Fixes https://github.com/rust-lang/rust/issues/138159.

Just like there are mentions in `env!` and `option_env!` docs to `std::env::var`, it'd be nice to have a "mention back" as well.
2025-03-08 01:27:23 -05:00
Jacob Pratt
0c67061569
Rollup merge of #137528 - ChrisDenton:rename-win, r=joboet
Windows: Fix error in `fs::rename` on Windows 1607

Fixes #137499

There's a bug in our Windows implementation of `fs::rename` that only manifests on a specific version of Windows. Both newer and older versions of Windows work.

I took the safest route to fixing this by using the old `MoveFileExW` function to implement this and only falling back to the new behaviour if that fails. This is similar to what is done in `unlink` (just above this function).

try-job: dist-x86_64-mingw
try-job: dist-x86_64-msvc
2025-03-08 01:27:21 -05:00
Jacob Pratt
720eacf086
Rollup merge of #136642 - bjorn3:separate_alloctest_crate, r=cuviper
Put the alloc unit tests in a separate alloctests package

Same rationale as https://github.com/rust-lang/rust/pull/135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
2025-03-08 01:27:20 -05:00
Jacob Pratt
8cf86cd68d
Rollup merge of #138000 - RalfJung:atomic-rmw, r=Amanieu
atomic: clarify that failing conditional RMW operations are not 'writes'

Fixes https://github.com/rust-lang/rust/issues/136669

r? ``@Amanieu``
Cc ``@rust-lang/opsem`` ``@chorman0773`` ``@gnzlbg`` ``@briansmith``
2025-03-07 21:57:51 -05:00
Jacob Pratt
4ec8407196
Rollup merge of #137606 - davidtwco:next-edition, r=traviscross,ehuss
add a "future" edition

This idea has been discussed previously [on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Continuous.20edition-like.20changes.3F/near/432559262) (though what I've implemented isn't exactly the "next"/"future" editions proposed in that message, just the "future" edition). I've found myself prototyping changes that involve edition migrations and wanting to target an upcoming edition for those migrations, but none exists. This should be permanently unstable and not removed.
2025-03-07 21:57:49 -05:00
Guillaume Gomez
17dd2b179c Mention env and option_env macros in std::env::var docs 2025-03-07 22:00:36 +01:00
bjorn3
22d0440993 Add comments 2025-03-07 19:11:13 +00:00
bjorn3
ae5687e4b0 Fully test the alloc crate through alloctests
For the tests that make use of internal implementation details, we
include the module to test using #[path] in alloctests now.
2025-03-07 19:11:13 +00:00
bjorn3
701bedc323 Move last remaining Rc test to alloctests 2025-03-07 19:11:13 +00:00
bjorn3
be1e0b786d Move most Rc tests to alloctests 2025-03-07 19:11:13 +00:00
bjorn3
fb04372dc5 Move all alloc integration tests to a new alloctests crate 2025-03-07 19:11:11 +00:00
Matthias Krüger
f5a143f796
Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=nikomatsakis
Ergonomic ref counting

This is an experimental first version of ergonomic ref counting.

This first version implements most of the RFC but doesn't implement any of the optimizations. This was left for following iterations.

RFC: https://github.com/rust-lang/rfcs/pull/3680
Tracking issue: https://github.com/rust-lang/rust/issues/132290
Project goal: https://github.com/rust-lang/rust-project-goals/issues/107

r? ```@nikomatsakis```
2025-03-07 19:15:33 +01:00
Chris Denton
3cb53df1fe
Return OutOfMemoryError and update docs 2025-03-07 17:51:56 +00:00
Chris Denton
0dfe2ae3fb
Windows: Use MoveFileEx by default in fs:rename 2025-03-07 17:51:49 +00:00
bors
03eb454523 Auto merge of #138155 - matthiaskrgr:rollup-xq5buio, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #137674 (Enable `f16` for LoongArch)
 - #138034 (library: Use `size_of` from the prelude instead of imported)
 - #138060 (Revert #138019 after further discussion about how hir-pretty printing should work)
 - #138073 (Break critical edges in inline asm before code generation)
 - #138107 (`librustdoc`: clippy fixes)
 - #138111 (Use `default_field_values` for `rustc_errors::Context`, `rustc_session::config::NextSolverConfig` and `rustc_session::config::ErrorOutputType`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-07 13:47:27 +00:00
Matthias Krüger
b834632071
Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35
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.

try-job: test-various
try-job: x86_64-gnu
try-job: x86_64-msvc-1
2025-03-07 10:12:44 +01:00
Matthias Krüger
6e7d1353d1
Rollup merge of #137674 - heiher:enable-f16-loong, r=tgross35
Enable `f16` for LoongArch

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

r? ```@tgross35```

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

try-job: dist-loongarch64-linux
try-job: dist-loongarch64-musl
2025-03-07 10:12:43 +01:00
Matthias Krüger
c33e9d6844
Rollup merge of #138129 - RalfJung:stabilize-const-things, r=tgross35
Stabilize const_char_classify, const_sockaddr_setters

FCP for const_char_classify: #132241
FCP for const_sockaddr_setters: #131714

Fixes #132241
Fixes #131714

Cc ``@rust-lang/wg-const-eval``
2025-03-07 10:02:30 +01:00
Matthias Krüger
9e16082e63
Rollup merge of #137904 - scottmcm:ordering-is, r=workingjubilee
Improve the generic MIR in the default `PartialOrd::le` and friends

It looks like I regressed this accidentally in #137197 due to #137901

So this PR does two things:
1. Tweaks the way we're calling `is_some_and` so that it optimizes in the generic MIR (rather than needing to optimize it in every monomorphization) -- the first commit adds a MIR test, so you can see the difference in the second commit.
2. Updates the implementations of `is_le` and friends to be slightly simpler, and parallel how clang does them.
2025-03-07 10:02:26 +01:00
Matthias Krüger
a98df54bdc
Rollup merge of #137832 - wgwoods:fix-bufreader-peek, r=joboet
Fix crash in BufReader::peek()

`bufreader_peek` tracking issue: #128405

This fixes a logic error in `Buffer::read_more()` that would make `BufReader::peek()` expose uninitialized data and/or segfault if `read_more()` was called with a partially-full buffer and a non-empty inner reader.
2025-03-07 10:02:22 +01:00
Matthias Krüger
d9860276b8
Rollup merge of #137777 - thaliaarchi:os_string-push-str, r=joboet
Specialize `OsString::push` and `OsString as From` for UTF-8

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.

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.

Unfortunately, a specialization for `T: AsRef<str>` conflicts with `T: AsRef<OsStr>`, so stamp out string types with a macro.

r? ``@ChrisDenton``
2025-03-07 10:02:20 +01:00
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
Matthias Krüger
0b151c6c4f
Rollup merge of #136667 - vita-rust:revert-vita-c-char, r=cuviper
Revert vita's c_char back to i8

# Description

Hi!

https://github.com/rust-lang/rust/pull/132975 changed the definition of `c_char` from i8 to u8 for most ARM targets. While that would usually be correct, [VITASDK uses signed chars by default](https://github.com/vitasdk/buildscripts/blob/master/patches/gcc/0001-gcc-10.patch#L33-L34). The Clang definitions are incorrect because Clang is not (yet?) supported by the vita commmunity / `VITADSK`, On the Rust side, the pre-compiled libraries the user can link to are all compiled using vita's `gcc` and [we set `TARGET_CC` and `TARGET_CXX`](d564a132cb/src/commands/build.rs (L230)) in `cargo vita` for build scripts using `cc`.

I'm creating it as a draft PR so that we can discuss it and possibly get it approved here, but wait to merge the [libc side](https://github.com/rust-lang/libc/pull/4258) and get a libc version first, as having the definitions out of sync breaks std. As a nightly-only target it can be confusing/frustrating for new users when the latest nightly, which is the default, is broken.
2025-03-07 10:02:19 +01:00
Thalia Archibald
5dfa2f5fd0 Use turbofish for size_of<T> and align_of<T> in docs 2025-03-06 20:20:38 -08: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
bors
91a0e1604f Auto merge of #138127 - compiler-errors:rollup-kcarqrz, r=compiler-errors
Rollup of 17 pull requests

Successful merges:

 - #137827 (Add timestamp to unstable feature usage metrics)
 - #138041 (bootstrap and compiletest: Use `size_of_val` from the prelude instead of imported)
 - #138046 (trim channel value in `get_closest_merge_commit`)
 - #138053 (Increase the max. custom try jobs requested to `20`)
 - #138061 (triagebot: add a `compiler_leads` ad-hoc group)
 - #138064 (Remove - from xtensa targets cpu names)
 - #138075 (Use final path segment for diagnostic)
 - #138078 (Reduce the noise of bootstrap changelog warnings in --dry-run mode)
 - #138081 (Move `yield` expressions behind their own feature gate)
 - #138090 (`librustdoc`: flatten nested ifs)
 - #138092 (Re-add `DynSend` and `DynSync` impls for `TyCtxt`)
 - #138094 (a small borrowck cleanup)
 - #138098 (Stabilize feature `const_copy_from_slice`)
 - #138103 (Git ignore citool's target directory)
 - #138105 (Fix broken link to Miri intrinsics in documentation)
 - #138108 (Mention me (WaffleLapkin) when changes to `rustc_codegen_ssa` occur)
 - #138117 ([llvm/PassWrapper] use `size_t` when building arg strings)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-07 02:56:46 +00:00
bors
98a48781fe Auto merge of #138114 - compiler-errors:rollup-7xr4b69, r=compiler-errors
Rollup of 25 pull requests

Successful merges:

 - #135733 (Implement `&pin const self` and `&pin mut self` sugars)
 - #135895 (Document workings of successors more clearly)
 - #136922 (Pattern types: Avoid having to handle an Option for range ends in the type system or the HIR)
 - #137303 (Remove `MaybeForgetReturn` suggestion)
 - #137327 (Undeprecate env::home_dir)
 - #137358 (Match Ergonomics 2024: add context and examples to the unstable book)
 - #137534 ([rustdoc] hide item that is not marked as doc(inline) and whose src is doc(hidden))
 - #137565 (Try to point of macro expansion from resolver and method errors if it involves macro var)
 - #137637 (Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck)
 - #137643 (Add DWARF test case for non-C-like `repr128` enums)
 - #137744 (Re-add `Clone`-derive on `Thir`)
 - #137758 (fix usage of ty decl macro fragments in attributes)
 - #137764 (Ensure that negative auto impls are always applicable)
 - #137772 (Fix char count in `Display` for `ByteStr`)
 - #137798 (ci: use ubuntu 24 on arm large runner)
 - #137802 (miri native-call support: all previously exposed provenance is accessible to the callee)
 - #137805 (adjust Layout debug printing to match the internal field name)
 - #137808 (Do not require that unsafe fields lack drop glue)
 - #137820 (Clarify why InhabitedPredicate::instantiate_opt exists)
 - #137825 (Provide more context on resolve error caused from incorrect RTN)
 - #137834 (rustc_fluent_macro: use CARGO_CRATE_NAME instead of CARGO_PKG_NAME)
 - #137868 (Add minimal platform support documentation for powerpc-unknown-linux-gnuspe)
 - #137910 (Improve error message for `AsyncFn` trait failure for RPIT)
 - #137920 (interpret/provenance_map: consistently use range_is_empty)
 - #138038 (Update `compiler-builtins` to 0.1.151)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-06 23:39:38 +00:00
Ralf Jung
8f8c7fcb8b stabilize const_sockaddr_setters 2025-03-06 22:29:07 +01:00
Ralf Jung
98dc15fb0f stabilize const_char_classify 2025-03-06 22:28:48 +01:00
Santiago Pastorino
5a6d00c05d
Add allow(incomplete_features) to alloc 2025-03-06 17:58:35 -03:00
Santiago Pastorino
a68db7e3a8
Add examples in stdlib demonstrating the use syntax 2025-03-06 17:58:34 -03:00
Santiago Pastorino
dcdfd551f0
Add UseCloned trait related code 2025-03-06 17:58:32 -03:00
Michael Goulet
61aaec7965
Rollup merge of #138105 - reddevilmidzy:fix-broken-link, r=saethlin
Fix broken link to Miri intrinsics in documentation

This PR updates an outdated link in the library/core/src/intrinsics/mod.rs file. The previous link, pointing to the Miri repository's src/shims/intrinsics directory, has been replaced with the correct one: https://github.com/rust-lang/miri/tree/master/src/intrinsics. This ensures that users can access the appropriate resources for the relevant intrinsic functions.
2025-03-06 15:40:09 -05:00
Eric Huss
a78d1b092c Update stdarch 2025-03-06 11:11:55 -08: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
1c3733aa69
Rollup merge of #137808 - jswrenn:droppy-unsafe-fields, r=nnethercote
Do not require that unsafe fields lack drop glue

Instead, we adopt the position that introducing an `unsafe` field itself carries a safety invariant: that if you assign an invariant to that field weaker than what the field's destructor requires, you must ensure that field is in a droppable state in your destructor.

See:
- https://github.com/rust-lang/rfcs/pull/3458#discussion_r1971676100
- https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/unsafe.20fields.20RFC/near/502113897

Tracking Issue: #132922
2025-03-06 12:22:19 -05:00
Michael Goulet
fe926384c1
Rollup merge of #137772 - thaliaarchi:bstr-display, r=joshtriplett
Fix char count in `Display` for `ByteStr`

`ByteStr as Display` performs a byte count when a char count is required.

r? ```````````@joshtriplett```````````
2025-03-06 12:22:16 -05:00
Michael Goulet
00132141c7
Rollup merge of #137764 - compiler-errors:always-applicable-negative-impl, r=lcnr
Ensure that negative auto impls are always applicable

r? lcnr (or reassign if you dont want to review)

https://github.com/rust-lang/rust/issues/68318#issuecomment-2689265030
2025-03-06 12:22:16 -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
Michael Goulet
6ac714d526
Rollup merge of #136922 - oli-obk:pattern-types-option-ends, r=BoxyUwU
Pattern types: Avoid having to handle an Option for range ends in the type system or the HIR

Instead,

1. during hir_ty_lowering, we now generate constants for the min/max when the range doesn't have a start/end specified.
2. in a later commit we generate those constants during ast lowering, simplifying everything further by not having to handle the range end inclusivity anymore in the type system (and thus avoiding any issues of `0..5` being different from `0..=4`

I think it makes all the type system code simpler, and the cost of the extra `ConstKind::Value` processing seems negligible.

r? `@BoxyUwU`

cc `@joshtriplett` `@scottmcm`
2025-03-06 12:22:10 -05:00
Michael Goulet
5b074125e5
Rollup merge of #135895 - hkBst:patch-15, r=joboet
Document workings of successors more clearly

This is an attempt to fix #135087 together with https://github.com/rust-lang/rust/pull/135886, but I am not sure if I've succeeded in adding much clarity here, so don't be shy with your comments.
2025-03-06 12:22:09 -05:00
Redddy
6b14125102
Fix broken link to Miri intrinsics in documentation
Replaced the outdated link to https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics with the correct link https://github.com/rust-lang/miri/tree/master/src/intrinsics in the library/core/src/intrinsics/mod.rs file.
2025-03-07 00:55:24 +09:00
okaneco
d4c0c94577 Stabilize const_copy_from_slice feature
Stabilizes `copy_from_slice` method on `[T]`
2025-03-06 07:32:52 -05:00
Oli Scherer
e8f7a382be Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
Scott McMurray
eae5ed609d Make is_le and friends work like clang's 2025-03-05 21:58:46 -08:00
许杰友 Jieyou Xu (Joe)
257b4947ed
Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk
Remove unsizing coercions for tuples

See https://github.com/rust-lang/rust/issues/42877#issuecomment-2686010847 and below comments for justification.

Tracking issue: #42877
Fixes: #135217
2025-03-05 21:46:44 +08:00
许杰友 Jieyou Xu (Joe)
4aa61e77ff
Rollup merge of #137679 - bjorn3:coretests_improvements, r=jieyouxu,onur-ozkan
Various coretests improvements

The first commit is not yet strictly necessary as directly testing libcore works though useless work, but will be necessary once https://github.com/rust-lang/rust/pull/136642 migrates the liballoc tests into a separate package. The second commit fixes https://github.com/rust-lang/rust/issues/137478 and ensures that coretests actually gets tested on all CI job. The third commit fixes an error that didn't get caught because coretests doesn't run on the wasm32 CI job.
2025-03-05 21:46:42 +08:00
许杰友 Jieyou Xu (Joe)
604d1ba61c
Rollup merge of #137569 - aDotInTheVoid:for-iurii, r=ibraheemdev
Stabilize `string_extend_from_within`

FCP'd here: https://github.com/rust-lang/rust/issues/103806#issuecomment-2674989531.

Closes  #103806.
2025-03-05 21:46:41 +08: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
许杰友 Jieyou Xu (Joe)
1b9b515674
Rollup merge of #136662 - thaliaarchi:formatter-pad-char-count, r=m-ou-se
Count char width at most once in `Formatter::pad`

When both width and precision flags are specified, then `Formatter::pad` counts the character width twice. Instead, record the character width when truncating it to the precision, so it does not need to be recomputed. Simplify control flow so the cases are more clear.

Related:
- 6c9e708f4b (`fmt::Formatter::pad`: don't call chars().count() more than one time, 2021-09-01): Reduce counting chars from thrice to twice in worst case
- ede39aeb33 (feat: reinterpret `precision` field for strings, 2016-06-29): Change meaning of precision for strings
- b820748ff5 (Implement formatting arguments for strings and integers, 2013-08-10): Implement `Formatter::pad`
2025-03-05 21:46:33 +08:00
许杰友 Jieyou Xu (Joe)
9b8accbeb6
Rollup merge of #134063 - tgross35:dec2flt-refactoring, r=Noratrieb
dec2flt: Clean up float parsing modules

This is the first portion of my work adding support for parsing and printing `f16`. Changes in `float.rs` replace the magic constants with expressions and add some use of generics to better support the new float types. Everything else is related to documentation or naming; there are no functional changes in this PR.

This can be reviewed by commit.
2025-03-05 21:46:31 +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
131867b68b
Rollup merge of #137986 - fuyangpengqi:master, r=Amanieu
Fix some typos

Fix some typos
2025-03-04 19:37:04 -08:00
Jubilee
0bb2f95c26
Rollup merge of #137850 - slanterns:box_uninit_write, r=ibraheemdev
Stabilize `box_uninit_write`

Closes: https://github.com/rust-lang/rust/issues/129397.
2025-03-04 19:37:00 -08:00
Jubilee
29d3ad9eba
Rollup merge of #137829 - cramertj:stabilize-split-off, r=jhpratt
Stabilize [T]::split_off... methods

This was previously known as the slice_take feature.

Closes #62280
2025-03-04 19:36:59 -08: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
Michael Goulet
3d62b279dd Ensure that negative auto impls are always applicable 2025-03-04 17:45:18 +00:00
pcorwin
c392cf7690 Added documentation for flushing 2025-03-04 12:21:12 -05:00