Commit Graph

8402 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Scott McMurray
3a3aedee10 Update some comparison tests now that they pass in LLVM20 2025-02-17 16:36:14 -08: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
bendn
92fd960ca4
stabilize (const_)ptr_sub_ptr 2025-02-17 10:07:27 +07: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
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
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
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
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
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
4e36f46464 core: Apply unsafe_op_in_unsafe_fn 2025-02-14 07:36:17 -08: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
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
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
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
ef34064679 core: Apply unsafe_attr_outside_unsafe 2025-02-13 08:53:21 -08: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
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
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
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
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
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
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
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
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
Michael Goulet
17026e2412
Reword doc comment on CoercePointeeValidated 2025-02-10 11:50:02 -05: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
Ding Xiang Fei
18483434ae
block coerce_pointee_validated for stabilization 2025-02-10 04:36:43 +08:00
Michael Goulet
a4e7f8f9bf Mark extern blocks as unsafe 2025-02-09 17:11:13 +00:00
Michael Goulet
04bbc8340a Rename field in OnceWith from gen to make 2025-02-09 17:10:50 +00:00
bors
124cc92199 Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrum
Update bootstrap compiler and rustfmt

The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same
time.
2025-02-09 15:44:16 +00:00
bors
a26e97be88 Auto merge of #136754 - Urgau:rollup-qlkhjqr, r=Urgau
Rollup of 5 pull requests

Successful merges:

 - #134679 (Windows: remove readonly files)
 - #136213 (Allow Rust to use a number of libc filesystem calls)
 - #136530 (Implement `x perf` directly in bootstrap)
 - #136601 (Detect (non-raw) borrows of null ZST pointers in CheckNull)
 - #136659 (Pick the max DWARF version when LTO'ing modules with different versions )

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-09 12:54:26 +00:00
Ding Xiang Fei
c067324637
rename the trait to validity and place a feature gate afront 2025-02-09 20:40:42 +08:00
Ding Xiang Fei
de405dcb8f
introduce CoercePointeeWellformed for coherence checks at typeck stage 2025-02-09 20:40:41 +08:00
Jubilee
bf2c5323e0
Rollup merge of #136724 - steffahn:asyncfn-non-fundamental, r=compiler-errors
Make `AsyncFnOnce`, `AsyncFnMut`, `AsyncFn` non-`#[fundamental]`

Address the issue #136723 on nightly (the issue will only *actually* be fixed with a beta backport).
2025-02-08 20:41:22 -08:00
Michael Goulet
a61537f6c0 occured -> occurred 2025-02-08 22:28:21 +00:00
bjorn3
1fcae03369 Rustfmt 2025-02-08 22:12:13 +00:00
Jaken Herman
4457f44065 Document Sum::sum returns additive identities for []
Because the neutral element of `<fNN as iter::Sum>` was changed to
`neg_zero`, the documentation needed to be updated, as it was reporting
inadequate information about what should be expected from the return.

Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-02-08 14:06:13 -08:00
Frank Steffahn
7155382240 Make AsyncFnOnce, AsyncFnMut, AsyncFn non-#[fundamental] 2025-02-08 02:45:29 +01:00
Lukas Bergdoll
4c9b9d7258 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-07 15:22:42 +01:00
Askar Safin
ac31e9572b library: doc: core::alloc::Allocator: trivial typo fix 2025-02-07 09:14:17 +03:00
Waffle Lapkin
82b32ba03d
stabilize NonZero::count_ones 2025-02-06 22:40:25 +01:00
bors
59588250ad Auto merge of #136613 - workingjubilee:rollup-ry6rw0m, r=workingjubilee
Rollup of 13 pull requests

Successful merges:

 - #133932 (Avoid using make_direct_deprecated() in extern "ptx-kernel")
 - #136269 (Pass spans around new solver)
 - #136550 (Fix `rustc_hidden_type_of_opaques` for RPITITs with no default body)
 - #136558 (Document minimum supported host tooling on macOS)
 - #136563 (Clean up `Trivial*Impls` macros)
 - #136566 (Fix link in from_fn.rs)
 - #136573 (Document why some "type mismatches" exist)
 - #136583 (Only highlight unmatchable parameters at the definition site)
 - #136587 (Update browser-ui-test version to `0.20.2`)
 - #136590 (Implement RustcInternal for RawPtrKind)
 - #136591 (Add `rustc_hir_pretty::expr_to_string` function)
 - #136595 (Fix `unreachable_pub` lint for hermit target)
 - #136611 (cg_llvm: Remove the `mod llvm_` hack, which should no longer be necessary)

Failed merges:

 - #136565 (compiler: Clean up weird `rustc_abi` reexports)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-06 06:45:07 +00:00
Jubilee
8964e70051
Rollup merge of #136566 - hkBst:patch-1, r=scottmcm
Fix link in from_fn.rs
2025-02-05 19:53:49 -08:00
bors
c753cb9b42 Auto merge of #136409 - TDecking:mul_hi, r=Mark-Simulacrum
Use `widening_mul` instead of a separate function

