Commit Graph

8474 Commits

Author SHA1 Message Date
bors e52f547ed4 Auto merge of #154160 - JonathanBrouwer:rollup-4jbkEbt, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#154154 (Emit fewer errors for incorrect rtn and `=` -> `:` typos in bindings)
 - rust-lang/rust#154155 (tests/ui/async-await/drop-option-future.rs: New regression test)
 - rust-lang/rust#146961 (Allow passing `expr` metavariable as `cfg` predicate)
 - rust-lang/rust#154118 (don't suggest non-deriveable traits for unions)
 - rust-lang/rust#154120 (Start migrating `DecorateDiagCompat::Builtin` items to `DecorateDiagCompat::Dynamic`)
 - rust-lang/rust#154156 (Moving issue-52049 to borrowck)
2026-03-21 07:20:47 +00:00
Jonathan Brouwer b9f8e25f6e Rollup merge of #146961 - Jules-Bertholet:expr-cfg, r=JonathanBrouwer
Allow passing `expr` metavariable as `cfg` predicate

This PR allows expanding `expr` metavariables inside the configuration predicates of `cfg` and `cfg_attr` invocations.
For example, the following code will now compile:

```rust
macro_rules! mac {
    ($e:expr) => {
        #[cfg_attr($e, inline)]
        #[cfg($e)]
        fn func() {}

        #[cfg(not($e))]
        fn func() {
            panic!()
        }
    }
}

mac!(any(unix, feature = "foo"));
```

There is currently no `macro_rules` fragment specifier that can represent all valid `cfg` predicates. `meta` comes closest, but excludes `true` and `false`. By fixing that, this change makes it easier to write declarative macros that parse `cfg` or `cfg_attr` invocations, for example https://github.com/rust-lang/rust/pull/146281/.

@rustbot label T-lang needs-fcp A-attributes A-cfg A-macros
2026-03-21 00:42:47 +01:00
Ralf Jung 9dfdb6b4bc test copy_specializes_from_vecdeque: reduce iteration count for Miri 2026-03-20 15:55:56 +01:00
Stuart Cook 83d921de92 Rollup merge of #154019 - cyrgani:feature-clean, r=joboet
two smaller feature cleanups

Remove an unneeded feature gate for a private macro and sort the used features correctly by whether they are language or library features.
2026-03-20 15:33:07 +11:00
Jonathan Brouwer 981f837e2d Rollup merge of #153170 - LevitatingBusinessMan:is_disconnected, r=Mark-Simulacrum
Add is_disconnected functions to mpsc and mpmc channels

Add `is_disconnected()` functions to the `Sender` and `Receiver` of both `mpmc` an `mpsc` channels.

```rust
std::sync::mpmc::Sender<T>::is_disconnected(&self) -> bool
std::sync::mpmc::Receiver<T>::is_disconnected(&self) -> bool

std::sync::mpsc::Sender<T>::is_disconnected(&self) -> bool
std::sync::mpsc::Receiver<T>::is_disconnected(&self) -> bool
```

The `mpsc` methods are locked behind the `mpsc_is_disconnected` feature gate, which has no tracking issue yet.

ACP: https://github.com/rust-lang/libs-team/issues/748
Tracking issue: https://github.com/rust-lang/rust/issues/153668
2026-03-19 13:42:33 +01:00
Jonathan Brouwer 2c49023125 Rollup merge of #153333 - gautam899:main, r=Mark-Simulacrum
Fix bootstrap rust build failure for vxworks

Fixes rust-lang/rust#153332

Starting with VxWorks 25.09, struct stat was updated to use struct timespec instead of time_t for timestamp fields.

