Commit Graph

10012 Commits

Author SHA1 Message Date
bors cd14b73b4a Auto merge of #154459 - tgross35:destabilize-range-iter-remainder, r=scottmcm
core: Destabilize beta-stable `RangeInclusiveIter::remainder`



Destabilize `RangeInclusiveIter::remainder` and move `{RangeIter,RangefromIter}::remainder` to the `new_range_api` feature gate.

Original tracking issue: https://github.com/rust-lang/rust/issues/125687
New tracking issue: https://github.com/rust-lang/rust/issues/154458
Discussion: https://rust-lang.zulipchat.com/#narrow/channel/327149-t-libs-api.2Fapi-changes/topic/.60RangeFrom.3A.3Aremainder.60.20possible.20panic/with/582108913
2026-03-29 16:22:03 +00:00
Trevor Gross 0bb3fe315e core: Move {RangeIter, RangeFromIter}::remainder to new_range_remainder
Split the remainder functions from the rest of `std::range`.
2026-03-29 02:11:32 -05:00
Jonathan Brouwer e32b188e72 Rollup merge of #154512 - GrigorenkoPV:alignment/const, r=scottmcm
Constify comparisons and `Clone` for `core::mem::Alignment`

As suggested in https://github.com/rust-lang/rust/pull/153261#issuecomment-4136817185
2026-03-29 08:59:37 +02:00
Jonathan Brouwer df5f98513b Rollup merge of #154190 - Jules-Bertholet:nonfused, r=scottmcm
Don't fuse in `MapWindows`

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

Fusing makes the iterator larger, slower, more complicated, and less useful. Users who need fusing behavior can always use `.fuse()`, but there is no way to get non-fusing behavior from the fused version.

@rustbot label A-iterators
2026-03-29 08:59:36 +02:00
Trevor Gross cbc94349d0 core: Destabilize beta-stable RangeInclusiveIter::remainder
As discussed, make this portion of the range API unstable again. This
will now be tracked under `new_range_remainder`.

Discussion: https://rust-lang.zulipchat.com/#narrow/channel/327149-t-libs-api.2Fapi-changes/topic/.60RangeFrom.3A.3Aremainder.60.20possible.20panic/with/582108913
2026-03-29 01:58:50 -05:00
Guillaume Gomez 67ab3ac423 Rollup merge of #154043 - RalfJung:simd-min-max, r=Amanieu,calebzulawski,antoyo
simd_fmin/fmax: make semantics and name consistent with scalar intrinsics

This is the SIMD version of https://github.com/rust-lang/rust/pull/153343: change the documented semantics of the SIMD float min/max intrinsics to that of the scalar intrinsics, and also make the name consistent. The overall semantic change this amounts to is that we restrict the non-determinism: the old semantics effectively mean "when one input is an SNaN, the result non-deterministically is a NaN or the other input"; the new semantics say that in this case the other input must be returned. For all other cases, old and new semantics are equivalent. This means all users of these intrinsics that were correct with the old semantics are still correct: the overall set of possible behaviors has become smaller, no new possible behaviors are being added.

In terms of providers of this API:
- Miri, GCC, and cranelift already implement the new semantics, so no changes are needed.
- LLVM is adjusted to use `minimumnum nsz` instead of `minnum`, thus giving us the new semantics.