A helper function became obsolete after `widening_mul` became available for `u128` values.
2025-02-06 03:43:58 +00:00
许杰友 Jieyou Xu (Joe)
fd4623bdcc
Rollup merge of #136555 - cramertj:split_off, r=dtolnay
Rename `slice::take...` methods to `split_off...`

This rename was discussed and recommended in a recent t-libs meeting.

cc https://github.com/rust-lang/rust/issues/62280

There's an additional commit here which modifies internals of unstable `OneSidedRange` APIs in order to implement `split_off` methods in a panic-free way (remove `unreachable!()`) as recommended in https://github.com/rust-lang/rust/pull/88502/files#r760177240. I can split this out into a separate PR if needed.
2025-02-05 19:09:38 +08:00
许杰友 Jieyou Xu (Joe)
7ad1a3b8d8
Rollup merge of #136517 - m4rch3n1ng:inherent-str-constructors, r=jhpratt
implement inherent str constructors

implement #131114

this implements
- str::from_utf8
- str::from_utf8_mut
- str::from_utf8_unchecked
- str::from_utf8_unchecked_mut

i left `std::str::from_raw_parts` and `std::str::from_raw_parts_mut` out of this as those are unstable and were not mentioned by the tracking issue or the original pull request, but i can  add those here as well.

