Commit graph

18049 commits

Author SHA1 Message Date
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
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
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
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
Jubilee Young
d97bde059a Revert "Stabilize extended_varargs_abi_support"
This reverts commit 685f189b43.
2025-02-11 17:22:27 -08: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
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