The following changes were made in libc in the commit [libc](https://github.com/rust-lang/libc/pull/4781).

As a result, when performing a bootstrap build with VxWorks ≥ 25.09, libc no longer exposes the fields st_mtime, st_atime, and st_ctime, as they are conditionally compiled in src/vxworks/mod.rs here [libc](https://github.com/rust-lang/libc/blob/56caa81b6b433c49c5704bf0400a02d428cfacda/src/vxworks/mod.rs#L229). This causes the build to fail.

For VxWorks versions earlier than 25.09, the build completes successfully without errors.

This PR resolves the issue by detecting the WIND_RELEASE_ID environment variable (which is set in the VxWorks build environment) and conditionally guarding the affected functions in the two additional files where the errors originate.
2026-03-19 13:42:25 +01:00
Jonathan Brouwer b1050a74cc Rollup merge of #152998 - xtqqczze:panic-truncate, r=jhpratt
std: make `OsString::truncate` a no-op when `len > current_len`

Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`.

Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op.

Tracking (`os_string_truncate`): https://github.com/rust-lang/rust/issues/133262
See also: https://github.com/rust-lang/rust/pull/32977

cc: @alexcrichton, @lolbinarycat
2026-03-17 21:20:01 +01:00
cyrgani e350a56cf9 move features into the correct section 2026-03-17 09:31:03 +00:00
Jules Bertholet 7f83c784bd Allow passing expr metavariable as a cfg predicate 2026-03-15 13:44:14 -04:00
Jules Bertholet c5c1d94e6c Add From impls for wrapper types
- `From<T> for ThinBox<T>`
- `From<T> for UniqueRc<T>`
- `From<T> for UniqueArc<T>`
- `From<T: UnwindSafe> for AssertUnwindSafe<T>`
- `From<T> for LazyCell<T, F>`
- `From<T> for LazyLock<T, F>`
2026-03-14 22:09:35 -04:00
Bhavya Gautam 24d86b5f2b Fix rust build failure for vxworks 2026-03-14 17:54:19 +05:30
Sinan Nalkaya 8459d6bf3a Fix std doctest build for SGX target. 2026-03-12 15:49:13 +01:00
LevitatingBusinessMan (Rein Fernhout) ce2de643fc assign mpsc_is_disconnected issue 153668 2026-03-10 19:21:19 +01:00
Jonathan Brouwer b8e01edc24 Rollup merge of #153413 - joboet:organize-pal-os, r=Mark-Simulacrum
std: organise `sys::pal::os`

Continuing rust-lang/rust#153341, this moves around some functions in `sys::pal`, so that `pal::os` only contains standard-path-related code (which I'll move later as part of rust-lang/rust#117276).

Best reviewed commit-by-commit.
2026-03-09 11:49:22 +01:00
Jonathan Brouwer 1ef29e7af6 Rollup merge of #152535 - joboet:xous_env_once_lock, r=Mark-Simulacrum
std: use `OnceLock` for Xous environment variables

There's no need for exposed-provenance-shenanigans here...

CC @xobs
2026-03-08 22:51:51 +01:00
Josh Stone 78157ddde9 Replace version placeholders with 1.95.0
(cherry picked from commit bad24ccbec)
2026-03-07 10:42:01 -08:00
Jonathan Brouwer 4e50a44530 Rollup merge of #153174 - Trivo25:fix-wasm64-sync-cfg, r=joboet
std: add wasm64 to sync::Once and thread_parking atomics cfg guards

When targeting `wasm64-unknown-unknown` with atomics enabled, `std::sync::Once` and `thread_parking` fall through to the `no_threads`/`unsupported` implementations because the cfg guards only check for `wasm32`. This causes worker threads to panic with `unreachable` at runtime. The underlying futex implementations already handle both wasm32 and wasm64 correctly, only the cfg guards were missing wasm64.

I tested this manually with a multithreaded wasm64 application ([o1js](https://github.com/o1-labs/o1js/)) compiled with `-Z build-std=panic_abort,std` and `-C target-feature=+atomics,+bulk-memory,+mutable-globals`

Related: rust-lang/rust#83879 rust-lang/rust#77839

Happy to adjust anything based on feedback
2026-03-06 18:49:47 +01:00
Florian 6a950e74b7 add wasm64 to sync::Once and thread_parking atomics cfg guard
Update library/std/src/sys/sync/once/mod.rs

Update library/std/src/sys/sync/thread_parking/mod.rs

Co-Authored-By: Taiki Endo <te316e89@gmail.com>
2026-03-06 13:15:05 +03:00
joboet 6f980d4cbf std: use OnceLock for Xous environment variables 2026-03-05 19:59:15 +01:00
Jonathan Brouwer ed9d77216f Rollup merge of #153204 - xtqqczze:must-use-map, r=Amanieu,joboet
Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors

- `new_in`
- `with_capacity_and_hasher`
- `with_capacity_and_hasher_in`
- `with_hasher`
- `with_hasher_in`

See also: https://github.com/rust-lang/rust/issues/89692
2026-03-04 19:30:37 +01:00
Jonathan Brouwer 5ff104c0b2 Rollup merge of #153196 - MikkelPaulson:const-path-separators, r=joboet
Update path separators to be available in const context

Tracking issue: rust-lang/rust#153106

This makes platform-dependent secondary path separators available in const context (ie. at compile time). The platform definitions have also been consolidated behind a common macro to prevent transcription errors, whereas previously they were defined 3-4 times per platform.

### Questions

I've manually verified that this compiles against each platform. It seems like no unit tests should be required for this change; is that correct?
2026-03-04 19:30:37 +01:00
Jonathan Brouwer 1c44dbd580 Rollup merge of #152164 - mu001999-contrib:lint/unused_features, r=JonathanBrouwer
Lint unused features

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152164)*

Fixes rust-lang/rust#44232
Fixes rust-lang/rust#151752

---

This PR records used features through query side effect, then reports unsued features finally.
2026-03-04 19:30:36 +01:00
Mikkel Paulson 098b1b98f5 make path separators available in const context
* consolidate various representations of separators in std::sys::path
  into a single macro_rules invocation per platform to save
  transcription errors
* make `std::path::is_separator()` const
* new constants `std::path::{SEPARATORS, SEPARATORS_STR}`
2026-03-04 12:03:06 -05:00
joboet d31aecff6a std: reorganize some WASI helpers 2026-03-04 16:56:29 +01:00
joboet 866975f8a8 std: move SOLID error converting out of pal::os 2026-03-04 16:20:05 +01:00
joboet 390f683cfc std: move non-path functions into dedicated module in PAL 2026-03-04 16:20:05 +01:00
Mikkel Paulson 72de815eb2 reference local MAIN_SEPARATOR_STR
Change reference to imported MAIN_SEP_STR to local MAIN_SEPARATOR_STR,
removing an unnecessary import.
2026-03-04 10:01:43 -05:00
Matthias Krüger d70f5bdcca Rollup merge of #153341 - joboet:xous_params, r=tgross35
std: refactor Xous startup code

To facilitate rust-lang/rust#117276 I'm moving all non-path-related code out of `sys::pal::os` (see also rust-lang/rust#153130). This is particularly involved for Xous as `pal::os` also contains the `_start` entry function and the parameter block handling. This PR moves both out into the main `sys::pal` module and also simplifies the parameter block initialisation code slightly.

CC @xobs
2026-03-04 09:49:01 +01:00
Stuart Cook 49966fedd6 Rollup merge of #153295 - biscuitrescue:fix-panicking-docs, r=tgross35
update panicking() docs for panic=abort

fixes rust-lang/rust#151458

The documentation for `std::thread::panicking()` has not been changed since v1.0, even though panic hooks were added in v1.10.
Current documentation is misleading for `panic=abort`

`panicking()` can return `true` in 2 different cases:
1. Thread unwinds due to panic
2. Panic hook is executing with `panic=abort`

r? @SpriteOvO
2026-03-04 11:54:11 +11:00
Stuart Cook b5f3ca196a Rollup merge of #153272 - wmmc88:add-path-absolute-method, r=tgross35
Add `Path::absolute` method as alias for `std::path::absolute`

`Path::canonicalize()` is an alias for `fs::canonicalize()`, but there's no equivalent `Path::absolute()` for `path::absolute()`. This adds one.

Discussed in https://github.com/rust-lang/rust/issues/92750#issuecomment-2867636150, Chris [said](https://github.com/rust-lang/rust/issues/92750#issuecomment-2904002333) a PR would be welcome.

Tracking issue: rust-lang/rust#153328
2026-03-04 11:54:10 +11:00
mu001999 7ffaa41662 Remove unused features in library tests 2026-03-04 08:06:44 +08:00
biscuitrescue 014344b0c3 update panicking() docs for panic=abort
rephrasing and grammar
2026-03-04 01:38:06 +05:30
Melvin Wang bde5b584a6 Add Path::absolute method as alias for path::absolute
Add a convenience method Path::absolute() that delegates to the
existing free function std::path::absolute(), mirroring the pattern of
Path::canonicalize() delegating to fs::canonicalize().

Tracking issue: https://github.com/rust-lang/rust/issues/153328
2026-03-03 10:40:19 -08:00
Jonathan Brouwer f3f04699c1 Rollup merge of #153319 - DanielEScherzer:ie-dots, r=jhpratt
Comments and docs: add missing periods to "ie."

"i.e." is short for the Latin "id est" and thus both letters should be followed by periods.
2026-03-03 13:08:45 +01:00
joboet a598ccfc38 std: refactor Xous startup code 2026-03-03 12:26:21 +01:00
Jonathan Brouwer 8845cc0c67 Rollup merge of #153297 - Gelbpunkt:hermitcore-hermit, r=joboet
Update the name of the Hermit operating system

The HermitCore name was dropped a while ago, the project is now simply called "Hermit". See for example [the website](https://hermit-os.org/).

cc @stlankes @mkroening
2026-03-03 07:14:17 +01:00
Daniel Scherzer 158ac1a10b Comments and docs: add missing periods to "ie."
"i.e." is short for the Latin "id est" and thus both letters should be followed
by periods.
2026-03-02 18:11:13 -08:00
Aelin Reidel cc64a37912 library: std: hermit: Update name of the Hermit operating system
The HermitCore name was dropped a while ago, the project is now simply
called "Hermit".
2026-03-02 17:26:44 +01:00
Aelin Reidel f1a4d0cd37 library: std: process: skip tests on Hermit
Hermit does not yet support spawning processes.
2026-03-02 15:50:41 +01:00
Jonathan Brouwer 3bbbcbac91 Rollup merge of #153246 - vexide:fix/fs-dir, r=joboet
Fix compile error in std::fs impl on VEXos target

This PR fixes a compile error in the standard library on the `armv7a-vex-v5` target that was caused by there not being a version of the `Dir` struct exported from `std::sys::fs::vexos`. Reading from directories isn't supported on this platform, so the module now re-exports the unsupported version of `Dir`.
2026-03-01 17:43:42 +01:00
Jonathan Brouwer ad896d3457 Rollup merge of #153130 - joboet:move_getpid_sys_process, r=Mark-Simulacrum
std: move `getpid` to `sys::process`

Part of rust-lang/rust#117276.

Availability of process IDs is highly correlated with availability of processes, so moving the `getpid` implementations to `sys::process` makes a lot of sense (and removes quite some code duplication). The only notable change here is on Hermit, which doesn't have processes but does have `getpid`. But that [always returns 0](https://github.com/hermit-os/kernel/blob/ef27b798856b50d562a42c4ffd2edcb7493c5b5f/src/syscalls/tasks.rs#L21), so I doubt it is useful. If the change to a panic is problematic we could always copy the stub implementation and return zero ourselves (this also applies to the other single-process platforms).

CC @stlankes @mkroening
2026-03-01 17:43:40 +01:00
Lewis McClelland 04f6a493e4 Re-export unsupported Dir from fs impl on vexos 2026-03-01 01:19:04 -05:00
Jonathan Brouwer 0425a45c89 Rollup merge of #153054 - shri-prakhar:docs-temp-dir-env-vars, r=Mark-Simulacrum
docs: note env var influence on `temp_dir` and `env_clear` on Windows

On Windows, `env::temp_dir()` internally calls `GetTempPath2`/`GetTempPath`,
which checks the `TMP`, `TEMP`, and `USERPROFILE` environment variables in
order before falling back to the Windows directory. This lookup order was
previously only discoverable by following links to Microsoft documentation.

This PR documents the env var lookup order directly in `env::temp_dir` docs
and notes `GetTempPath2`'s SYSTEM-identity behavior (`C:\Windows\SystemTemp`).

Addresses rust-lang/rust#125439.
2026-02-28 19:55:51 +01:00
Jonathan Brouwer 5cf9a7f045 Rollup merge of #153052 - DanielEScherzer:patch-2, r=joboet
std random.rs: update link to RTEMS docs

The old URL with `master` resulted in a 404 error - use `main` instead.
2026-02-28 19:55:51 +01:00
Jonathan Brouwer 435be5b8b8 Rollup merge of #151991 - Ayush1325:uefi-split-path, r=joboet
std: sys: pal: uefi: os: Implement split_paths

- Tested using OVMF on QEMU

@rustbot label +O-UEFI
cc @nicholasbishop
2026-02-28 19:55:50 +01:00
LevitatingBusinessMan (Rein Fernhout) feef7b4eaf warn of possible race condition in channel is_disconnected doc 2026-02-28 19:52:50 +01:00
shri-prakhar 220295beef docs: note env var influence on temp_dir and env_clear on Windows
* docs: explicitly list env vars checked by temp_dir on Windows

On Windows, temp_dir() internally calls GetTempPath2/GetTempPath which
checks TMP, TEMP, USERPROFILE environment variables in order. This
information was previously only available by following links to Microsoft
docs. Making it explicit in Rust's own documentation improves
discoverability.

Addresses #125439.
* docs: note env var influence on temp_dir and env_clear on Windows

On Windows, nv::temp_dir() internally calls GetTempPath2/GetTempPath,
which checks TMP, TEMP, and USERPROFILE in order. Document this
lookup order directly in the 	emp_dir docs rather than requiring users
to follow the link to Microsoft documentation.

Also add a note on Command::env_clear explaining that clearing the
environment affects the child process's 	emp_dir(), not the parent's.

Closes #125439.
* docs: drop Windows env_clear temp_dir note
2026-02-28 16:29:48 +00:00
Jonathan Brouwer 1acf1c5367 Rollup merge of #152730 - BennoLossin:field-projections-lang-item, r=oli-obk
add field representing types

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152730)*

> [!NOTE]
> This is a rewrite of #146307 by using a lang item instead of a custom `TyKind`. We still need a `hir::TyKind::FieldOf` variant, because resolving the field name cannot be done before HIR construction. The advantage of doing it this way is that we don't need to make any changes to types after HIR (including symbol mangling). At the very beginning of this feature implementation, I tried to do it using a lang item, but then quickly abandoned the approach, because at that time I was still intending to support nested fields.

Here is a [range-diff](https://triagebot.infra.rust-lang.org/gh-range-diff/rust-lang/rust/605f49b27444a738ea4032cb77e3bdc4eb811bab..d15f5052095b3549111854a2555dd7026b0a729e/605f49b27444a738ea4032cb77e3bdc4eb811bab..f5f42d1e03495dbaa23671c46b15fccddeb3492f) between the two PRs

---

# Add Field Representing Types (FRTs)

This PR implements the first step of the field projection lang experiment (Tracking Issue: rust-lang/rust#145383). Field representing types (FRTs) are a new kind of type. They can be named through the use of the `field_of!` macro with the first argument being the type and the second the name of the field (or variant and field in the case of an enum). No nested fields are supported.

FRTs natively implement the `Field` trait that's also added in this PR. It exposes information about the field such as the type of the field, the type of the base (i.e. the type that contains the field) and the offset within that base type. Only fields of non-packed structs are supported, fields of enums an unions have unique types for each field, but those do not implement the `Field` trait.

This PR was created in collaboration with @dingxiangfei2009, it wouldn't have been possible without him, so huge thanks for mentoring me!

I updated my library solution for field projections to use the FRTs from `core` instead of creating my own using the hash of the name of the field. See the [Rust-for-Linux/field-projection `lang-experiment` branch](https://github.com/Rust-for-Linux/field-projection/tree/lang-experiment).

## API added to `core::field`

```rust
pub unsafe trait Field {
    type Base;

    type Type;

    const OFFSET: usize;
}

pub macro field_of($Container:ty, $($fields:expr)+ $(,)?);
```

Along with a perma-unstable type that the compiler uses in the expansion of the macro:

```rust
#[unstable(feature = "field_representing_type_raw", issue = "none")]
pub struct FieldRepresentingType<T: ?Sized, const VARIANT: u32, const FIELD: u32> {
    _phantom: PhantomData<T>,
}
```

## Explanation of Field Representing Types (FRTs)

FRTs are used for compile-time & trait-level reflection for fields of structs & tuples. Each struct & tuple has a unique compiler-generated type nameable through the `field_of!` macro. This type natively contains information about the field such as the outermost container, type of the field and its offset. Users may implement additional traits on these types in order to record custom information (for example a crate may define a [`PinnableField` trait](https://github.com/Rust-for-Linux/field-projection/blob/lang-experiment/src/marker.rs#L9-L23) that records whether the field is structurally pinned).

They are the foundation of field projections, a general operation that's generic over the fields of a struct. This genericism needs to be expressible in the trait system. FRTs make this possible, since an operation generic over fields can just be a function with a generic parameter `F: Field`.

> [!NOTE]
> The approach of field projections has changed considerably since this PR was opened. In the end we might not need FRTs, so this API is highly experimental.

FRTs should act as though they were defined as `struct MyStruct_my_field<StructGenerics>;` next to the struct. So it should be local to the crate defining the struct so that one can implement any trait for the FRT from that crate. The `Field` traits should be implemented by the compiler & populated with correct information (`unsafe` code needs to be able to rely on them being correct).

## TODOs

There are some `FIXME(FRTs)` scattered around the code:
- Diagnostics for `field_of!` can be improved
  - `tests/ui/field_representing_types/nonexistent.rs`
  - `tests/ui/field_representing_types/non-struct.rs`
  - `tests/ui/field_representing_types/offset.rs`
  - `tests/ui/field_representing_types/not-field-if-packed.rs`
  - `tests/ui/field_representing_types/invalid.rs`
- Simple type alias already seem to work, but might need some extra work in `compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs`

r? @oli-obk
2026-02-28 12:52:52 +01:00
xtqqczze dda4f84c56 Add #[must_use] attribute to HashMap and HashSet constructors 2026-02-28 01:22:45 +00:00
xtqqczze 3ecd18ca37 std: make OsString::truncate a no-op when len > current_len
Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`.

Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op.
2026-02-27 18:49:45 +00:00