i was also unsure of what to do with the `rustc_const_(un)stable` attributes: i removed the `#[rustc_const_stable]` attribute from `str::from_utf8`, `str::from_utf8_unchecked` and `str::from_utf8_unchecked_mut`, and left the`#[rust_const_unstable]` in `str::from_utf8_mut` (btw why is that one not const stable yet with #57349 merged?).

is there a way to redirect users to the stable `std::str::from_utf8` instead of only saying "hey this is unstable"?

for now i just removed the check for `str::from_utf8` in the test in `tests/ui/suggestions/suggest-std-when-using-type.rs`.
2025-02-05 19:09:36 +08:00
Marijn Schouten
6770d3ddf4
Fix link in from_fn.rs 2025-02-05 08:52:13 +01:00
León Orell Valerian Liehr
ba420062f1
Rollup merge of #136502 - yotamofek:pr/fmt-from-fn-must-use, r=dtolnay
Mark `std::fmt::from_fn` as `#[must_use]`

While working on #135494 I managed to shoot my own foot a few times by forgetting to actually use the result of `fmt::from_fn`, so I think a `#[must_use]` could be appropriate!

Didn't have a good message to put in the attr so left it blank, still unstable so we can come back to it I guess?

cc #117729 (and a huge +1 for getting it stabilized, it's very useful IMHO)
2025-02-05 05:03:06 +01:00
León Orell Valerian Liehr
d81701b610
Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obk
#[contracts::requires(...)]  + #[contracts::ensures(...)]

cc https://github.com/rust-lang/rust/issues/128044

Updated contract support: attribute syntax for preconditions and postconditions, implemented via a series of desugarings  that culminates in:
1. a compile-time flag (`-Z contract-checks`) that, similar to `-Z ub-checks`, attempts to ensure that the decision of enabling/disabling contract checks is delayed until the end user program is compiled,
2. invocations of lang-items that handle invoking the precondition,  building a checker for the post-condition, and invoking that post-condition checker at the return sites for the function, and
3. intrinsics for the actual evaluation of pre- and post-condition predicates that third-party verification tools can intercept and reinterpret for their own purposes (e.g. creating shims of behavior that abstract away the function body and replace it solely with the pre- and post-conditions).

Known issues:

 * My original intent, as described in the MCP (https://github.com/rust-lang/compiler-team/issues/759) was   to have a rustc-prefixed attribute namespace (like   rustc_contracts::requires). But I could not get things working when I tried   to do rewriting via a rustc-prefixed builtin attribute-macro. So for now it  is called `contracts::requires`.

 * Our attribute macro machinery does not provide direct support for attribute arguments that are parsed like rust expressions. I spent some time trying to add that (e.g. something that would parse the attribute arguments as an AST while treating the remainder of the items as a token-tree), but its too big a lift for me to undertake. So instead I hacked in something approximating that goal, by semi-trivially desugaring the token-tree attribute contents into internal AST constucts. This may be too fragile for the long-term.
   * (In particular, it *definitely* breaks when you try to add a contract to a function like this: `fn foo1(x: i32) -> S<{ 23 }> { ... }`, because its token-tree based search for where to inject the internal AST constructs cannot immediately see that the `{ 23 }` is within a generics list. I think we can live for this for the short-term, i.e. land the work, and continue working on it while in parallel adding a new attribute variant that takes a token-tree attribute alongside an AST annotation, which would completely resolve the issue here.)

* the *intent* of `-Z contract-checks` is that it behaves like `-Z ub-checks`, in that we do not prematurely commit to including or excluding the contract evaluation in upstream crates (most notably, `core` and `std`). But the current test suite does not actually *check* that this is the case. Ideally the test suite would be extended with a multi-crate test that explores the matrix of enabling/disabling contracts on both the upstream lib and final ("leaf") bin crates.
2025-02-05 05:03:01 +01:00
Taylor Cramer
836a989820 Add OneSidedRangeBound to eliminate panic in split_point_of
See discussion in https://github.com/rust-lang/rust/pull/88502/files#r760177240
2025-02-04 11:45:21 -08:00
Taylor Cramer
07cf20e987 Rename slice::take methods to split_off 2025-02-04 11:09:17 -08:00
bors
3f33b30e19 Auto merge of #135760 - scottmcm:disjoint-bitor, r=WaffleLapkin
Add `unchecked_disjoint_bitor` per ACP373

Following the names from libs-api in https://github.com/rust-lang/libs-team/issues/373#issuecomment-2085686057

Includes a fallback implementation so this doesn't have to update cg_clif or cg_gcc, and overrides it in cg_llvm to use `or disjoint`, which [is available in LLVM 18](https://releases.llvm.org/18.1.0/docs/LangRef.html#or-instruction) so hopefully we don't need any version checks.
2025-02-04 17:46:06 +00:00
Ralf Jung
04e7a10af6 intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic 2025-02-04 16:27:29 +01:00
bors
01e4f19cc8 Auto merge of #136534 - jhpratt:rollup-dnz57dq, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - #136398 (add UnsafeCell direct access APIs)
 - #136465 (Some `rustc_middle` cleanups)
 - #136479 (std::fs: further simplify dirent64 handling)
 - #136504 (Fix last compare-mode false negatives in tests)
 - #136511 (Add `cast_signed` and `cast_unsigned` methods for `NonZero` types)
 - #136518 (Add note about `FnPtr` trait being exposed as public bound)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-04 14:59:25 +00:00
bors
7b31983d55 Auto merge of #136533 - jhpratt:rollup-s0ign8n, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #134777 (Enable more tests on Windows)
 - #135621 (Move some std tests to integration tests)
 - #135844 ( Add new tool for dumping feature status based on tidy )
 - #136167 (Implement unstable `new_range` feature)
 - #136334 (Extract `core::ffi` primitives to a separate (internal) module)

Failed merges:

 - #136201 (Removed dependency on the field-offset crate, alternate approach)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-04 12:13:02 +00:00
Jacob Pratt
af178aa806
Rollup merge of #136518 - Urgau:fn_ptr-public-bound, r=Noratrieb
Add note about `FnPtr` trait being exposed as public bound
2025-02-04 05:38:06 -05:00
Jacob Pratt
5178a3630e
Rollup merge of #136511 - joshtriplett:nonzero-cast-signed-unsigned, r=dtolnay
Add `cast_signed` and `cast_unsigned` methods for `NonZero` types

Requested in https://github.com/rust-lang/rust/issues/125882 .

Note that this keeps the same names as the methods currently present on other
integer types. If we want to rename them, we can rename them all at the same
time.
2025-02-04 05:38:05 -05:00
Jacob Pratt
d89e98dcbf
Rollup merge of #136398 - pitaj:unsafecell_access, r=dtolnay
add UnsafeCell direct access APIs

- Implementation for ACP: https://github.com/rust-lang/libs-team/issues/521
- Tracking issue #136327
2025-02-04 05:38:03 -05:00
Jacob Pratt
54f9ef9eda
Rollup merge of #136334 - ricci009:primitivers, r=tgross35
Extract `core::ffi` primitives to a separate (internal) module

### Introduce library/core/src/ffi/primitives.rs

The regex preprocessing for PR #133944 would be more robust if the relevant types from core/src/ffi/mod.rs were first moved to library/core/src/ffi/primitives.rs, then there isn't a need to deal with traits / c_str / va_list / whatever might wind up in that module in the future

r? `@tgross35`
2025-02-04 05:36:53 -05:00
Jacob Pratt
d31e137d6a
Rollup merge of #136167 - pitaj:new_range, r=Nadrieril
Implement unstable `new_range` feature

Switches `a..b`, `a..`, and `a..=b` to resolve to the new range types.

For rust-lang/rfcs#3550
Tracking issue #123741

also adds the re-export that was missed in the original implementation of `new_range_api`
2025-02-04 05:36:52 -05:00
bors
019fc4de2f Auto merge of #135265 - pascaldekloe:fmt-int-speed, r=tgross35,ChrisDenton
Display of integers without raw pointers and without overflowing_literals

The benchmarks as is measure formatting speed of literals. The first commit `black_box`-es input to simulate runtime speed instead.

The second commit replaces `unsafe` pointer optimizations with plain array indices. The performance is equivalent on Apple M1. Needs peer review on Intel.

Happy to do the 128-bit version too if such change is welcome.
2025-02-04 09:15:53 +00:00