Commit Graph

18461 Commits

Author SHA1 Message Date
Michael Goulet
74e5366020
Rollup merge of #137543 - petrochenkov:wintest, r=ChrisDenton
std: Fix another new symlink test on Windows

Checking for `got_symlink_permission` first is a standard procedure for such tests.
2025-02-24 19:21:48 -05:00
Michael Goulet
8f729e9cff
Rollup merge of #137489 - RalfJung:no-more-rustc_intrinsic_must_be_overridden, r=oli-obk
remove `#[rustc_intrinsic_must_be_overridde]`

In https://github.com/rust-lang/rust/pull/135031, we gained support for just leaving away the body. Now that the bootstrap compiler got bumped, stop using the old style and remove support for it.

r? `@oli-obk`

There are a few more mentions of this attribute in RA code that I didn't touch; Cc `@rust-lang/rust-analyzer`
2025-02-24 19:21:47 -05:00
Michael Goulet
1cd083d73f
Rollup merge of #137321 - aviraxp:patch-1, r=cuviper
Correct doc about `temp_dir()` behavior on Android

Since commit d5ccb038f6, `TMPDIR` will be set to application's cache dir when app starts.
2025-02-24 19:21:46 -05:00
Trevor Gross
91dc3eed50
Rollup merge of #137516 - RalfJung:rustc_const_unstable-cleanup, r=Amanieu
remove some unnecessary rustc_const_unstable

If the function is anyway unstable, it doesn't need to be `rustc_const_unstable`.

`copy_from_slice` turns out to not do anything const-unstable itself, we just haven't stably committed to it being available in const yet. See [here](https://rustc-dev-guide.rust-lang.org/stability.html?highlight=rustc_const_stable_indirect) for more details on the `rustc_const_stable_indirect` attribute.
2025-02-24 18:46:37 -05:00
Trevor Gross
50940109cc
Rollup merge of #137349 - thaliaarchi:io-optional-methods/zkvm, r=Noratrieb
Implement `read_buf` for zkVM stdin

For the zkVM, even when a guest buffer is uninitialized, from the host's perspective it is just a normal piece of memory which was initialized before letting the guest write into it. This makes `sys_read` safe to use with an uninitialized buffer. See https://github.com/risc0/risc0/issues/2853.

cc `@bobbobbio,` `@flaub`

r? `@Noratrieb`

Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-24 18:46:36 -05:00
Trevor Gross
57ce16ca27
Rollup merge of #137109 - bend-n:knife, r=oli-obk
stabilize extract_if

Tracking issue: #43244
Closes: #43244
FCP completed: https://github.com/rust-lang/rust/issues/43244#issuecomment-2523595704
2025-02-24 18:46:35 -05:00
Trevor Gross
03326daf23
Rollup merge of #136775 - robertbastian:patch-2, r=Amanieu
Update `String::from_raw_parts` safety requirements

These have become out of sync with `Vec::from_raw_part`'s safety requirements, and are likely to diverge again. I think it's safest to just point at `Vec`'s requirements.

https://github.com/rust-lang/rust/issues/119206#issuecomment-2180116680
2025-02-24 18:46:35 -05:00
Trevor Gross
fe2876fcba
Rollup merge of #136668 - WaffleLapkin:from_utf8_mut, r=Amanieu
Stabilize `core::str::from_utf8_mut` as `const`

cc #91006 (tracking issue)

r? libs-api
2025-02-24 18:46:34 -05:00
Trevor Gross
dc2b86feb8
Rollup merge of #135933 - hkBst:patch-19, r=workingjubilee
Explain how Vec::with_capacity is faithful

This is a revival of https://github.com/rust-lang/rust/pull/99790 building on the prose of `@workingjubilee` and edits of `@jmaargh.` Closes https://github.com/rust-lang/rust/issues/99385.
2025-02-24 18:46:34 -05:00
Trevor Gross
23e113200d
Rollup merge of #134655 - GrigorenkoPV:hash_extract_if, r=cuviper
Stabilize `hash_extract_if`

FCP complete: https://github.com/rust-lang/rust/issues/59618#issuecomment-2674880530

Tracking issue: #59618
Closes #59618
2025-02-24 18:46:33 -05:00
Alona Enraght-Moony
78615ff2ae Stablize string_extend_from_within 2025-02-24 23:34:46 +00:00
Michael Goulet
5c5ed92c37 Simplify trait error message for CoercePointee validation 2025-02-24 19:34:54 +00:00
David Wood
d6bb98e757
span: add a "future" edition
It's hard to implement edition migrations without having a perma-unstable
"future" edition to target.
2025-02-24 14:35:30 +00:00
Vadim Petrochenkov
9c65672397 std: Fix another new symlink test on Windows 2025-02-24 17:12:37 +03:00
Robert Bastian
562880cfd9
Update string.rs
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-02-24 10:02:55 +01:00
Mahmoud Mazouz
1ccdc06136
Remove speculation on cause of error
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-02-24 09:50:46 +01:00
Ralf Jung
68543abb45 remove some unnecessary rustc_const_unstable 2025-02-24 08:54:53 +01:00
Trevor Gross
fb5f804f52 Update compiler-builtins to 0.1.148
Includes `f16` symbols on MIPS [1], updates for `libm` [2], and
reapplies the patch that drops the `public_test_deps!` macro [3].

[1]: https://github.com/rust-lang/compiler-builtins/pull/762
[2]: https://github.com/rust-lang/compiler-builtins/pull/765
[3]: https://github.com/rust-lang/compiler-builtins/pull/766
2025-02-24 07:46:55 +00:00
Jacob Pratt
3a1549ca8e
Rollup merge of #137495 - madhav-madhusoodanan:feature-unstable-control-flow-into-value, r=jhpratt
Added into_value function to ControlFlow<T, T>
2025-02-24 02:11:36 -05:00
Jacob Pratt
8a8c0e25c9
Rollup merge of #137484 - chenyukang:yukang-fix-sort-doc, r=Noratrieb
Fix documentation for unstable sort on slice

Fixes #136665
2025-02-24 02:11:35 -05:00
Jacob Pratt
56fca2638f
Rollup merge of #137482 - rust9x:win-file-open-truncate, r=ChrisDenton
Windows: use existing wrappers in `File::open_native`

Just a small improvement I've noticed - prevents accidents regarding `SetFileInformationByHandle` parameters.

Probably ``@ChrisDenton`` since we talked about it on discord :)
2025-02-24 02:11:34 -05:00
Jacob Pratt
31640178bd
Rollup merge of #137393 - chorman0773:unbounded-shifts-stabilize, r=Amanieu
Stabilize `unbounded_shifts`

This stabilizes and const-stabilizes `<iN>::unbounded_shl` and `<uN>::unbounded_shr` from https://github.com/rust-lang/rust/issues/129375.
2025-02-24 02:11:34 -05:00
Jacob Pratt
b7f11ef362
Rollup merge of #137061 - progressive-galib:gen_future-closing#76249, r=ibraheemdev
Unstable `gen_future` Feature Tracking

This PR removes the reference to the closed tracking issue **#50547** for the `gen_future` feature. Since `gen_future` is an internal feature used in async block desugaring, it does not require a public tracking issue.

#### Changes:
- Replaced `issue = "50547"` with `issue = "none"` in **library/core/src/future/mod.rs**.
- Ensures that it is correctly identified as an internal feature.

#### Rationale:
With this change, the Unstable Book will now state:
> *"This feature has no tracking issue and is therefore likely internal to the compiler, not being intended for general use."*

Closes **#76249**. 🚀🦀
2025-02-24 02:11:33 -05:00
Ralf Jung
5a58a922e2 remove uses of rustc_intrinsic_must_be_overridden from standard library 2025-02-24 07:53:57 +01:00
Madhav Madhusoodanan
f49b6c6cd5 Added into_value const function to ControlFlow<T, T>
Fixed issue with usage of generics and moved feature gate to crate root

Removed const tag

Fixed alphabetical ordering of feature gate, added same to doctest

Removed crate-level declaration of feature gate control_flow_into_value

Used const_precise_live_drops to constify into_value without issue of a drop
2025-02-24 07:36:27 +05:30
Trevor Gross
18ffee2126
Rollup merge of #137483 - bend-n:😅, r=Noratrieb
rename sub_ptr to offset_from_unsigned

i also made `byte_sub_ptr` `byte_offset_from_unsigned`

fixes #137121
tracking issue #95892
2025-02-23 14:30:28 -05:00
Trevor Gross
fb54acd700
Rollup merge of #137297 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.147