In terms of consumers of this API:
- Portable SIMD almost certainly wants to match the scalar behavior, so this is strictly a bugfix here.
- Stdarch mostly stopped using the intrinsic, except on nvptx, where arguably the new semantics are closer to what we actually want than the old semantics (https://github.com/rust-lang/stdarch/issues/2056).

Q: Should there be an `f` in the intrinsic name to indicate that it is for floats? E.g., `simd_fminimum_number_nsz`?

Also see https://github.com/rust-lang/rust/issues/153395.
2026-03-29 00:06:50 +01:00
Guillaume Gomez e6f17e4bbb Rollup merge of #153834 - N1ark:generic-float-intrinsics, r=tgross35,RalfJung
Merge `fabsf16/32/64/128` into `fabs::<F>`

Following [a small conversation on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Float.20intrinsics/with/521501401) (and because I'd be interested in starting to contribute on Rust), I thought I'd give a try at merging the float intrinsics :)

This PR just merges `fabsf16`, `fabsf32`, `fabsf64`, `fabsf128`, as it felt like an easy first target.

Notes:
- I'm opening the PR for one intrinsic as it's probably easier if the shift is done one intrinsic at a time, but let me know if you'd rather I do several at a time to reduce the number of PRs.
- Currently this PR increases LOCs, despite being an attempt at simplifying the intrinsics/compilers. I believe this increase is a one time thing as I had to define new functions and move some things around, and hopefully future PRs/commits will reduce overall LoCs
- `fabsf32` and `fabsf64` are `#[rustc_intrinsic_const_stable_indirect]`, while `fabsf16` and `fabsf128` aren't; because `f32`/`f64` expect the function to be const, the generic version must be made indirectly stable too. We'd need to check with T-lang this change is ok; the only other intrinsics where there is such a mismatch is `minnum`, `maxnum` and `copysign`.
- I haven't touched libm because I'm not familiar with how it works; any guidance would be welcome!
2026-03-29 00:06:50 +01:00
Guillaume Gomez aad3710227 Rollup merge of #153380 - pitaj:stabilize-new_range_from_api, r=tgross35
stabilize new RangeFrom type and iterator

```rust
// in core and std
pub mod range;

// in core::range

pub struct RangeFrom<Idx> {
    pub start: Idx,
}

impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> { /* ... */ }

impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
    pub const fn contains<U>(&self, item: &U) -> bool
    where
        Idx: [const] PartialOrd<U>,
        U: ?Sized + [const] PartialOrd<Idx>;
}

impl<Idx: Step> RangeFrom<Idx> {
    pub fn iter(&self) -> RangeFromIter<Idx>;
}

impl<T> const RangeBounds<T> for RangeFrom<T> { /* ... */ }
impl<T> const RangeBounds<T> for RangeFrom<&T> { /* ... */ }

impl<T> const From<RangeFrom<T>> for legacy::RangeFrom<T> { /* ... */ }
impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { /* ... */ }

pub struct RangeFromIter<A>(/* ... */);

// `RangeFromIter::remainder` left unstable

impl<A: Step> Iterator for RangeFromIter<A> {
    type Item = A;
    /* ... */
}

impl<A: Step> FusedIterator for RangeFromIter<A> { }
impl<A: Step> IntoIterator for RangeFrom<A> {
    type Item = A;
    type IntoIter = RangeFromIter<A>;
    /* ... */
}

unsafe impl<T> const SliceIndex<[T]> for range::RangeFrom<usize> {
    type Output = [T];
    /* ... */
}
unsafe impl const SliceIndex<str> for range::RangeFrom<usize> {
    type Output = str;
    /* ... */
}

impl ops::Index<range::RangeFrom<usize>> for CStr {
    type Output = CStr;
    /* ... */
}
```

Tracking issue: https://github.com/rust-lang/rust/issues/125687
2026-03-29 00:06:49 +01:00
Peter Jaszkowiak 085dff4944 stabilize new RangeFrom type and iterator
stabilizes `core::range::RangeFrom`
stabilizes `core::range::RangeFromIter`

add examples for `remainder` method on range iterators
`RangeFromIter::remainder` was not stabilized (see issue 154458)
2026-03-28 12:00:10 -06:00
Pavel Grigorenko c45bfa8d73 const_clone for core::mem::Alignment 2026-03-28 20:38:43 +03:00
Pavel Grigorenko 219420573b const_cmp for core::mem::Alignment 2026-03-28 20:38:42 +03:00
bors 7e28c7438a Auto merge of #153821 - Lars-Schumann:const-step, r=Mark-Simulacrum
constify `Step` trait and all of its `impl`ementations

constifying [Step](https://github.com/rust-lang/rust/issues/42168) trait and all of its implementations, with some friendly help from [const_cmp](https://github.com/rust-lang/rust/issues/143800)
2026-03-28 10:44:18 +00:00
Stuart Cook 50fe743b9b Rollup merge of #154196 - Jules-Bertholet:ipv6-multicast-discriminant, r=Mark-Simulacrum
Make `Ipv6Addr::multicast_scope()` exhaustive

And make `Ipv6MulticastScope` exhaustive, with `repr(u8)` and the proper discriminant values. The variants for the two reserved scopes are gated behind a perma-unstable feature, in order to avoid committing to names for them.

[IETF RFC 4291](https://datatracker.ietf.org/doc/html/rfc4291#section-2.7) and [IETF RFC 7346](https://datatracker.ietf.org/doc/html/rfc7346#section-2) define the list of multicast scopes. The former document says:

> scopes labeled "(unassigned)" are available for administrators to define additional multicast regions.

Tracking issue: https://github.com/rust-lang/rust/issues/27709
@rustbot label A-io
2026-03-28 15:01:38 +11:00
Jules Bertholet 4ca6328536 Remove repr(u8) 2026-03-27 18:50:08 -04:00
Jacob Pratt f229fc0e77 Rollup merge of #153675 - RalfJung:simd-overflow, r=scottmcm
simd_add/sub/mul/neg: document overflow behavior

`simd_neg` had an odd comment about overflow not being UB, without saying what the behavior is instead. Replace that by just saying this uses wrapping arithmetic, and add the same for add/sub/mul. div/rem are already documented to cause UB on div-by-zero and min-div-by-minus-one, and shl/shr cause UB on too large shift amounts.
2026-03-27 02:30:08 -04:00
bors ac40f5e105 Auto merge of #154004 - GrigorenkoPV:alignment/as_nonzero_usize, r=scottmcm
`Alignment`: move from `ptr` to `mem` and rename `as_nonzero` to `as_nonzero_usize`



- tracking issue: rust-lang/rust#102070
- split off from rust-lang/rust#153261
2026-03-27 01:25:29 +00:00
Tim (Theemathas) Chirananthavat 91e4524bfe Link from assert_matches to debug_assert_matches
This resolves a FIXME which was added in
https://github.com/rust-lang/rust/pull/151423.
2026-03-26 12:12:53 +07:00
Jonathan Brouwer bd919a0ee7 Rollup merge of #154288 - Jules-Bertholet:patch-2, r=JohnTitor
Fix typo in doc comment for `char::to_titlecase`

@rustbot label A-docs
2026-03-25 19:53:00 +01:00
Jonathan Brouwer 4783d35218 Rollup merge of #154216 - airblast-dev:main, r=tgross35
unstably mark `NonNull::with_exposed_provenance` as const

Feature: `const_nonnull_with_exposed_provenance`
Tracking issue: https://github.com/rust-lang/rust/issues/154215

This PR constifies `NonNull::with_exposed_provenance`.

r? @tgross35
2026-03-25 19:52:58 +01:00
Pavel Grigorenko ba1e06a722 core::mem::Alignemnt: rename as_nonzero to as_nonzero_usize 2026-03-25 16:18:33 +03:00
Pavel Grigorenko f8d658ab81 core: move Alignment from ptr to mem 2026-03-25 16:18:33 +03:00
Theemathas Chirananthavat f55c8cca4c Rewrite safety comment for PinCoerceUnsized 2026-03-25 11:40:27 +07:00
Theemathas Chirananthavat 1e4c1d6f75 Make PinCoerceUnsized require Deref
Also, delete impls on non-Deref types.

Pin doesn't do anything useful for non-Deref types, so PinCoerceUnsized
on such types makes no sense.

This is a breaking change, since stable code can observe the deleted
`PinCoerceUnsized` impls by uselessly coercing between such types
inside a `Pin`.

There is still some strange behavior, such as `Pin<&mut i32>` being
able to coerce to `Pin<&dyn Send>`, but not being able to coerce to
`Pin<&i32>`. However, I don't think it's possible to fix this.

Fixes https://github.com/rust-lang/rust/issues/145081
2026-03-25 11:40:27 +07:00
Jonathan Brouwer f9f6c97d8b Rollup merge of #154311 - GuillaumeGomez:fix-integer-doc-cfg, r=eggyal,tgross35
[libcore] Disable `doc(auto_cfg)` for integers trait impls

Fixes rust-lang/rust#153655.

Thanks to https://github.com/rust-lang/rust/pull/153964, `doc(auto_cfg)` finally works as expected on impls. So now this fix works:

<img width="1000" height="806" alt="image" src="https://github.com/user-attachments/assets/f37da375-c2eb-4a7b-abf2-1fdd3a73e2bb" />

cc @eggyal
2026-03-24 22:36:56 +01:00
Guillaume Gomez 24295bf7ae Disable doc(auto_cfg) for integers trait impls 2026-03-24 14:23:41 +01:00
Jonathan Brouwer fad2a35ebf Rollup merge of #154133 - bjorn3:va_list_drop_defer_codegen, r=nnethercote
Defer codegen for the VaList Drop impl to actual uses

This allows compiling libcore with codegen backends that don't actually implement VaList like cg_clif.
2026-03-24 10:54:04 +01:00
bjorn3 366cf883c7 Add comments 2026-03-24 10:01:46 +01:00
Jacob Pratt 04f63328d6 Rollup merge of #154153 - tgross35:funnel-unchecked, r=Mark-Simulacrum
core: Implement `unchecked_funnel_{shl,shr}`

These methods are just wrappers around the intrinsics.

Tracking issue: https://github.com/rust-lang/rust/issues/145686
2026-03-23 23:42:50 -04:00
Jules Bertholet af6324a90f Fix typo in doc comment for char::to_titlecase 2026-03-23 22:25:09 -04:00
Jules Bertholet ebb91f735b Make Ipv6Addr::multicast_scope() exhaustive
And make `Ipv6MulticastScope` exhaustive,
with `repr(u8)` and the proper discriminant values.
The variants for the two reserved scopes
are gated behind a perma-unstable feature,
in order to avoid committing to names for them.

[IETF RFC 4291](https://datatracker.ietf.org/doc/html/rfc4291#section-2.7)
and [IETF RFC 7346](https://datatracker.ietf.org/doc/html/rfc7346#section-2)
define the list of multicast scopes.
The former document says:

> scopes labeled "(unassigned)" are available for administrators
> to define additional multicast regions.
2026-03-23 17:46:09 -04:00
Jonathan Brouwer 3cad6d130a Rollup merge of #122668 - Jules-Bertholet:titlecase, r=Mark-Simulacrum
Add APIs for dealing with titlecase

ACP: https://github.com/rust-lang/libs-team/issues/354
Tracking issue: https://github.com/rust-lang/rust/issues/153892

r? libs-api

@rustbot label T-libs -T-libs-api A-unicode

~~The last commit has some insta-stable `PartialEq` impls, therefore: @rustbot label -needs-fcp
Alternatively, I could split those out into a follow-up PR.~~ (Edit: will do in follow-up)
2026-03-23 20:18:32 +01:00
bors eb9d3caf05 Auto merge of #154253 - JonathanBrouwer:rollup-LLZUsz2, r=JonathanBrouwer
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#154241 (`rust-analyzer` subtree update)
 - rust-lang/rust#153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets)
 - rust-lang/rust#154105 (bootstrap: Pass `--features=rustc` to rustc_transmute)
 - rust-lang/rust#153069 ([BPF] add target feature allows-misaligned-mem-access)
 - rust-lang/rust#154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer)
 - rust-lang/rust#154191 (refactor RangeFromIter overflow-checks impl)
 - rust-lang/rust#154207 (Refactor query loading)
 - rust-lang/rust#153540 (drop derive helpers during attribute parsing)
 - rust-lang/rust#154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.)
 - rust-lang/rust#154161 (On E0277 tweak help when single type impls traits)
 - rust-lang/rust#154218 (interpret/validity: remove unreachable error kind)
 - rust-lang/rust#154225 (diagnostics: avoid ICE in confusable_method_name for associated functions)
 - rust-lang/rust#154228 (Improve inline assembly error messages)
2026-03-23 15:46:13 +00:00
Jonathan Brouwer cd3e866c7a Rollup merge of #153880 - asder8215:intersperse_nonfused, r=Mark-Simulacrum
Lifted intersperse and intersperse_with Fused transformation and updated documentation + tests

This PR once again builds on top of rust-lang/rust#152855. From the discussion in rust-lang/rust#152855, libs team came to the conclusion that `intersperse`/`intersperse_with` shouldn't transform the given iterator to a fused iterator always and a separator should be emitted between `Some(_)` items for non fused iterators (particularly just right before the subsequent `Some(_)`).

On top of the change Zakarumych added in the PR, I lifted the `FusedIterator` trait and transformation of the inner `iter` for `Intersperse`/`IntersperseWith`, so that we can display this behavior. I've adjusted the documentation and tests accordingly to reflect this change as well.

r? @jhpratt
2026-03-23 12:14:54 +01:00
Jonathan Brouwer 452af7ed94 Rollup merge of #154140 - theemathas:checks_always_on_in_const, r=RalfJung
Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.
2026-03-23 12:01:01 +01:00
Jonathan Brouwer 61b4c77781 Rollup merge of #154191 - pitaj:fix-154124, r=tgross35
refactor RangeFromIter overflow-checks impl

Crates with different overflow-checks settings accessing the same RangeFromIter resulted in incorrect values being yielded

Fixes rust-lang/rust#154124

r? @tgross35
2026-03-23 12:00:59 +01:00
Tim (Theemathas) Chirananthavat 338deef451 Remove outdated consteval docs for is_val_statically_known.
We've already stabilized float operations in const,
which means we've already accepted that a `const fn`
might behave differently in consteval vs at run time.
2026-03-23 10:56:33 +07:00
Tim (Theemathas) Chirananthavat 8dcb2578e2 Document consteval behavior of ub_checks & overflow_checks. 2026-03-23 10:55:10 +07:00
Peter Jaszkowiak 8befc9d082 refactor RangeFromIter overflow-checks impl
Crates with different overflow-checks settings accessing the same RangeFromIter resulted in incorrect values being yielded
2026-03-22 13:31:50 -06:00
Tayfun Bocek 1223441926 Constify NonNull::with_exposed_provenance 2026-03-22 17:28:41 +03:00
Jules Bertholet 0a49163be7 Don't fuse in MapWindows 2026-03-21 18:16:51 -04:00
Jules Bertholet 8d072616a5 Add APIs for dealing with titlecase
- `char::is_cased`
- `char::is_titlecase`
- `char::case`
- `char::to_titlecase`
2026-03-21 14:30:38 -04:00
Jonathan Brouwer 70d1c586ce Rollup merge of #154118 - malezjaa:dont-suggest-some-traits-for-unions, r=JonathanBrouwer
don't suggest non-deriveable traits for unions

Fixes rust-lang/rust#137587

Before, the compiler suggested adding `#[derive(Debug)]` (other traits too) for unions,
which is misleading because some traits can't be automatically derived.

Only traits that are still suggested are Copy and Clone.

I noticed the error label changed after removing the suggestion. I hope this isn't a big deal, but let me know if that's an issue.

original example:
```rs
union Union {
    member: usize,
}

impl PartialEq<u8> for Union {
    fn eq(&self, rhs: &u8) -> bool {
        unsafe { self.member == (*rhs).into() }
    }
}

fn main() {
    assert_eq!(Union { member: 0 }, 0);
}
```

before:
```
error[E0277]: `Union` doesn't implement `Debug`
  --> src\main.rs:13:5
   |
13 |     assert_eq!(Union { member: 0 }, 0);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `Union`
   |
   = note: add `#[derive(Debug)]` to `Union` or manually `impl Debug for Union`
   = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `Union` with `#[derive(Debug)]`
   |
 2 + #[derive(Debug)]
 3 | union Union {
   |
```

after (the message doesn't suggest adding #[derive(Debug)] to unions)
```
error[E0277]: `Union` doesn't implement `Debug`
  --> src\main.rs:13:5
   |
13 |     assert_eq!(Union { member: 0 }, 0);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Debug` is not implemented for `Union`
  --> src\main.rs:2:1
   |
 2 | union Union {
   | ^^^^^^^^^^^
   = note: manually `impl Debug for Union`
```
2026-03-21 00:42:48 +01:00
malezjaa 27212bb09d Don't suggest non-deriveable traits for unions.
Don't suggest non-deriveable traits for unions. This also adds enum, struct and union markers to rustc_on_unimplemented
2026-03-20 23:39:28 +01:00
Trevor Gross d54cf8f40a core: Implement unchecked_funnel_{shl,shr}
These methods are just wrappers around the intrinsics.
2026-03-20 14:59:42 -04:00
bjorn3 0b69ff5074 Defer codegen for the VaList Drop impl to actual uses
This allows compiling libcore with codegen backends that don't actually
implement VaList like cg_clif.
2026-03-20 11:48:36 +01:00
Stuart Cook 83d921de92 Rollup merge of #154019 - cyrgani:feature-clean, r=joboet
two smaller feature cleanups

Remove an unneeded feature gate for a private macro and sort the used features correctly by whether they are language or library features.
2026-03-20 15:33:07 +11:00
Jonathan Brouwer 793d1c9a2e Rollup merge of #153804 - DanielEScherzer:derive-eq-docs, r=Mark-Simulacrum
Derive Macro Eq: link to more detailed documentation

Match the other derive macros in the module (Ord, PartialEq, PartialOrd) by linking to the section in the trait documentation about how the derive macro works.
2026-03-19 13:42:36 +01:00
Jonathan Brouwer 7c6fc44b7c Rollup merge of #151905 - tgross35:dec2flt-traits, r=Mark-Simulacrum
Split the `dec2flt::RawFloat` trait for easier reuse

`RawFloat` is an internal trait with quite a few useful float properties. It currently resides in the `dec2flt` module but is also used in parsing, and would be nice to reuse other places. Unfortunately it cannot be implemented on `f128` because of limitations with how the parsing API is implemented (mantissa must fit into a u64).

To make the trait easier to work with, split it into the following:

* `Float`: Anything that is reasonably applicable to all floating point types.
* `FloatExt`: Items that should be part of `Float` but don't work for all float types. This will eventually be merged back into `Float` once it can be implemented on f128.
* `Lemire`: Items that are specific to the Lemire dec2flt algorithm.

These traits are then moved to places that make sense.

Builds on top of https://github.com/rust-lang/rust/pull/151900
2026-03-19 13:42:32 +01:00
Jonathan Brouwer f7ac53b661 Rollup merge of #154077 - jhpratt:optimize-128-bit-formatting, r=dtolnay
Optimize 128-bit integer formatting

The compiler is unaware of the restricted range of the input, so it is unable to optimize out the final division and modulus. By doing this manually, we get a nontrivial performance gain.

r? @dtolnay

(copied from https://github.com/dtolnay/itoa/pull/68)
2026-03-19 13:42:30 +01:00
bors 8b86f48958 Auto merge of #153480 - RaphiMuehlbacher:track-caller, r=Mark-Simulacrum
Add missing `track_caller` to overflowing trait methods

Fixes rust-lang/rust#152599 by adding `#[track_caller]` to arithmetic trait methods (`Neg`, `Shl`, `ShlAssign`, `Shr` and `ShrAssign`) so overflow panics report the correct call site instead of the trait definition.
2026-03-19 05:52:42 +00:00