Removes an ABI hack that used `<2 x i64>` to return `i128` in `xmm0` on Windows [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/759
Link: https://github.com/rust-lang/rust/issues/116558
Link: https://github.com/rust-lang/compiler-builtins/issues/758

try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
2025-02-23 14:30:27 -05:00
Trevor Gross
a2bb4d748d
Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35
intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic

LLVM has three intrinsics here that all do the same thing (when used in the default FP environment). There's no reason Rust needs to copy that historically-grown mess -- let's just have one intrinsic and leave it up to the LLVM backend to decide how to lower that.

Suggested by `@hanna-kruppe` in https://github.com/rust-lang/rust/issues/136459; Cc `@tgross35`

try-job: test-various
2025-02-23 14:30:25 -05:00
bendn
c813d8f3e4
rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
yukang
1a440d56d6 Fix documentation for unstable sort 2025-02-23 22:29:53 +08:00
Waffle Lapkin
bf3ed81c20
Stabilize core::str::from_utf8_mut 2025-02-23 15:16:26 +01:00
bendn
c39f33baae
stabilize extract_if 2025-02-23 21:11:12 +07:00
Dennis Duda
87c0380799 Win: use existing wrappers for SetFileInformationByHandle in File::open_native 2025-02-23 14:19:58 +01:00
Mahmoud Mazouz
db1f0d0458
Return error on unexpected termination in Thread::join.
There is a time window during which the OS can terminate a thread before stdlib
can retreive its `Packet`. Currently the `Thread::join` panics with no message
in such an event, which makes debugging difficult; fixes #124466.
2025-02-23 12:26:16 +01:00
bors
b880760977 Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrum
Master bootstrap update

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday

r? `@Mark-Simulacrum`
2025-02-23 11:12:56 +00:00
Ralf Jung
b9d0555d11 add stdarch compatibility hack 2025-02-23 11:53:49 +01:00
Jacob Pratt
2ff53a293e
Rollup merge of #137194 - kornelski:ftls, r=tgross35
More const {} init in thread_local

`const {}` in `thread_local!` gets an optimization just based on the syntax, rather than the expression being const-compatible. This is easy to miss, so I've added more examples to the docs.

I've also added `const {}` in a couple of places in std where this optimization has been missed.
2025-02-23 02:44:17 -05:00
Jacob Pratt
4493159b35
Rollup merge of #136826 - xizheyin:issue-136737, r=thomcc
Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in Unix

As discussion in #136737.

- Replace `mem::zeroed()` with `MaybeUninit::uninit()` for `sockaddr_storage` in `accept()` and `recvfrom()` since these functions fill in the address structure
- Replace `mem::zeroed()` with `MaybeUninit::uninit()` for `pthread_attr_t` in thread-related functions since `pthread_attr_init()` initializes the structure
- Add references to man pages to document this behavior
2025-02-23 02:44:16 -05:00
Rain
b340545114 [illumos] attempt to use posix_spawn to spawn processes
illumos has `posix_spawn`, and the very newest versions also have `_addchdir`,
so use that.

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-02-23 06:49:59 +00:00
Trevor Gross
08f1086bf0 Update compiler-builtins to 0.1.147
Removes an ABI hack that used `<2 x i64>` to return `i128` in `xmm0` on
Windows [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/759
Link: https://github.com/rust-lang/rust/issues/116558
Link: https://github.com/rust-lang/compiler-builtins/issues/758
2025-02-23 06:13:09 +00:00
Matthias Krüger
88ed69c035
Rollup merge of #137383 - folkertdev:stabilize-unsigned-is-multiple-of, r=Noratrieb
stabilize `unsigned_is_multiple_of`

tracking issue: https://github.com/rust-lang/rust/issues/128101
fcp completed in: https://github.com/rust-lang/rust/issues/128101#issuecomment-2674880635

### Public API

A version of this for all the unsigned types

```rust
fn is_multiple_of(lhs: u64, rhs: u64) -> bool {
    match rhs {
        // prevent division by zero
        0 => lhs == 0,
        _ => lhs % rhs == 0,
    }
}
```
2025-02-23 00:16:20 +01:00
Matthias Krüger
929423a4f0
Rollup merge of #137121 - bend-n:master, r=Noratrieb
stabilize `(const_)ptr_sub_ptr`

Tracking issue: #95892
Closes #95892
FCP Completed: https://github.com/rust-lang/rust/issues/95892#issuecomment-2561139730

r? ````@Noratrieb````
2025-02-23 00:16:18 +01:00
Matthias Krüger
1610bfb6af
Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3
Inject `compiler_builtins` during postprocessing and ensure it is made private

Follow up of https://github.com/rust-lang/rust/pull/135278

Do the following:

* Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST
* Do not make dependencies of `std` private by default (this was added in #135278)
* Make sure sysroot crates correctly mark their dependencies private/public
* Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified
* Do the `compiler_builtins` update that has been blocked on this

There is more detail in the commit messages. This includes the changes I was working on in https://github.com/rust-lang/rust/pull/136226.

try-job: test-various
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
try-job: i686-mingw-1
try-job: i686-mingw-2
2025-02-23 00:16:18 +01:00
Ralf Jung
d1b34acb3b make the new intrinsics safe 2025-02-22 14:12:55 +01:00
Matthias Krüger
d3e46d2e72
Rollup merge of #137388 - PaulDance:disable-rename-posix-semantics-tests-under-win7, r=ChrisDenton
Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7

Would otherwise fail there. The Windows7-specific parts were left pretty much untouched by the changes introduced by
51df98ddb0, so it is expected that these tests fail under Windows 7 as they were probably written to run under Windows 10+ only.
2025-02-22 11:36:46 +01:00
Matthias Krüger
1df3a35bca
Rollup merge of #136910 - okaneco:sig_ones, r=thomcc
Implement feature `isolate_most_least_significant_one` for integer types

Accepted ACP - https://github.com/rust-lang/libs-team/issues/467
Tracking issue - #136909

Implement ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and `NonZero` integers.

Add function `isolate_most_significant_one`
Add function `isolate_least_significant_one`

---

This PR adds the following impls
```rust
impl {u8, u16, u32, u64, u128, usize} {
    const fn isolate_most_significant_one(self) -> Self;
    const fn isolate_least_significant_one(self) -> Self;
}
impl {i8, i16, i32, i64, i128, isize} {
    const fn isolate_most_significant_one(self) -> Self;
    const fn isolate_least_significant_one(self) -> Self;
}
impl NonZeroT {
    const fn isolate_most_significant_one(self) -> Self;
    const fn isolate_least_significant_one(self) -> Self;
}
```
Example behavior
```rust
assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000);
assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100);
```
2025-02-22 11:36:42 +01:00
Matthias Krüger
5400270279
Rollup merge of #137207 - petertodd:2025-add-track-caller-to-duration-div, r=jhpratt
Add #[track_caller] to Duration Div impl

Previously the location of the divide-by-zero error condition would be attributed to the code in the rust standard library, eg:

	thread 'main' panicked at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/time.rs:1172:31:
	divide by zero error when dividing duration by scalar

With #[track_caller] the error is correctly attributed to the callee.
2025-02-22 01:01:40 +01:00
bors
794c12416b Auto merge of #137397 - matthiaskrgr:rollup-ls2pilo, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #132876 (rustdoc book: acknowledge --document-hidden-items)
 - #136148 (Optionally add type names to `TypeId`s.)
 - #136609 (libcore/net: `IpAddr::as_octets()`)
 - #137336 (Stabilise `os_str_display`)
 - #137350 (Move methods from Map to TyCtxt, part 3.)
 - #137353 (Implement `read_buf` for WASI stdin)
 - #137361 (Refactor `OperandRef::extract_field` to prep for MCP838)
 - #137367 (Do not exempt nonexistent platforms from platform policy)
 - #137374 (Stacker now handles miri using a noop impl itself)
 - #137392 (remove few unused fields)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-21 19:57:50 +00:00
Paul Mabileau
6ed53a624b
Fix(lib/fs/tests): Disable rename POSIX semantics FS tests under Windows 7
Would otherwise fail there. The Windows7-specific parts were left pretty
much untouched by the changes introduced by
51df98ddb0, so it is expected that these
tests fail under Windows 7 as they were probably written to run under
Windows 10+ only.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-02-21 20:49:04 +01:00
Connor Horman
f1c21c9fc6 Fix unbounded_shifts tests 2025-02-21 18:13:30 +00:00
Matthias Krüger
ef14e9a6d0
Rollup merge of #137353 - thaliaarchi:io-optional-methods/wasi-stdin, r=alexcrichton
Implement `read_buf` for WASI stdin

`WasiFd::read_buf` already exists. Simply use it in `Stdin`.

cc `@alexcrichton`

Tracked in https://github.com/rust-lang/rust/issues/136756
2025-02-21 19:01:15 +01:00
Matthias Krüger
2dc7573edd
Rollup merge of #137336 - riverbl:stabilise-os-str-display, r=tgross35
Stabilise `os_str_display`

Closes #120048.
2025-02-21 19:01:14 +01:00
Matthias Krüger
4aa973b3e4
Rollup merge of #136609 - mammothbane:master, r=scottmcm
libcore/net: `IpAddr::as_octets()`

[ACP](https://github.com/rust-lang/libs-team/issues/535)
[Tracking issue](https://github.com/rust-lang/rust/issues/137259)

Adds `const` `core::net::IpAddr{,v4,v6}::as_octets()` methods to provide reference access to IP address contents.

The concrete usecase for me is allowing the `IpAddr` to provide an extended lifetime in contexts that want a `&[u8]`:

```rust
trait AddrSlice {
    fn addr_slice(&self) -> &[u8];
}

impl AddrSlice for IpAddrV4 {
    fn addr_slice(&self) -> &[u8] {
        // self.octets() doesn't help us here, because we can't return a reference to the owned array.
        // Instead we want the IpAddrV4 to continue owning the memory:
        self.as_octets()
    }
}
```

(Notably, in this case we can't parameterize `AddrSlice` by a `const N: usize` (such that `fn addr_slice(&self) -> [u8; N]`) and maintain object-safety.)
2025-02-21 19:01:13 +01:00
Matthias Krüger
28164f1229
Rollup merge of #136148 - kpreid:type-str, r=joboet
Optionally add type names to `TypeId`s.

This feature is intended to provide expensive but thorough help for developers who have an unexpected `TypeId` value and need to determine what type it actually is. It causes `impl Debug for TypeId` to print the type name in addition to the opaque ID hash, and in order to do so, adds a name field to `TypeId`. The cost of this is the increased size of `TypeId` and the need to store type names in the binary; therefore, it is an optional feature. It does not expose any new public API, only change the `Debug` implementation.

It may be enabled via `cargo -Zbuild-std -Zbuild-std-features=debug_typeid`. (Note that `-Zbuild-std-features` disables default features which you may wish to reenable in addition; see
<https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features>.)

Example usage and output:

```
fn main() {
    use std::any::{Any, TypeId};
    dbg!(TypeId::of::<usize>(), drop::<usize>.type_id());
}
```

```
TypeId::of::<usize>() = TypeId(0x763d199bccd319899208909ed1a860c6 = usize)
drop::<usize>.type_id() = TypeId(0xe6a34bd13f8c92dd47806da07b8cca9a = core::mem::drop<usize>)
```

Also added feature declarations for the existing `debug_refcell` feature so it is usable from the `rust.std-features` option of `config.toml`.

Related issues:

* #68379
* #61533
2025-02-21 19:01:12 +01:00
Trevor Gross
93925809eb Replace some instances of pub with pub(crate)
The recent fixes to private dependencies exposed some cases in the UEFI
module where private dependencies are exposed in a public interface.
These do not need to be crate-public, so change them to `pub(crate)`.
2025-02-21 17:37:03 +00:00
Trevor Gross
8c1b49d5e9 Use public-dependencies in all sysroot crates
In [1], most dependencies of `std` and other sysroot crates were marked
private, but this did not happen for `alloc` and `test`. Update these
here, marking public standard library crates as the only non-private
dependencies.

[1]: https://github.com/rust-lang/rust/pull/111076
2025-02-21 17:37:03 +00:00
Connor Horman
a3f389745e Stabilize unbounded_shifts 2025-02-21 16:58:37 +00:00
Folkert de Vries
ad962ed131
stabilize unsigned_is_multiple_of 2025-02-21 16:50:23 +01:00
bors
71e06b9c59 Auto merge of #137371 - matthiaskrgr:rollup-3qkdqar, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #128080 (Specify scope in `out_of_scope_macro_calls` lint)
 - #135630 (add more `s390x` target features)
 - #136089 (Reduce `Box::default` stack copies in debug mode)
 - #137204 (Clarify MIR dialects and phases)
 - #137299 (Simplify `Postorder` customization.)
 - #137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck)
 - #137305 (Tweaks in and around `rustc_middle`)
 - #137313 (Some codegen_llvm cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-21 14:56:04 +00:00
Marijn Schouten
fc02cfd1c0 Do not use CString in the examples of CStr.
Fixes #83999.
2025-02-21 14:39:34 +01:00
Kornel
4742dbc765
Use faster thread_local! for stdout 2025-02-21 13:09:16 +00:00
Kornel
ad566646cf
Use faster thread_local in current_thread_id() 2025-02-21 13:09:16 +00:00
Kornel
b94162078d
Highlight thread_local! const init in docs 2025-02-21 13:02:42 +00:00
Matthias Krüger
8d52aae968
Rollup merge of #136089 - jwong101:box-default-debug-stack-usage, r=Amanieu
Reduce `Box::default` stack copies in debug mode

The `Box::new(T::default())` implementation of `Box::default` only
had two stack copies in debug mode, compared to the current version,
which has four. By avoiding creating any `MaybeUninit<T>`'s and just writing
`T` directly to the `Box` pointer, the stack usage in debug mode remains
the same as the old version.

Another option would be to mark `Box::write` as `#[inline(always)]`,
and change it's implementation to to avoid calling `MaybeUninit::write`
(which creates a `MaybeUninit<T>` on the stack) and to use `ptr::write` instead.

Fixes: #136043
2025-02-21 12:45:22 +01:00
Marijn Schouten
da7210b17f Explain how Vec::with_capacity is faithful
Co-authored-by: Jubilee <workingjubilee@gmail.com> and jmaargh
2025-02-21 12:43:45 +01:00
bors
9f48dedc97 Auto merge of #137192 - kornelski:windows-tls-lto, r=ChrisDenton
Remove obsolete Windows ThinLTO+TLS workaround

The bug #109797 has been fixed by #129079, so this workaround is no longer needed.
2025-02-21 11:43:00 +00:00
Frank Steffahn
bf26f24423 Clarify/update comments in BufRead::read_line's default body
with where to *actually* look for more details
2025-02-21 03:56:49 +01:00
Thalia Archibald
d32eeb86b2 Implement read_buf for WASI stdin 2025-02-20 17:06:33 -07:00
Thalia Archibald
98b0f050cf Implement read_buf for zkVM stdin
For the zkVM, even when a guest buffer is uninitialized, from the host's
perspective it is just a normal piece of memory which was initialized
before letting the guest write into it. This makes `sys_read` safe to
use with an uninitialized buffer. See
https://github.com/risc0/risc0/issues/2853.
2025-02-20 16:07:12 -07:00
Jubilee
f24b140976
Rollup merge of #137270 - QianNangong:master, r=ChrisDenton
Fix `*-win7-windows-msvc` target since 26eeac1a1e

That commit make it failed to build `std` with `*-win7-windows-msvc` so fix it.
2025-02-20 14:58:18 -08:00
Jubilee
480a72d601
Rollup merge of #134340 - Urgau:stabilize-num_midpoint_signed, r=scottmcm
Stabilize `num_midpoint_signed` feature

This PR proposes that we stabilize the signed variants of [`iN::midpoint`](https://github.com/rust-lang/rust/issues/110840#issue-1684506201), the operation is equivalent to doing `(a + b) / 2` in a sufficiently large number.

The stabilized API surface would be:

```rust
/// Calculates the middle point of `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a
/// sufficiently-large signed integer type. This implies that the result is
/// always rounded towards zero and that no overflow will ever occur.

impl i{8,16,32,64,128,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}
```

T-libs-api previously stabilized the unsigned (and float) variants in #131784, the signed variants were left out because of the rounding that should be used in case of negative midpoint.

This stabilization proposal proposes that we round towards zero because:
 - it makes the obvious `(a + b) / 2` in a sufficiently-large number always true
   - using another rounding for the positive result would be inconsistent with the unsigned variants
 - it makes `midpoint(-a, -b)` == `-midpoint(a, b)` always true
 - it is consistent with `midpoint(a as f64, b as f64) as i64`
 - it makes it possible to always suggest `midpoint` as a replacement for `(a + b) / 2` expressions *(which we may want to do as a future work given the 21.2k hits on [GitHub Search](https://github.com/search?q=lang%3Arust+%2F%5C%28%5Ba-zA-Z_%5D*+%5C%2B+%5Ba-zA-Z_%5D*%5C%29+%5C%2F+2%2F&type=code&p=1))*

`@scottmcm` mentioned a drawback in https://github.com/rust-lang/rust/pull/132191#issuecomment-2439891200:
> I'm torn, because rounding towards zero makes it "wider" than other values, which `>> 1` avoids -- `(a + b) >> 1` has the nice behaviour that `midpoint(a, b) + 2 == midpoint(a + 2, b + 2)`.
>
> But I guess overall sticking with `(a + b) / 2` makes sense as well, and I do like the negation property 🤷

Which I think is outweigh by the advantages cited above.

Closes #110840
cc `@rust-lang/libs-api`
cc `@scottmcm`
r? `@dtolnay`
2025-02-20 14:58:16 -08:00
riverbl
5112ecb8ca Stabilise os_str_display 2025-02-20 19:12:06 +00:00
bors
f04bbc60f8 Auto merge of #136771 - scottmcm:poke-slice-iter-next, r=joboet
Simplify `slice::Iter::next` enough that it inlines

Inspired by this zulip conversation: <https://rust-lang.zulipchat.com/#narrow/channel/189540-t-compiler.2Fwg-mir-opt/topic/Feedback.20on.20a.20MIR.20optimization.20idea/near/498579990>

~~Draft for now because it needs #136735 to get the codegen tests to pass.~~
2025-02-20 18:20:40 +00:00
Arlo Siemsen
2c752bcf55 Undeprecate env::home_dir 2025-02-20 11:47:14 -06:00
Wang Han
0d4d752e83
Correct doc about temp_dir() behavior on Android
Since commit d5ccb038f6, `TMPDIR` will be set to application's cache dir when app starts.
2025-02-21 00:13:55 +08:00
Martin Nordholts
cf1242c461 Enable f16 for MIPS
It seems as if `f16` works on MIPS now according to my
testing on Rust master with LLVM 20, and I was asked to
create PRs with my changes.

I only tested on the flavour of `mipsel-unknown-linux-gnu`
hardware that happens to be available to me, so I can't say
anything about other MIPS hardware, but from a casual
skimming of the LLVM code ([1], [2]) it seems like `f16`
should work on all MIPS hardware. So enable it for all MIPS
hardware.

[1]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/Target/Mips/MipsISelLowering.h#L370
[2]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1367-L1388
2025-02-20 11:34:48 +01:00
okaneco
97bc99a18f Implement feature isolate_most_least_significant_one for integer types
Implement accepted ACP for functions that isolate the most significant
set bit and least significant set bit on unsigned, signed, and NonZero
integers.

Add function `isolate_most_significant_one`
Add function `isolate_least_significant_one`
Add tests
2025-02-20 05:19:06 -05:00
Peter Jaszkowiak
c293af9b57 add IntoBounds::intersect and RangeBounds::is_empty 2025-02-19 23:04:10 -07:00
Thalia Archibald
eb14652770 Skip scanning for surrogates when not known valid 2025-02-19 18:43:24 -08:00
Thalia Archibald
0842f2c65c Add fast path for displaying pre-validated Wtf8Buf 2025-02-19 18:43:24 -08:00
bors
6d3c050de8 Auto merge of #137295 - matthiaskrgr:rollup-tdu3t39, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135296 (interpret: adjust vtable validity check for higher-ranked types)
 - #137106 (Add customized compare for Link in rustdoc)
 - #137253 (Restrict `bevy_ecs` `ParamSet` hack)
 - #137262 (Make fewer crates depend on `rustc_ast_ir`)
 - #137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages)
 - #137266 (MIR visitor tweaks)
 - #137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions)
 - #137277 (stabilize `inherent_str_constructors`)
 - #137281 (Tweak "expected ident" parse error to avoid talking about doc comments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-20 02:39:28 +00:00
Matthias Krüger
be73ea82ce
Rollup merge of #137277 - m4rch3n1ng:stabilize-inherent-str-constructors, r=tgross35
stabilize `inherent_str_constructors`

fcp done in https://github.com/rust-lang/rust/issues/131114#issuecomment-2668859969.

tracking issue: #131114
closes: #131114
2025-02-20 00:55:16 +01:00
bors
4e1356b959 Auto merge of #137290 - matthiaskrgr:rollup-a7xdbi4, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #120580 (Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants)
 - #132268 (Impl TryFrom<Vec<u8>> for String)
 - #136093 (Match Ergonomics 2024: update old-edition behavior of feature gates)
 - #136344 (Suggest replacing `.` with `::` in more error diagnostics.)
 - #136690 (Use more explicit and reliable ptr select in sort impls)
 - #136815 (CI: Stop /msys64/bin from being prepended to PATH in msys2 shell)
 - #136923 (Lint `#[must_use]` attributes applied to methods in trait impls)
 - #137155 (Organize `OsString`/`OsStr` shims)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-19 23:29:37 +00:00
Matthias Krüger
3964bb131b
Rollup merge of #137155 - thaliaarchi:wtf8-organize, r=ChrisDenton
Organize `OsString`/`OsStr` shims

Synchronize the `bytes.rs` and `wtf8.rs` shims for `OsString`/`OsStr` so they're easier to diff between each other. This is mostly ordering items the same between the two. I tried to minimize moves and went for the average locations between the files.

With them in the same order, it is clear that `FromInner<_>` is not implemented for `bytes::Buf` and `Clone::clone_from` is not implemented for `wtf8::Buf`, but they are for the other. Fix that.

I added #[inline] to all inherent methods of the `OsString`/`OsStr` shims, because it seemed that was already the rough pattern. `bytes.rs` has more inlining than `wtf8.rs`, so I added the corresponding ones to `wtf8.rs`. Then, the common missing ones have no discernible pattern to me. They're not divided by non-allocating/allocating. Perhaps the pattern is that UTF-8 validation isn't inlined? Since these types are merely the inner values in `OsStr`/`OsString`, I put inline on all methods and let those public types dictate inlining. I have not inspected codegen or run benchmarks.

Also, touch up some (private) documentation comments.

r? ``````@ChrisDenton``````
2025-02-19 21:16:12 +01:00
Matthias Krüger
c29cc600fd
Rollup merge of #136923 - samueltardieu:push-vxxqvqwspssv, r=davidtwco
Lint `#[must_use]` attributes applied to methods in trait impls

The `#[must_use]` attribute has no effect when applied to methods in trait implementations. This PR adds it to the unused `#[must_use]` lint, and cleans the extra attributes in portable-simd and Clippy.
2025-02-19 21:16:11 +01:00
Matthias Krüger
59d2b102b4
Rollup merge of #136690 - Voultapher:use-more-explicit-and-reliable-ptr-select, r=thomcc
Use more explicit and reliable ptr select in sort impls

Using `if ...` with the intent to avoid branches can be surprising to readers and carries the risk of turning into jumps/branches generated by some future compiler version, breaking crucial optimizations.

This commit replaces their usage with the explicit and IR annotated `bool::select_unpredictable`.
2025-02-19 21:16:09 +01:00
Matthias Krüger
7b7b1d4ee9
Rollup merge of #132268 - elichai:string_try_from_vec, r=Amanieu
Impl TryFrom<Vec<u8>> for String

I think this is useful enough to have :)
As a general question, is there any policy around adding "missing" trait implementations? (like adding `AsRef<T> for T` for std types), I mostly stumble upon them when using a lot of "impl Trait in argument position" like (`foo: impl Into<String>`)
2025-02-19 21:16:02 +01:00
Matthias Krüger
84e9f29007
Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=m-ou-se
Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants

This pull request adds the `MAX_LEN_UTF8` and `MAX_LEN_UTF16` constants as per #45795, gated behind the `char_max_len` feature.

The constants are currently applied in the `alloc`, `core` and `std` libraries.
2025-02-19 21:16:01 +01:00
may
b24f77507f
stabilize inherent_str_constructors 2025-02-19 19:24:49 +01:00
Matthias Krüger
ce72b8d91e
Rollup merge of #136794 - cberner:stabilize, r=joshtriplett
Stabilize file_lock

Closes #130994
2025-02-19 18:52:06 +01:00
Matthias Krüger
e6406ad4dd
Rollup merge of #136347 - allevo:patch-1, r=Amanieu
Add a bullet point to `std::fs::copy`

I needed to copy a file but I got the following error:
```
Os { code: 2, kind: NotFound, message: "No such file or directory" }
```
After read the documentation, I though the error was generated by the `from` parameter, forgetting the `to` part. Anyway, I got the error because the parent folder of `to` didn't exist.
Even if the documentation explicitly saying `but is not limited to just these cases`, I would like to add this case because I spent 3 hours around it.

This PR just wants to put a mention about it.
2025-02-19 18:52:05 +01:00
Matthias Krüger
2c1e1bd2cb
Rollup merge of #136301 - hkBst:patch-33, r=thomcc
Improve instant docs

This should be enough to close #79881.
2025-02-19 18:52:04 +01:00
Matthias Krüger
2c380a4661
Rollup merge of #134995 - DaniPopes:stable-const_slice_flatten, r=Amanieu
Stabilize const_slice_flatten

Const-stabilizes `slice::as_flattened{,_mut}`:
```rust
// core::slice
impl<T, const N: usize> [[T; N]] {
    pub const fn as_flattened(&self) -> &[T];
    pub const fn as_flattened_mut(&mut self) -> &mut [T];
}
```

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

Requires separate FCP, as per https://github.com/rust-lang/rust/issues/95629#issuecomment-2566546257.

Closes https://github.com/rust-lang/rust/issues/95629.

`````@rustbot````` modify labels: +T-libs-api

Happy new year!
2025-02-19 18:52:03 +01:00
xizheyin
70f11ee0c0
fix by comments
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-19 20:16:28 +08:00
Li Keqing
35febd7a6d Fix *-win7-windows-msvc target since 26eeac1a1e 2025-02-19 18:05:37 +08:00
Tommaso Allevi
3ad847779e
Update library/std/src/fs.rs
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-02-19 09:17:18 +01:00
Nathan Perry
8fb888555f core/net: IpAddr*::as_octets()
Adds `const` `Ip*Addr::as_octets` methods providing reference access to
`Ip*Addr` octets contents.

See https://github.com/rust-lang/libs-team/issues/535 for accepted ACP
with a more detailed justification.
2025-02-19 00:50:46 -05:00
xizheyin
604364fcf4
remove assume_init in stack_overflow
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-19 13:20:03 +08:00
Matthias Krüger
e51fae58da
Rollup merge of #137228 - steffahn:one-coerces-to-supertypes-not-subtypes, r=the8472
Fix typo in hidden internal docs of `TrustedRandomAccess`

I typoed the coercion direction here 4 years ago; fixing it now
2025-02-19 01:30:14 +01:00
Matthias Krüger
38fba8ca96
Rollup merge of #137026 - GrigorenkoPV:integer_sign_cast, r=jhpratt
Stabilize (and const-stabilize) `integer_sign_cast`

Tracking issue: #125882
Closes: #125882
FCP completed: https://github.com/rust-lang/rust/issues/125882#issuecomment-2658274124
2025-02-19 01:30:10 +01:00
bors
f44efbf9e1 Auto merge of #137235 - matthiaskrgr:rollup-2kjua2t, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #135711 (Do not ICE on default_field_value const with lifetimes)
 - #136599 (librustdoc: more usages of `Joined::joined`)
 - #136876 (Locking documentation updates)
 - #137000 (Deeply normalize item bounds in new solver)
 - #137126 (fix docs for inherent str constructors)
 - #137161 (Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions)
 - #137191 (Update mdbook and move error_index_generator)
 - #137203 (Improve MIR modification)
 - #137206 (Make E0599 a structured error)
 - #137218 (misc `layout_of` cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-18 21:08:58 +00:00
Josh Stone
e61cac20c8 Remove outdated target unexpected_cfgs 2025-02-18 10:22:46 -08:00
许杰友 Jieyou Xu (Joe)
477a2eeb3d std::fs: slightly reformat remove_dir_all error docs
To make the error cases easier to spot on a quick glance.
2025-02-19 02:00:02 +08:00
Matthias Krüger
ac3b179c3b
Rollup merge of #137126 - m4rch3n1ng:fix-inherent-str-docs, r=Amanieu
fix docs for inherent str constructors

related to #131114

when implementing inherent str constructors in #136517, i forgot to change the docs, so the code examples still imported the `std::str` module and used the constructor from there, instead of using "itself" (the inherent constructor).
2025-02-18 18:40:52 +01:00
Matthias Krüger
5a942d67a6
Rollup merge of #136876 - joshtriplett:locking-might-not-be-advisory, r=Amanieu
Locking documentation updates

- Reword file lock documentation to clarify advisory vs mandatory. Remove the
  word "advisory", and make it more explicit that the lock may be advisory or
  mandatory depending on platform.

- Document that locking a file fails on Windows if the file is opened only for append
2025-02-18 18:40:50 +01:00
Urgau
b7c2da2231
Rollup merge of #137214 - cyrgani:clippy_diagnostic_items, r=compiler-errors
add last std diagnostic items for clippy

Part of https://github.com/rust-lang/rust-clippy/issues/5393.
Add diagnostic item attributes to the items in `std` and `core` where clippy currently uses hardcoded paths (https://github.com/rust-lang/rust-clippy/blob/master/clippy_utils/src/paths.rs).
2025-02-18 18:34:18 +01:00
Urgau
73e5abd175
Rollup merge of #137205 - thaliaarchi:remove-wasi-fileext-tell, r=alexcrichton
Remove `std::os::wasi::fs::FileExt::tell`

Following #137165 (Use `tell` for `<File as Seek>::stream_position`), `tell` is now directly exposed via `stream_position`, making `<File as FileExt>::tell` redundant. Remove it.

`std::os::wasi::fs::FileExt::tell` is currently unstable and tracked in https://github.com/rust-lang/rust/issues/71213.

``@rustbot`` ping wasi
2025-02-18 18:34:17 +01:00
Urgau
14fb84a5bb
Rollup merge of #137167 - martn3:reliable_f16_math-f16-erfc, r=tgross35
tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg

In #136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid:

    rust_out.71e2e529d20ea47d-cgu.0:\
    (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \
    undefined reference to `__gnu_h2f_ieee'

on MIPS (and maybe other architectures).

r? tgross35
2025-02-18 18:34:15 +01:00
Urgau
d7fe4c0e92
Rollup merge of #136750 - kornelski:ub-bug, r=saethlin
Make ub_check message clear that it's not an assert

I've seen a user assume that their unsound code was *safe*, because ub_check prevented the program from performing the unsafe operation.

This PR makes the panic message clearer that ub_check is a bug detector, not run-time safety protection.
2025-02-18 18:34:13 +01:00
Josh Stone
3c45324e67 update cfg(bootstrap) 2025-02-18 09:32:44 -08:00
Frank Steffahn
d93926cb5d Fix typo in hidden internal docs of TrustedRandomAccess
I typoed the coercion direction here 4 years ago; fixing it now
2025-02-18 17:54:56 +01:00
Josh Stone
fdba8a7c47 update version placeholders
(cherry picked from commit e4840ce59b)
2025-02-18 08:50:21 -08:00
Josh Triplett
ec2034d53d Reorder "This lock may be advisory or mandatory." earlier in the lock docs 2025-02-18 17:31:10 +01:00
Josh Triplett
35674eff6f Clarify that locking on Windows also works for files opened with .read(true) 2025-02-18 17:26:33 +01:00
cyrgani
a72402a0f9 add last std diagnostic items for clippy 2025-02-18 10:54:37 +01:00
Peter Todd
4e4cb10b84
Add #[track_caller] to Duration Div impl
Previously the location of the divide-by-zero error condition would be
attributed to the code in the rust standard library, eg:

	thread 'main' panicked at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/time.rs:1172:31:
	divide by zero error when dividing duration by scalar

With #[track_caller] the error is correctly attributed to the callee.
2025-02-18 04:56:03 +00:00
Thalia Archibald
d2f15971de Remove std::os::wasi::fs::FileExt::tell
Following #137165 (Use `tell` for `<File as Seek>::stream_position`),
`tell` is now directly exposed via `stream_position`, making
`<File as FileExt>::tell` redundant. Remove it.
2025-02-17 20:21:05 -08:00
Scott McMurray
3a3aedee10 Update some comparison tests now that they pass in LLVM20 2025-02-17 16:36:14 -08:00
Kornel
40ecda6a33
Remove obsolete MinGW ThinLTO+TLS workaround
#109797 is fixed
2025-02-17 22:10:25 +00:00
Matthias Krüger
10018d8e10
Rollup merge of #137165 - thaliaarchi:file-tell, r=ChrisDenton
Use `tell` for `<File as Seek>::stream_position`

Some platforms have a more efficient way to get the current offset of the file than by seeking. For example, Wasi has `fd_tell` and SOLID has `SOLID_FS_Ftell`. Implement `<File as Seek>::stream_position()` in terms of those.

I do not use any APIs that were not already used in `std`. Although, the `libc` crate has [`ftell`](https://docs.rs/libc/latest/libc/fn.ftell.html), [`ftello`](https://docs.rs/libc/latest/libc/fn.ftello.html), and [`ftello64`](https://docs.rs/libc/latest/libc/fn.ftello64.html), I do not know platform coverage. It appears that Windows has no `tell`-like API.

I have checked that it builds on each relevant platform.
2025-02-17 17:06:10 +01:00
Thalia Archibald
7112474134 Use tell for <File as Seek>::stream_position 2025-02-17 05:25:14 -08:00
bors
2162e9d4b1 Auto merge of #137164 - matthiaskrgr:rollup-dj5826k, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #137095 (Replace some u64 hashes with Hash64)
 - #137100 (HIR analysis: Remove unnecessary abstraction over list of clauses)
 - #137105 (Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.)
 - #137120 (Enable `relative-path-include-bytes-132203` rustdoc-ui test on Windows)
 - #137125 (Re-add missing empty lines in the releases notes)
 - #137145 (use add-core-stubs / minicore for a few more tests)
 - #137149 (Remove SSE ABI from i586-pc-windows-msvc)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-17 11:18:33 +00:00
Martin Nordholts
f6485ff617 tests: Also gate f16::erfc() doctest with reliable_f16_math cfg
In 136324 the doctest for `f16::erf()` was gated with
`reliable_f16_math`. Add the same gate on `f16::erfc()` to
avoid:

    rust_out.71e2e529d20ea47d-cgu.0:\
    (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \
    undefined reference to `__gnu_h2f_ieee'

on MIPS (and maybe other architectures).
2025-02-17 11:59:09 +01:00
Matthias Krüger
fae72a07dd
Rollup merge of #137105 - zachs18:cow-derefpure-restrict, r=Nadrieril
Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.

Fixes #136046

`feature(deref_patterns)` tracking issue: https://github.com/rust-lang/rust/issues/87121

`Cow<'_, T>` should only implement `DerefPure` if its `Deref` impl is pure, which requires `<T::Owned as Borrow<T>>::borrow`  to be pure. This PR restricts `impl DerefPure for Cow<'_, T>` to `T: Sized + Clone`, `T = [U: Clone]`, and `T = str` (for all of whom `<T::Owned as Borrow<T>>::borrow` is implemented in the stdlib and is pure).

cc ``@Nadrieril``

------

An alternate approach would be to introduce a new `unsafe trait BorrowPure<T>` analogous to `DerefPure`  that could be implemented for `T: Sized`, `&T`, `&mut T`, `String`, `Vec`, `Box`, `PathBuf`, `OsString`, etc. https://github.com/rust-lang/rust/compare/master...zachs18:borrow-pure-trait
2025-02-17 06:38:15 +01:00
Matthias Krüger
86f3d525e0
Rollup merge of #137101 - GrigorenkoPV:str-inherent-lint, r=Urgau
`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing https://github.com/rust-lang/rust/issues/131114#issuecomment-2646663535

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
2025-02-17 06:37:38 +01:00
Matthias Krüger
c04801dbb9
Rollup merge of #136844 - thaliaarchi:const-io-error, r=ChrisDenton
Use `const_error!` when possible

Replace usages of `io::Error::new(io::ErrorKind::Variant, "constant string")` with `io::const_error!(io::ErrorKind::Variant, "constant string")` to avoid allocations when possible. Additionally, fix `&&str` error messages in SGX and missing/misplaced trailing commas in `const_error!`.
2025-02-17 06:37:37 +01:00
bendn
92fd960ca4
stabilize (const_)ptr_sub_ptr 2025-02-17 10:07:27 +07:00
Thalia Archibald
05e4175d79 Synchronize platform adaptors for OsString/OsStr
* Order items as the average of the two adaptors. Enables easier diffs.
* Consistently apply #[inline].
* Implement FromInner<Vec<u8>> for bytes::Buf.
* Implement Clone::clone_from for wtf8::Buf.
2025-02-16 15:21:46 -08:00
Thalia Archibald
8b1a3a26c7 Simplify control flow with while-let 2025-02-16 15:19:08 -08:00
Thalia Archibald
09dc38f23b Improve WTF-8 comments 2025-02-16 14:43:31 -08:00
Matthias Krüger
f82764f2d9
Rollup merge of #137114 - ChrisDenton:error, r=Noratrieb
Add an example for `std::error::Error`

There is currently no example provided for `std::error::Error` so let's fix that.
2025-02-16 17:14:06 +01:00
Matthias Krüger
53b4c7c631
Rollup merge of #136986 - ehuss:library-unsafe-fun, r=Noratrieb
Apply unsafe_op_in_unsafe_fn to the standard library

This applies unsafe_op_in_unsafe_fn to the standard library in preparation for updating to Rust 2024.

Closes https://github.com/rust-lang/rust/issues/127747 (I think?) cc ``@workingjubilee``
I have been testing a variety of targets, and I feel like they are all pretty much covered. I'll continue doing some testing async, but I don't expect to catch any more.
2025-02-16 17:14:03 +01:00
Pavel Grigorenko
f53d0f502d invalid_from_utf8[_unchecked]: also lint inherent methods 2025-02-16 16:34:51 +03:00
HTGAzureX1212
eec49bbf59 add MAX_LEN_UTF8 and MAX_LEN_UTF16 constants 2025-02-16 21:08:38 +08:00
may
345c313def
fix docs for inherent str constructors 2025-02-16 12:02:06 +01:00
Chris Denton
f396a31075
Add an example for std::error::Error 2025-02-16 08:14:41 +00:00
Zachary S
0f220efb1a Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str. 2025-02-15 21:02:00 -06:00
Kornel
ca288273b4
Make ub_check message clear that it's not an assert 2025-02-16 00:56:09 +00:00
cyrgani
f0a6af0baa remove MaybeUninit::uninit_array 2025-02-15 23:36:01 +01:00
Michael Howell
4d551dd754 docs: fix broken intra-doc links that never worked 2025-02-15 12:21:38 -07:00
bors
8c07d140e0 Auto merge of #137065 - jhpratt:rollup-ree9mej, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #135687 (re-export `FromCoroutine` from `core::iter`)
 - #135813 (CI: split i686-mingw job to three free runners)
 - #136749 (Implement Extend<AsciiChar> for String)
 - #136879 (Add safe new() to NotAllOnes)
 - #136978 (Windows: Update generated bindings)
 - #137028 (mir_build: Clarify some code for lowering `hir::PatExpr` to THIR)
 - #137029 (Remove unnecessary check code in unused_delims)
 - #137056 (made check_argument_compat public for use in miri)
 - #137062 (Forward all default methods for I/O impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-15 07:52:03 +00:00
Jacob Pratt
ba89ea8add
Rollup merge of #137062 - thaliaarchi:io-optional-methods/write, r=workingjubilee
Forward all default methods for I/O impls

Forward all default methods for `&mut T` and `Box<T>` to the inner `io::Read`, `io::Write`, `io::Seek`, and `io::BufRead` types.
2025-02-15 02:37:33 -05:00
Jacob Pratt
224be79129
Rollup merge of #136978 - ChrisDenton:windows-bindgen, r=Amanieu
Windows: Update generated bindings

Update to windows-bindgen 0.59.

This update is aimed at reducing churn in the future, but means a bit more churn now:

- `bindings.txt` no longer needs us to write the namespace for each item. This is good because it means in the future we won't need to change them if the namespace changes. However, there are a few where we still need to disambiguate due to duplicate items (this is a bug in the upstream metadata).
- The output in `windows-sys.rs` is now sorted. It was mostly sorted before but not intentionally. This should mean future changes are less noisy.

The actual code changes are minimal here. A few types are now `bool` instead of `BOOLEAN`, which is more convenient.
2025-02-15 02:37:30 -05:00
Jacob Pratt
1524b5319a
Rollup merge of #136879 - kornelski:non1, r=Noratrieb
Add safe new() to NotAllOnes

Replaces duplicated `unsafe` code with a single, easier to verify implementation.
2025-02-15 02:37:29 -05:00
Jacob Pratt
26be558650
Rollup merge of #136749 - mzeitlin11:extend-asciichar, r=scottmcm
Implement Extend<AsciiChar> for String

Implement `Extend<AsciiChar>` for `String` as suggested in https://github.com/rust-lang/rust/issues/110998#issuecomment-2590122968. Also implements `Extend<&AsciiChar>` since there's an analogous impl for `Extend<&char>`, but happy to remove if not thought useful.

r? `@scottmcm`
since you requested it, but no pressure to review!
2025-02-15 02:37:28 -05:00
Jacob Pratt
afbeefb684
Rollup merge of #135687 - joseluis:feat-reexport_from_coroutine, r=scottmcm
re-export `FromCoroutine` from `core::iter`

tracking issue: https://github.com/rust-lang/rust/issues/43122
fixes: #135686
2025-02-15 02:37:27 -05:00
progressive-galib
e52534f7d8
tidying up tidy 2025-02-15 13:34:01 +06:00
Scott McMurray
7add358319 Add real safety comments 2025-02-14 22:59:19 -08:00
Scott McMurray
39118d6181 Go back to Some instead of transmuting to it.
This adds a few more statements to `next`, but optimizes better in the loops (saving 2 blocks in `forward_loop`, for example)
2025-02-14 22:24:27 -08:00
Scott McMurray
3a62c70051 Save another BB by using SubUnchecked instead of a call to arith_offset
Probably reasonable anyway since it more obviously drops provenance.
2025-02-14 22:24:27 -08:00
Scott McMurray
aede8f5fbf Simplify slice::Iter::next enough that it inlines 2025-02-14 22:24:27 -08:00
Thalia Archibald
11c174006e Forward all default methods for I/O impls 2025-02-14 21:48:12 -08:00
progressive.galib
e2b522505b replaced the four occurrences of issue ="50547" in
library/core/src/future/mod.rs with issue = "none"
2025-02-15 05:19:09 +00:00
bors
f77247ac59 Auto merge of #136324 - GrigorenkoPV:erf, r=tgross35
Implement `f{16,32,64,128}::{erf,erfc}` (`#![feature(float_erf)]`)

Tracking issue: #136321

try-job: x86_64-gnu-aux
2025-02-15 04:52:50 +00:00
Jacob Pratt
932f7fd8e4
Make phantom variance markers transparent 2025-02-15 00:47:49 +00:00
Jubilee
922119b79c
Rollup merge of #136983 - ehuss:misc-2024-prep, r=tgross35
Prepare standard library for Rust 2024 migration

This includes a variety of commits preparing the standard library for migration to Rust 2024.

The actual migration is blocked on a few things, so I wanted to get this out of the way in a relatively digestable PR.
2025-02-14 14:05:24 -08:00
Jubilee
58e84ff2b5
Rollup merge of #134016 - zachs18:stable-const-str-split_at, r=Amanieu
Stabilize `const_is_char_boundary` and `const_str_split_at`.

Tracking issues: #131516, #131518

Stabilized const API:

```rs
// in `core`
impl str {
    // const_is_char_boundary feature
    const fn is_char_boundary(&self, index: usize) -> bool;

    // const_str_split_at feature, depends on const_is_char_boundary
    const fn split_at(&self, mid: usize) -> (&str, &str);
    const fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
    const fn split_at_checked(&self, mid: usize) -> Option<(&str, &str)>;
    const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut str, &mut str)>;
}
```

This will allow safely splitting string slices during const-eval.

Closes #131516, Closes #131518

This will need FCP.
r? libs-api

IIUC these do not use any new const language features (i.e. they are implementable manually on stable 1.83.0 using `unsafe`: [playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3679632cd1041084796241b7ac8edfbd)).

Cc ``@rust-lang/wg-const-eval`` (I don't know if I have the permissions for this ping; if not, someone else please ping wg-const-eval if it is necessary)
2025-02-14 14:05:22 -08:00
Pavel Grigorenko
66a4540155 Stabilize (and const-stabilize) integer_sign_cast 2025-02-15 00:17:17 +03:00
Eric Huss
80a7eb1c09 proc_macro: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Eric Huss
4f4ea35a69 std: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Eric Huss
d5f0aa49e7 Fix safety of windows uwp functions
These functions were changed to be safe in
https://github.com/rust-lang/rust/pull/127763, but this particular UWP
version was missed. Otherwise this causes unnecessary unsafe block
warnings/errors.
2025-02-14 07:36:17 -08:00
Eric Huss
0484d23465 unwind: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Eric Huss
331911e699 panic_unwind: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Eric Huss
e13928de93 panic_abort: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Eric Huss
4e36f46464 core: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08:00
Matthias Krüger
145e35a6e3
Rollup merge of #136976 - jedbrown:jed/doc-boxed-deferred-init, r=tgross35
alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr

In the deferred initialization pattern, the docs were needlessly going through `as_mut_ptr().write()` to initialize, which is unnecessary use of a pointer, needs to be inside an `unsafe` block, and may weaken alias analysis.
2025-02-14 16:23:33 +01:00
Matthias Krüger
b5fce2ab8e
Rollup merge of #136967 - DaniPopes:io-repeat-fill, r=joboet
Use `slice::fill` in `io::Repeat` implementation

Use the existing `fill` methods on slices instead of manually writing the fill loop.
2025-02-14 16:23:32 +01:00
Matthias Krüger
c21a76fde0
Rollup merge of #136886 - ehuss:remove-prelude-common, r=jhpratt
Remove the common prelude module

This fixes the issues described in https://github.com/rust-lang/rust/issues/136102. Primarily, this resolves some issues with how the documentation for the prelude is generated:

- It avoids showing "unstable" for macros in the prelude that are actually stable.
- Avoids duplication of some pages due to the previous lack of `doc(no_inline)`.
- Makes the different edition preludes consistent, and sets a pattern that can be used by future editions.

We may need to rearrange these modules in the future if we decide to remove anything from the prelude again. If we do, I think we should look into a different solution that avoids the documentation problems.

Closes https://github.com/rust-lang/rust/issues/136102
2025-02-14 16:23:30 +01:00
Matthias Krüger
678ff2a59b
Rollup merge of #136052 - no1wudi:fix, r=workingjubilee
Correct comment for FreeBSD and DragonFly BSD in unix/thread
2025-02-14 16:23:29 +01:00
Kornel
00964aa401
Add safe new to NotAllOnes 2025-02-14 12:00:13 +00:00
bors
d88ffcdb8b Auto merge of #136735 - scottmcm:transmute-nonnull, r=oli-obk
`transmute` should also assume non-null pointers

Previously it only did integer-ABI things, but this way it does data pointers too.  That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2025-02-14 09:06:17 +00:00
Jubilee
e961aac3c0
Rollup merge of #136992 - ehuss:update-backtrace, r=workingjubilee
Update backtrace

This updates the backtrace submodule.

6 commits in f8cc6ac9acc4e663ecd96f9bcf1ff4542636d1b9..9d2c34e7e63afe1e71c333b247065e3b7ba4d883
2025-01-04 03:37:47 +0100 to 2025-02-13 14:14:18 -0800
- Various cleanups: https://github.com/rust-lang/backtrace-rs/pull/673
- libunwind: Use builtin _Unwind_GetIP for NuttX on ARM platform: https://github.com/rust-lang/backtrace-rs/pull/692
- remove outdated docs part on Dbghelp::ensure_open: https://github.com/rust-lang/backtrace-rs/pull/696
- Cleanup Windows trace modules: https://github.com/rust-lang/backtrace-rs/pull/697
- Attempt to fix ARM32 Windows: https://github.com/rust-lang/backtrace-rs/pull/685
- Prepare backtrace for Rust 2024: https://github.com/rust-lang/backtrace-rs/pull/700
2025-02-13 21:37:53 -08:00
Jubilee
dfc235f80c
Rollup merge of #136908 - mustartt:aix-mutex-destory-einval, r=joboet
[AIX] expect `EINVAL` for `pthread_mutex_destroy`

Calling `pthread_mutex_destory` on a mutex initalized with the static initializer macro `PTHREAD_MUTEX_INITIALIZER` will result in `EINVAL` if the mutex is not lock/unlocked prior to calling `pthread_mutex_destroy`.
2025-02-13 21:37:51 -08:00
Jubilee
a82d7d6026
Rollup merge of #136904 - pitaj:range-into_bounds, r=tgross35
add `IntoBounds` trait

for `range_into_bounds`  feature

Tracking issue: #136903
ACP: https://github.com/rust-lang/libs-team/issues/538
2025-02-13 21:37:50 -08:00
Eric Huss
06524b56bd Update backtrace 2025-02-13 14:32:50 -08:00
Pavel Grigorenko
b8f0ed37bd Implement f{16,32,64,128}::{erf,erfc}
Also add
```rust
// #[unstable(feature = "float_gamma", issue = "99842")]
```
to `gamma`-function-related methods on `f16` & `f128`,
as per https://github.com/rust-lang/rust/pull/136324#issuecomment-2626270247
2025-02-14 01:23:16 +03:00
Eric Huss
ef20a1b1f8 std: Apply deprecated_safe_2024 2025-02-13 13:10:28 -08:00
Eric Huss
36733f3bce test: Apply deprecated_safe_2024 2025-02-13 13:10:27 -08:00
Eric Huss
1b3940f07f std: Apply fixes for tail drop expressions 2025-02-13 13:10:27 -08:00
Eric Huss
1ba59f868a std: Apply rust_2024_incompatible_pat 2025-02-13 13:10:27 -08:00
Eric Huss
7dc9e05742 std: Apply dependency_on_unit_never_type_fallback
This generates a warning of irrefutable patterns. I decided to slightly
tweak the example so the closure returns unit, since the intent wasn't
to show the weird behavior of returning `!`.
2025-02-13 13:10:27 -08:00
Eric Huss
c1791a1b48 std: Apply missing_unsafe_on_extern 2025-02-13 13:10:27 -08:00
Eric Huss
9e60b0e554 std: Apply unsafe_attr_outside_unsafe 2025-02-13 13:10:27 -08:00
Eric Huss
07ebbddeff alloc: Apply missing_unsafe_on_extern 2025-02-13 13:10:27 -08:00
Eric Huss
55ef73c00d alloc: Apply unsafe_attr_outside_unsafe 2025-02-13 13:10:27 -08:00
Eric Huss
890530e186 alloc: Workaround hidden doctest line
A small workaround for https://github.com/rust-lang/rust/issues/136899,
rustdoc's invalid_rust_codeblocks was not handling this well in 2024.
This may be needed when migrating to 2024 when building with stage0.
2025-02-13 13:10:27 -08:00
Eric Huss
0aa634e71a Migrate coretests to Rust 2024 2025-02-13 13:10:21 -08:00
bors
a567209daa Auto merge of #134633 - GrigorenkoPV:get_disjoint_mut, r=cuviper
Stabilize `get_many_mut` as `get_disjoint_mut`

Tracking issue: #104642

Closes #104642

FCP completed in https://github.com/rust-lang/rust/issues/104642#issuecomment-2558161073
2025-02-13 21:09:31 +00:00
Eric Huss
b7c975b22e library: Update rand to 0.9.0 2025-02-13 12:20:55 -08:00
Eric Huss
ef34064679 core: Apply unsafe_attr_outside_unsafe 2025-02-13 08:53:21 -08:00
Jed Brown
2f27236745 alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr
In the deferred initialization pattern, the docs were needlessly going
through as_mut_ptr().write() to initialize, which is unnecessary use of
a pointer, needs to be inside an unsafe block, and may weaken alias
analysis.
2025-02-13 09:13:33 -07:00
xizheyin
c1ecdf1124 Consistently using as_mut_ptr() and as_ptr() in thread
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-13 19:39:05 +08:00
xizheyin
7e7f5d3856 Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in unix
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-13 19:39:05 +08:00
DaniPopes
1a3efd27ab
Use slice::fill in io::Repeat implementation
Use the existing `fill` methods on slices instead of manually
writing the fill loop.
2025-02-13 12:23:52 +01:00
Chris Denton
26eeac1a1e
Windows: Update generated bindings to 0.59 2025-02-13 10:32:59 +00:00
Jacob Pratt
f9142b0785
Rollup merge of #136949 - ehuss:wasm-bench-time, r=jhpratt
Fix import in bench for wasm

This import was causing annoying unused import errors when checking the standard library for some wasm targets. The problem is that everything here is disabled if it is wasm32, but this import wasn't cfg'd.
2025-02-13 03:53:33 -05:00
Jacob Pratt
4ea261018a
Rollup merge of #136660 - compiler-errors:BikeshedGuaranteedNoDrop, r=lcnr
Use a trait to enforce field validity for union fields + `unsafe` fields + `unsafe<>` binder types

This PR introduces a new, internal-only trait called `BikeshedGuaranteedNoDrop`[^1] to faithfully model the field check that used to be implemented manually by `allowed_union_or_unsafe_field`.

942db6782f/compiler/rustc_hir_analysis/src/check/check.rs (L84-L115)

Copying over the doc comment from the trait:

```rust
/// Marker trait for the types that are allowed in union fields, unsafe fields,
/// and unsafe binder types.
///
/// Implemented for:
/// * `&T`, `&mut T` for all `T`,
/// * `ManuallyDrop<T>` for all `T`,
/// * tuples and arrays whose elements implement `BikeshedGuaranteedNoDrop`,
/// * or otherwise, all types that are `Copy`.
///
/// Notably, this doesn't include all trivially-destructible types for semver
/// reasons.
///
/// Bikeshed name for now.
```

As far as I am aware, there's no new behavior being guaranteed by this trait, since it operates the same as the manually implemented check. We could easily rip out this trait and go back to using the manually implemented check for union fields, however using a trait means that this code can be shared by WF for `unsafe<>` binders too. See the last commit.

The only diagnostic changes are that this now fires false-negatives for fields that are ill-formed. I don't consider that to be much of a problem though.

r? oli-obk

[^1]: Please let's not bikeshed this name lol. There's no good name for `ValidForUnsafeFieldsUnsafeBindersAndUnionFields`.
2025-02-13 03:53:30 -05:00
Scott McMurray
0cc14b688d transmute should also assume non-null pointers
Previously it only did integer-ABI things, but this way it does data pointers too.  That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2025-02-12 23:01:27 -08:00
Michael Goulet
516afd557c Implement and use BikeshedGuaranteedNoDrop for union/unsafe field validity 2025-02-13 03:45:04 +00:00
Jacob Pratt
9a26bb1892
Rollup merge of #136945 - samueltardieu:push-rsqlyknnvyqm, r=fmease
Add diagnostic item for `std::io::BufRead`

This will be used in Clippy to detect unbuffered calls to `Read::bytes()`.
2025-02-12 20:10:03 -05:00
Jacob Pratt
de712f9e0a
Rollup merge of #136818 - a1phyr:io_repeat_exact, r=jhpratt
Implement `read*_exact` for `std:io::repeat`

cc #136756
2025-02-12 20:10:01 -05:00
Jacob Pratt
4ce473ccba
Rollup merge of #136699 - joboet:netaddr_from_inner, r=cuviper
std: replace the `FromInner` implementation for addresses with private conversion functions

Having these implementation available crate-wide means that platforms not using sockets for their networking code have to stub out the libc definitions required to support them. This PR moves the conversions to private helper functions that are only available where actually needed.

I also fixed the signature of the function converting from a C socket address to a Rust one: taking a reference to a `sockaddr_storage` resulted in unsound usage inside  `LookupHost::next`, which could create a reference to a structure smaller than `sockaddr_storage`. Thus I've replaced the argument type with a pointer and made the function `unsafe`.
2025-02-12 20:09:59 -05:00
Jacob Pratt
575405161f
Rollup merge of #134090 - veluca93:stable-tf11, r=oli-obk
Stabilize target_feature_11

# Stabilization report

This is an updated version of https://github.com/rust-lang/rust/pull/116114, which is itself a redo of https://github.com/rust-lang/rust/pull/99767. Most of this commit and report were copied from those PRs. Thanks ```@LeSeulArtichaut``` and ```@calebzulawski!```

## Summary
Allows for safe functions to be marked with `#[target_feature]` attributes.

Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot *generally* be assigned to safe function pointers, and don't implement the `Fn*` traits.

However, calling them from other `#[target_feature]` functions with a superset of features is safe.

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() {
    // Calling `avx2` here is unsafe, as we must ensure
    // that AVX is available first.
    unsafe {
        avx2();
    }
}

#[target_feature(enable = "avx2")]
fn bar() {
    // Calling `avx2` here is safe.
    avx2();
}
```

Moreover, once https://github.com/rust-lang/rust/pull/135504 is merged, they can be converted to safe function pointers in a context in which calling them is safe:

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() -> fn() {
    // Converting `avx2` to fn() is a compilation error here.
    avx2
}

#[target_feature(enable = "avx2")]
fn bar() -> fn() {
    // `avx2` coerces to fn() here
    avx2
}
```

See the section "Closures" below for justification of this behaviour.

## Test cases
Tests for this feature can be found in [`tests/ui/target_feature/`](f6cb952dc1/tests/ui/target-feature).

## Edge cases
### Closures
 * [target-feature 1.1: should closures inherit target-feature annotations? #73631](https://github.com/rust-lang/rust/issues/73631)

Closures defined inside functions marked with #[target_feature] inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```
This means that in order to call a function with #[target_feature], you must guarantee that the target-feature is available while the function, any closures defined inside it, as well as any safe function pointers obtained from target-feature functions inside it, execute.

This is usually ensured because target features are assumed to never disappear, and:
- on any unsafe call to a `#[target_feature]` function, presence of the target feature is guaranteed by the programmer through the safety requirements of the unsafe call.
- on any safe call, this is guaranteed recursively by the caller.

If you work in an environment where target features can be disabled, it is your responsibility to ensure that no code inside a target feature function (including inside a closure) runs after this (until the feature is enabled again).

**Note:** this has an effect on existing code, as nowadays closures do not inherit features from the enclosing function, and thus this strengthens a safety requirement. It was originally proposed in #73631 to solve this by adding a new type of UB: “taking a target feature away from your process after having run code that uses that target feature is UB” .
This was motivated by userspace code already assuming in a few places that CPU features never disappear from a program during execution (see i.e. 2e29bdf908/crates/std_detect/src/detect/arch/x86.rs); however, concerns were raised in the context of the Linux kernel; thus, we propose to relax that requirement to "causing the set of usable features to be reduced is unsafe; when doing so, the programmer is required to ensure that no closures or safe fn pointers that use removed features are still in scope".

* [Fix #[inline(always)] on closures with target feature 1.1 #111836](https://github.com/rust-lang/rust/pull/111836)

Closures accept `#[inline(always)]`, even within functions marked with `#[target_feature]`. Since these attributes conflict, `#[inline(always)]` wins out to maintain compatibility.

### ABI concerns
* [The extern "C" ABI of SIMD vector types depends on target features #116558](https://github.com/rust-lang/rust/issues/116558)

The ABI of some types can change when compiling a function with different target features. This could have introduced unsoundness with target_feature_11, but recent fixes (#133102, #132173) either make those situations invalid or make the ABI no longer dependent on features. Thus, those issues should no longer occur.

### Special functions
The `#[target_feature]` attribute is forbidden from a variety of special functions, such as main, current and future lang items (e.g. `#[start]`, `#[panic_handler]`), safe default trait implementations and safe trait methods.

This was not disallowed at the time of the first stabilization PR for target_features_11, and resulted in the following issues/PRs:
* [`#[target_feature]` is allowed on `main` #108645](https://github.com/rust-lang/rust/issues/108645)
* [`#[target_feature]` is allowed on default implementations #108646](https://github.com/rust-lang/rust/issues/108646)
* [#[target_feature] is allowed on #[panic_handler] with target_feature 1.1 #109411](https://github.com/rust-lang/rust/issues/109411)
* [Prevent using `#[target_feature]` on lang item functions #115910](https://github.com/rust-lang/rust/pull/115910)

## Documentation
 * Reference: [Document the `target_feature_11` feature reference#1181](https://github.com/rust-lang/reference/pull/1181)
---

cc tracking issue https://github.com/rust-lang/rust/issues/69098
cc ```@workingjubilee```
cc ```@RalfJung```
r? ```@rust-lang/lang```
2025-02-12 20:09:56 -05:00
Peter Jaszkowiak
9c03369c17 add IntoBounds trait
for `range_into_bounds`  feature, #136903
2025-02-12 17:38:44 -07:00
Eric Huss
c91737373a Fix import in bench for wasm 2025-02-12 14:44:30 -08:00
Samuel Tardieu
f8930b44a5 Add diagnostic item for std::io::BufRead
This will be used in Clippy to detect unbuffered calls to
`Read::bytes()`.
2025-02-12 22:22:15 +01:00
Guillaume Gomez
269d784dd5
Rollup merge of #136890 - saethlin:swap_nonoverlapping, r=RalfJung
Change swap_nonoverlapping from lang to library UB

The implementation of ptr::swap_nonoverlapping does not always escalate its safety contract to language UB, so it should be `check_library_ub`.

Fixes https://github.com/rust-lang/miri/issues/4188
2025-02-12 20:30:54 +01:00
Ben Kimock
21bb8cb946 Change swap_nonoverlapping from lang to library UB 2025-02-12 12:20:14 -05:00
joboet
80c60fe783
std: replace the FromInner implementation for addresses with private conversion functions
Having these implementation available crate-wide means that platforms not using sockets for their networking code have to stub out the libc definitions required to support them. This PR moves the conversions to private helper functions that are only available where actually needed.

I also fixed the signature of the function converting from a C socket address to a Rust one: taking a reference to a `sockaddr_storage` resulted in unsound usage inside  `LookupHost::next`, which could create a reference to a structure smaller than `sockaddr_storage`. Thus I've replaced the argument type with a pointer and made the function `unsafe`.
2025-02-12 14:13:35 +01:00
Samuel Tardieu
f3515fb127 Remove ignored #[must_use] attributes from portable-simd
The `#[must_use]` attribute has no effect when applied to methods in
trait implementations.
2025-02-12 13:59:22 +01:00
bors
552a959051 Auto merge of #136918 - GuillaumeGomez:rollup-f6h21gg, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #134981 ( Explain that in paths generics can't be set on both the enum and the variant)
 - #136698 (Replace i686-unknown-redox target with i586-unknown-redox)
 - #136767 (improve host/cross target checking)
 - #136829 ([rustdoc] Move line numbers into the `<code>` directly)
 - #136875 (Rustc dev guide subtree update)
 - #136900 (compiler: replace `ExternAbi::name` calls with formatters)
 - #136913 (Put kobzol back on review rotation)
 - #136915 (documentation fix: `f16` and `f128` are not double-precision)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-12 12:42:25 +00:00
Guillaume Gomez
40f04999f5
Rollup merge of #136915 - eyelash:float-precision, r=workingjubilee
documentation fix: `f16` and `f128` are not double-precision
2025-02-12 10:46:42 +01:00
bors
021fb9c09a Auto merge of #136897 - workingjubilee:revert-unfcped-stab, r=WaffleLapkin
Revert "Stabilize `extended_varargs_abi_support`"

I cannot find an FCP for this, despite it being a stabilization PR which normally means we do an FCP of some kind? It would seem reasonable for _either_ compiler or lang to have FCPed it? I am thus opening a revert PR, which mostly-cleanly applies, so that we can later actually land this properly with a stability report and FCP.

- https://github.com/rust-lang/rust/issues/136896
- https://github.com/rust-lang/rust/pull/116161
- https://github.com/rust-lang/rust/issues/100189
2025-02-12 09:44:30 +00:00
eyelash
4f37b458fc
f128 is quadruple-precision 2025-02-12 09:55:45 +01:00
eyelash
0ca8353651
f16 is half-precision 2025-02-12 09:54:33 +01:00
Henry Jiang
4b086d4711 expect EINVAL for pthread_mutex_destroy for aix 2025-02-12 00:54:00 -05:00
Matthias Krüger
72fd5719aa
Rollup merge of #136874 - tgross35:likely-unlikely-tracking, r=jhpratt
Change the issue number for `likely_unlikely` and `cold_path`

These currently point to rust-lang/rust#26179, which is nearly a decade old and has a lot of outdated discussion. Move these features to a new tracking issue specifically for the recently added API.

New tracking issue: https://github.com/rust-lang/rust/issues/136873
2025-02-12 06:07:38 +01:00
Jubilee Young
cafa646f21 library: amend revert of extended_varargs_abi_support for beta diff
And leave a comment on the unusual `cfg_attr`

Co-authored-by: waffle <waffle.lapkin@gmail.com>
2025-02-11 20:03:56 -08:00
Kevin Reid
d2ed8cf661 Optionally add type names to TypeIds.
This feature is intended to provide expensive but thorough help for
developers who have an unexpected `TypeId` value and need to determine
what type it actually is. It causes `impl Debug for TypeId` to print
the type name in addition to the opaque ID hash, and in order to do so,
adds a name field to `TypeId`. The cost of this is the increased size of
`TypeId` and the need to store type names in the binary; therefore, it
is an optional feature.

It may be enabled via `cargo -Zbuild-std -Zbuild-std-features=debug_typeid`.
(Note that `-Zbuild-std-features` disables default features which you
may wish to reenable in addition; see
<https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features>.)

Example usage and output:

```
fn main() {
    use std::any::{Any, TypeId};
    dbg!(TypeId::of::<usize>(), drop::<usize>.type_id());
}
```

```
TypeId::of::<usize>() = TypeId(0x763d199bccd319899208909ed1a860c6 = usize)
drop::<usize>.type_id() = TypeId(0xe6a34bd13f8c92dd47806da07b8cca9a = core::mem::drop<usize>)
```

Also added feature declarations for the existing `debug_refcell` feature
so it is usable from the `rust.std-features` option of `config.toml`.
2025-02-11 18:42:19 -08:00
Jubilee Young
d97bde059a Revert "Stabilize extended_varargs_abi_support"
This reverts commit 685f189b43.
2025-02-11 17:22:27 -08:00
Eric Huss
8c24c0a023 Remove the common prelude module
This fixes the issues described in
https://github.com/rust-lang/rust/issues/136102. Primarily, this
resolves some issues with how the documentation for the prelude is
generated:

- It avoids showing "unstable" for macros in the prelude that are
  actually stable.
- Avoids duplication of some pages due to the previous lack of
  `doc(no_inline)`.
- Makes the different edition preludes consistent, and sets a pattern
  that can be used by future editions.

We may need to rearrange these modules in the future if we decide to
remove anything from the prelude again. If we do, I think we should look
into a different solution that avoids the documentation problems.
2025-02-11 13:04:27 -08:00
Josh Triplett
bc59397f8f Document that locking a file fails on Windows if the file is opened only for append 2025-02-11 21:11:05 +01:00
Josh Triplett
16abb39c9d Reword file lock documentation to clarify advisory vs mandatory
Remove the word "advisory", and make it more explicit that the lock may
be advisory or mandatory depending on platform.
2025-02-11 21:11:05 +01:00
Matthias Krüger
45a0ec81ea
Rollup merge of #136354 - hkBst:patch-34, r=ibraheemdev
Update docs for impl keyword

This started as a fix for #79878, but also introduces some structure (headings), and elaborates a tiny bit on impl Trait syntax.
2025-02-11 18:04:40 +01:00
Matthias Krüger
052ebc65b2
Rollup merge of #136246 - hkBst:patch-29, r=ibraheemdev
include note on variance and example

Fixes #89150
2025-02-11 18:04:38 +01:00
Trevor Gross
e32f79583c Change the issue number for likely_unlikely and cold_path
These currently point to rust-lang/rust#26179, which is nearly a decade
old and has a lot of outdated discussion. Move these features to a new
tracking issue specifically for the recently added API.

New tracking issue: https://github.com/rust-lang/rust/issues/136873
2025-02-11 16:10:35 +00:00
bors
69482e8e5a Auto merge of #136851 - jhpratt:rollup-ftijn95, r=jhpratt
Rollup of 11 pull requests

Successful merges:

 - #136606 (Fix long lines which rustfmt fails to format)
 - #136663 (Stabilize `NonZero::count_ones`)
 - #136672 (library: doc: core::alloc::Allocator: trivial typo fix)
 - #136704 (Improve examples for file locking)
 - #136721 (cg_llvm: Reduce visibility of some items outside the `llvm` module)
 - #136813 (rustc_target: Add the fp16 target feature for AArch32)
 - #136830 (fix i686-unknown-hurd-gnu x87 footnote)
 - #136832 (Fix platform support table for i686-unknown-uefi)
 - #136835 (Stop using span hack for contracts feature gating)
 - #136837 (Overhaul how contracts are lowered on fn-like bodies)
 - #136839 (fix ensure_monomorphic_enough)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-11 10:17:02 +00:00
Marijn Schouten
e279c4eadb include note on variance and example
Fixes #89150

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2025-02-11 09:20:59 +01:00
Marijn Schouten
166680c480 Update docs for impl keyword 2025-02-11 08:04:32 +01:00
Jacob Pratt
2996cfdcc3
Rollup merge of #136704 - benschulz:patch-1, r=ibraheemdev
Improve examples for file locking

The `lock` and `try_lock` documentation states that "if the file not open for writing, it is unspecified whether this function returns an error." With this change, the examples use `File::create` instead of `File::open`, eliminating the possibility of someone blindly copying code with unspecified behavior.
2025-02-11 01:02:40 -05:00
Jacob Pratt
aaf2c46202
Rollup merge of #136672 - safinaskar:alloc-2025-02-07-09-10, r=cuviper
library: doc: core::alloc::Allocator: trivial typo fix

(see subject)
2025-02-11 01:02:39 -05:00
Jacob Pratt
67e4e3aea9
Rollup merge of #136663 - WaffleLapkin:count-non-zero-ones, r=cuviper
Stabilize `NonZero::count_ones`

As per https://github.com/rust-lang/rust/issues/120287#issuecomment-2639187140

r? libs
2025-02-11 01:02:38 -05:00
Thalia Archibald
593c88fc49 Fix long lines which rustfmt fails to format
rustfmt fails to format this match expression, because it has several
long string literals over the maximum line width. This seems to exhibit
rustfmt issues #3863 (Gives up on chains if any line is too long) and
#3156 (Fail to format match arm when other arm has long line).
2025-02-10 18:51:29 -08:00
Matthias Krüger
af3c51d849
Rollup merge of #136107 - dingxiangfei2009:coerce-pointee-wellformed, r=compiler-errors
Introduce CoercePointeeWellformed for coherence checks at typeck stage

Fix #135206

This is the first PR to introduce the "wellformedness" check for `derive(CoercePointee)`.

This patch introduces a new error code to cover all the prerequisites of the said macro. The checks that is enforced with this patch is whether the data is indeed `struct` and whether the layout is set to `repr(transparent)`.

A following series of patch will arrive later to address the following concern.
1. #135217 so that we would only admit one single coercion on one type parameter, and leave the rest for future consideration in tandem of development of other coercion rules.
1. Enforcement of data field requirements.

**An open question** is whether there is a good schema to encode the `#[pointee]` as well, so that we could also check if the `#[pointee]` type parameter is indeed `?Sized`.

``@rustbot`` label F-derive_coerce_pointee
2025-02-11 02:53:42 +01:00
Thalia Archibald
9e390b2995 Fix &&str and trailing commas in io::const_error! 2025-02-10 16:34:13 -08:00
Thalia Archibald
7edd034a1f Use io::const_error! when possible over io::Error::new 2025-02-10 16:20:21 -08:00
bors
4bb6ec05b0 Auto merge of #136823 - matthiaskrgr:rollup-vp20mk1, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #136419 (adding autodiff tests)
 - #136628 (ci: upgrade to crosstool-ng 1.27.0)
 - #136681 (resolve `llvm-config` path properly on cross builds)
 - #136714 (Update `compiler-builtins` to 0.1.146)
 - #136731 (rustc_middle: parallel: TyCtxt: remove "unsafe impl DynSend/DynSync")
 - #136791 (Disable DWARF in linker options for i686-unknown-uefi)

Failed merges:

 - #136767 (improve host/cross target checking)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-10 18:12:10 +00:00
Michael Goulet
17026e2412
Reword doc comment on CoercePointeeValidated 2025-02-10 11:50:02 -05:00
Matthias Krüger
ad92b850c6
Rollup merge of #136714 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.146

Exposes the error function so we can expose this in the standard library [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/753
2025-02-10 16:38:26 +01:00
bors
4b293d9927 Auto merge of #135701 - calebzulawski:sync-from-portable-simd-2025-01-18, r=workingjubilee
Portable SIMD subtree update

r? `@workingjubilee`
2025-02-10 15:19:51 +00:00
Benoît du Garreau
321fab4337 Implement read*_exact for std:io::repeat
cc #136756
2025-02-10 13:43:12 +01:00
Jubilee
ffa8a96040
Rollup merge of #136805 - RalfJung:miri-win-delete-self, r=Noratrieb
ignore win_delete_self test in Miri

Follow-up to https://github.com/rust-lang/rust/pull/134679, fixes miri-test-libstd on Windows

Cc `@ChrisDenton` `@Mark-Simulacrum`
2025-02-10 00:51:58 -08:00
Jubilee
72f0205d28
Rollup merge of #136705 - compiler-errors:edition-library, r=jhpratt
Some miscellaneous edition-related library tweaks

Some library edition tweaks that can be done separately from upgrading the whole standard library to edition 2024 (which is blocked on getting the submodules upgraded, for example)
2025-02-10 00:51:54 -08:00
Jubilee
f471ce39fb
Rollup merge of #136552 - ChrisDenton:option-find-handle, r=Mark-Simulacrum
Use an `Option` for `FindNextFileHandle` in `ReadDir` instead of `INVALID_FILE_HANDLE` sentinel value

Sometimes we store an invalid handle when we don't want to return an error. We then check the handle before use in order to avoid actually using the invalid handle. However, using an `Option` for this is better and avoids us forgetting to check the handle is valid. This was noticed due to us closing the handle without checking for validity: bd6a6777f5/library/std/src/sys/pal/windows/fs.rs (L148-L151)
2025-02-10 00:51:53 -08:00
Jubilee
6ef2cd8e1c
Rollup merge of #136353 - purplesyringa:libtest-instant-wasm, r=Mark-Simulacrum
fix(libtest): Enable Instant on Emscripten targets

`Instant::now()` works correctly on Emscripten since https://github.com/rust-lang/libc/pull/3962. All wasm-family targets with OS support can now handle instants.

Improves #131738.

~~This changes the behavior of libtest on `unknown-unknown`/`unknown-none` wasm targets, but as far as I can see, libtest doesn't support them anyway. (Can anyone double-check?)~~ UPD: this patch no longer affects `unknown-unknown` targets.

``@rustbot`` label +A-libtest +T-testing-devex +O-emscripten +O-wasm -needs-triage
2025-02-10 00:51:51 -08:00
Jubilee
888b438476
Rollup merge of #136228 - hkBst:patch-28, r=Mark-Simulacrum
Simplify Rc::as_ptr docs + typo fix
2025-02-10 00:51:50 -08:00
Ralf Jung
2f3c943f42 ignore win_delete_self test in Miri 2025-02-10 08:08:32 +01:00
Christopher Berner
82af73dd4c Stabilize file_lock 2025-02-09 13:55:42 -08:00
Alisa Sireneva
b01c7f6b9c fix(libtest): Enable Instant on Emscripten targets
`Instant::now()` works correctly on Emscripten since
https://github.com/rust-lang/libc/pull/3962. All wasm-family targets
with OS support can now handle instants.
2025-02-09 23:51:54 +03:00
Ding Xiang Fei
18483434ae
block coerce_pointee_validated for stabilization 2025-02-10 04:36:43 +08:00