Commit Graph

8538 Commits

Author SHA1 Message Date
Christopher Durham
2e5a76cd1e Use cfg_match in core 2025-03-26 14:32:35 -04:00
Jacob Pratt
deb987b69d
Rollup merge of #138945 - DaniPopes:override-partialord-bool, r=scottmcm
Override PartialOrd methods for bool

I noticed that `PartialOrd` implementation for `bool` does not override the individual operator methods, unlike the other primitive types like `char` and integers.

This commit extracts these `PartialOrd` overrides shared by the other primitive types into a macro and calls it on `bool` too.

CC `@scottmcm` for our recent adventures in `PartialOrd` land
2025-03-25 20:34:50 -04:00
DaniPopes
154cb083e7
Override PartialOrd methods for bool
I noticed that `PartialOrd` implementation for `bool` does not override the
individual operator methods, unlike the other primitive types like `char`
and integers.

This commit extracts these `PartialOrd` overrides shared by the other
primitive types into a macro and calls it on `bool` too.
2025-03-25 21:02:55 +01:00
Matthias Krüger
5f6c1a9f57
Rollup merge of #135745 - bardiharborow:std/net/rfc9602, r=cuviper
Recognise new IPv6 non-global range from IETF RFC 9602

This PR adds the `5f00::/16` range defined by [IETF RFC 9602](https://datatracker.ietf.org/doc/rfc9602/) to those ranges which `Ipv6Addr::is_global` recognises as a non-global IP. This range is used for Segment Routing (SRv6) SIDs.

See also: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
Unstable tracking issue: #27709
2025-03-25 18:09:03 +01:00
Jacob Pratt
1ba9b7873a
Rollup merge of #138135 - scottmcm:chaining-ord, r=Mark-Simulacrum
Simplify `PartialOrd` on tuples containing primitives

We noticed in https://github.com/rust-lang/rust/pull/133984#issuecomment-2704011800 that currently the tuple comparison code, while it [does optimize down](https://github.com/rust-lang/rust/blob/master/tests/codegen/comparison-operators-2-tuple.rs) today, is kinda huge: <https://rust.godbolt.org/z/xqMoeYbhE>

This PR changes the tuple code to go through an overridable "chaining" version of the comparison functions, so that for simple things like `(i16, u16)` and `(f32, f32)` (as seen in the new MIR pre-codegen test) we just directly get the
```rust
if lhs.0 == rhs.0 { lhs.0 OP rhs.0 }
else { lhs.1 OP rhs.1 }
```
version in MIR, rather than emitting a mess for LLVM to have to clean up.

Test added in the first commit, so you can see the MIR diff in the second one.
2025-03-23 20:44:09 -04:00
Scott McMurray
7781346243 Stop using specialization for this
Uses `__`-named `doc(hidden)` methods instead.
2025-03-23 15:27:31 -07:00
Michael Goulet
1e023420f9
Rollup merge of #138854 - TaKO8Ki:invalid-extern-fn-body, r=compiler-errors
Fix ICE #138415 for invalid extern function body

Fixes #138415
2025-03-23 14:59:35 -04:00
Michael Goulet
145fe2d648
Rollup merge of #136040 - mu001999-contrib:cleanup, r=Mark-Simulacrum
Remove unused trait BoundedSize

Detected by #128637

The usage of this trait is removed in #135104

r? `@the8472`
2025-03-23 14:59:29 -04:00
Takayuki Maeda
34b7d51b95 fix typo 2025-03-23 17:47:10 +09:00
bors
f08d5c01e6 Auto merge of #138833 - joboet:optimize-repeat-n, r=thomcc
core: optimize `RepeatN`

...by adding an optimized implementation of `try_fold` and `fold` as well as replacing some unnecessary `mem::replace` calls with `MaybeUninit` helper methods.
2025-03-23 03:11:13 +00:00
bors
b48576b4db Auto merge of #138831 - matthiaskrgr:rollup-3t0dqiz, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138609 (Add stack overflow handler for cygwin)
 - #138639 (Clean UI tests 2 of n)
 - #138773 (catch_unwind intrinsic: document return value)
 - #138782 (test(ui): add tuple-struct-where-clause-suggestion ui test for #91520)
 - #138794 (expand: Do not report `cfg_attr` traces on macros as unused attributes)
 - #138801 (triagebot: add autolabel rules for D-* and L-*)
 - #138804 (Allow inlining for `Atomic*::from_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-22 20:52:30 +00:00
joboet
51d51c8666
core: optimize RepeatN
...by adding an optimized implementation of `try_fold` and `fold` as well as replacing some unnecessary `mem::replace` calls with `MaybeUninit` helper methods.
2025-03-22 13:35:46 +01:00
Matthias Krüger
2644500bff
Rollup merge of #138804 - tgross35:atomic-from-ptr-inline, r=RalfJung
Allow inlining for `Atomic*::from_ptr`

Currently this cannot be inlined, which among other things means it can't be used in `compiler-builtins` [1]. These are trivial functions that should be inlineable, so add `#[inline]`.

[1]: https://github.com/rust-lang/compiler-builtins/pull/790#issuecomment-2744371738
2025-03-22 12:00:51 +01:00
Matthias Krüger
ca86dd5036
Rollup merge of #138773 - RalfJung:catch_unwind_docs, r=jhpratt
catch_unwind intrinsic: document return value

Seems like we forgot to document this. The comment reflects what Miri does, which seems to also match what codegen does at least [in `codegen_gnu_try`](b754ef727c/compiler/rustc_codegen_llvm/src/intrinsic.rs (L953-L964)).
2025-03-22 12:00:49 +01:00
bors
0ce1369bde Auto merge of #136974 - m-ou-se:fmt-options-64-bit, r=scottmcm
Reduce FormattingOptions to 64 bits

This is part of https://github.com/rust-lang/rust/issues/99012

This reduces FormattingOptions from 6-7 machine words (384 bits on 64-bit platforms, 224 bits on 32-bit platforms) to just 64 bits (a single register on 64-bit platforms).

Before:

```rust
pub struct FormattingOptions {
    flags: u32, // only 6 bits used
    fill: char,
    align: Option<Alignment>,
    width: Option<usize>,
    precision: Option<usize>,
}
```

After:

```rust
pub struct FormattingOptions {
    /// Bits:
    ///  - 0-20: fill character (21 bits, a full `char`)
    ///  - 21: `+` flag
    ///  - 22: `-` flag
    ///  - 23: `#` flag
    ///  - 24: `0` flag
    ///  - 25: `x?` flag
    ///  - 26: `X?` flag
    ///  - 27: Width flag (if set, the width field below is used)
    ///  - 28: Precision flag (if set, the precision field below is used)
    ///  - 29-30: Alignment (0: Left, 1: Right, 2: Center, 3: Unknown)
    ///  - 31: Always set to 1
    flags: u32,
    /// Width if width flag above is set. Otherwise, always 0.
    width: u16,
    /// Precision if precision flag above is set. Otherwise, always 0.
    precision: u16,
}
```
2025-03-22 10:56:14 +00:00
Trevor Gross
eb2a2f86bb Allow inlining for Atomic*::from_ptr
Currently this cannot be inlined, which among other things means it
can't be used in `compiler-builtins` [1]. These are trivial functions
that should be inlineable, so add `#[inline]`.

[1]: https://github.com/rust-lang/compiler-builtins/pull/790#issuecomment-2744371738
2025-03-21 20:51:06 +00:00
Mara Bos
9b7060ad31 Add todo comment on using a niche type for fmt flags. 2025-03-21 17:05:56 +01:00
Matthias Krüger
7c2475e9aa
Rollup merge of #138717 - jdonszelmann:pin-macro, r=WaffleLapkin
Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it

Fixes a regression, see issue below. This is a temporary fix, super let is the real solution.

Closes #138596
2025-03-21 15:48:57 +01:00
Ralf Jung
244e92ba5c catch_unwind intrinsic: document return value 2025-03-21 10:33:47 +01:00
Bardi Harborow
ea99e81485 Recognise new IPv6 non-global range from RFC9602
This commit adds the 5f00::/16 range defined by RFC9602 to those ranges which Ipv6Addr::is_global recognises as a non-global IP. This range is used for Segment Routing (SRv6) SIDs.
2025-03-21 17:53:29 +11:00
Matthias Krüger
809378bd2e
Rollup merge of #138650 - thaliaarchi:io-write-fmt-known, r=ibraheemdev
Optimize `io::Write::write_fmt` for constant strings

When the formatting args to `fmt::Write::write_fmt` are a statically known string, it simplifies to only calling `write_str` without a runtime branch. Do the same in `io::Write::write_fmt` with `write_all`.

Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-21 06:56:46 +01:00
Jana Dönszelmann
7c085f7ffd
add rustc_macro_edition_2021 2025-03-19 17:37:35 +01:00
Scott McMurray
35248c6830 Add chaining versions of lt/le/gt/ge and use them in tuple PartialOrd 2025-03-19 09:27:02 -07:00
Matthias Krüger
2df731d586
Rollup merge of #138540 - okaneco:const_split_off_first_last, r=m-ou-se
core/slice: Mark some `split_off` variants unstably const

Tracking issue: #138539

Add feature gate `#![feature(const_split_off_first_last)]`
Mark `split_off_first`, `split_off_first_mut`, `split_off_last`, and `split_off_last_mut` slice methods unstably const
2025-03-19 16:52:55 +01:00
Matthias Krüger
d46cc71f54
Rollup merge of #135394 - clarfonthey:uninit-slices-part-2, r=tgross35
`MaybeUninit` inherent slice methods part 2

These were moved out of #129259 since they require additional libs-api approval. Tracking issue: #117428.

New API surface:

```rust
impl<T> [MaybeUninit<T>] {
    // replacing fill; renamed to avoid conflict
    pub fn write_filled(&mut self, value: T) -> &mut [T] where T: Clone;

    // replacing fill_with; renamed to avoid conflict
    pub fn write_with<F>(&mut self, value: F) -> &mut [T] where F: FnMut() -> T;

    // renamed to remove "fill" terminology, since this is closer to the write_*_of_slice methods
    pub fn write_iter<I>(&mut self, iter: I) -> (&mut [T], &mut Self) where I: Iterator<Item = T>;
}
```

Relevant motivation for these methods; see #129259 for earlier methods' motiviations.

* I chose `write_filled` since `filled` is being used as an object here, whereas it's being used as an action in `fill`.
* I chose `write_with` instead of `write_filled_with` since it's shorter and still matches well.
* I chose `write_iter` because it feels completely different from the fill methods, and still has the intent clear.

In all of the methods, it felt appropriate to ensure that they contained `write` to clarify that they are effectively just special ways of doing `MaybeUninit::write` for each element of a slice.

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

r? libs-api
2025-03-19 16:52:52 +01:00
bendn
7a8cdf00e6
use then 2025-03-19 10:45:42 +07:00
Thalia Archibald
a0c3dd4df4 Optimize io::Write::write_fmt for constant strings
When the formatting args to `fmt::Write::write_fmt` are a statically
known string, it simplifies to only calling `write_str` without a
runtime branch. Do the same in `io::Write::write_fmt` with `write_all`.

Also, match the convention of `fmt::Write` for the name of `args`.
2025-03-18 01:40:27 -07:00
Matthias Krüger
9adf2189f5
Rollup merge of #137449 - compiler-errors:control-flow, r=Amanieu,lnicola
Denote `ControlFlow` as `#[must_use]`

I've repeatedly hit bugs in the compiler due to `ControlFlow` not being marked `#[must_use]`. There seems to be an accepted ACP to make the type `#[must_use]` (https://github.com/rust-lang/libs-team/issues/444), so this PR implements that part of it.

Most of the usages in the compiler that trigger this new warning are "root" usages (calling into an API that uses control-flow internally, but for which the callee doesn't really care) and have been suppressed by `let _ = ...`, but I did legitimately find one instance of a missing `?` and one for a never-used `ControlFlow` value in #137448.

Presumably this needs an FCP too, so I'm opening this and nominating it for T-libs-api.

This PR also touches the tools (incl. rust-analyzer), but if this went into FCP, I'd split those out into separate PRs which can land before this one does.

r? libs-api
`@rustbot` label: T-libs-api I-libs-api-nominated
2025-03-17 16:34:47 +01:00
bors
10bcdad7df Auto merge of #138583 - jhpratt:rollup-h699hty, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #136293 (document capacity for ZST as example)
 - #136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove)
 - #136816 (refactor `notable_traits_button` to use iterator combinators  instead of for loop)
 - #138552 (Misc print request handling cleanups + a centralized test for print request stability gating)
 - #138573 (Make `_Unwind_Action` a type alias, not enum)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-17 03:45:06 +00:00
Jacob Pratt
feb6cb4132
Rollup merge of #136359 - hkBst:ptr_copy_docs, r=Amanieu
doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove

Fixes #79430
2025-03-16 21:47:42 -04:00
bors
c3dd4eefd6 Auto merge of #138363 - beetrees:f16-f128-integer-convert, r=Amanieu
Add `From<{integer}>` for `f16`/`f128` impls

This PR adds `impl From<{bool,i8,u8}> for f16` and `impl From<{bool,i8,u8,i16,u16,i32,u32}> for f128`.

The `From<{i64,u64}> for f128` impls are left commented out as adding them would allow using `f128` on stable before it is stabilised like in the following example:
```rust
fn f<T: From<u64>>(x: T) -> T { x }

fn main() {
    let x = f(1.0); // the type of the literal is inferred to be `f128`
}
```
None of the impls added in this PR have this issue as they are all, at minimum, also implemented by `f64`.

This PR will need a crater run for the `From<{i32,u32}>` impls, as `f64` is no longer the only float type to implement them (similar to the cause of #125198).

cc `@bjoernager`
r? `@tgross35`

Tracking issue: #116909
2025-03-17 00:33:36 +00:00
Michael Goulet
2439623278 Make ControlFlow must_use 2025-03-16 17:47:56 +00:00
bors
8b87fefd76 Auto merge of #138537 - yotamofek:pr/lib/multi-char-pattern, r=jhpratt
Optimize multi-char string patterns

Uses specialization for `[T]::contains` from #130991 to optimize multi-char patterns in string searches.
Requesting a perf run to see if this actually has an effect 🙏
(I think that adding `char` to the list of types for which the `SliceContains` is specialized is a good idea, even if it doesn't show up on perf - might be helpful for downstream users)
2025-03-16 14:23:18 +00:00
许杰友 Jieyou Xu (Joe)
a23a93cb4e
Rollup merge of #135080 - Enselic:debug-ptr-metadata, r=thomcc
core: Make `Debug` impl of raw pointers print metadata if present

Make Rust pointers appear less magic by including metadata information in their `Debug` output.

This does not break Rust stability guarantees because `Debug` impl are explicitly exempted from stability:
https://doc.rust-lang.org/std/fmt/trait.Debug.html#stability

> ## Stability
>
> Derived `Debug` formats are not stable, and so may change with future Rust versions. Additionally, `Debug` implementations of types provided by the standard library (`std`, `core`, `alloc`, etc.) are not stable, and may also change with future Rust versions.

Note that a regression test is added as a separate commit to make it clear what impact the last commit has on the output.

Closes #128684 because the output of that code now becomes:

```
thread 'main' panicked at src/main.rs:5:5:
assertion `left == right` failed
  left: Pointer { addr: 0x7ffd45c6fc6b, metadata: 5 }
 right: Pointer { addr: 0x7ffd45c6fc6b, metadata: 3 }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
2025-03-16 13:19:51 +08:00
许杰友 Jieyou Xu (Joe)
01bc95417c
Rollup merge of #138329 - scottmcm:assert-hint, r=Mark-Simulacrum
debug-assert that the size_hint is well-formed in `collect`

Closes #137919

In the hopes of helping to catch any future accidentally-incorrect rustc or stdlib iterators (like the ones #137908 accidentally found), this has `Iterator::collect` call `size_hint` and check its `low` doesn't exceed its `Some(high)`.

There's of course a bazillion more places this *could* be checked, but the hope is that this one is a good tradeoff of being likely to catch lots of things while having minimal maintenance cost (especially compared to putting it in *every* container's `from_iter`).
2025-03-16 09:40:07 +08:00
许杰友 Jieyou Xu (Joe)
5b9225070c
Rollup merge of #138323 - kpreid:offset-of-doc, r=Mark-Simulacrum
Expand and organize `offset_of!` documentation.

* Give example of how to get the offset of an unsized tail field (prompted by discussion <https://github.com/rust-lang/rust/pull/133055#discussion_r1986422206>).
* Specify the return type.
* Add section headings.
* Reduce “Visibility is respected…”, to a single sentence.
* Move `offset_of_enum` documentation to unstable book (with link to it).
* Add `offset_of_slice` documentation in unstable book.

r? Mark-Simulacrum
2025-03-16 09:40:07 +08:00
许杰友 Jieyou Xu (Joe)
413600c2de
Rollup merge of #138309 - DiuDiu777:intrinsic-doc-fix, r=thomcc
Add missing doc for intrinsic (Fix PR135334)

The previous [PR135334](https://github.com/rust-lang/rust/pull/135334) mentioned that some of the intrinsic APIs were missing safety descriptions.

Among intrinsic APIs that miss safety specifications, most are related to numerical operations. They might need to be discussed and then seen how to organize.

Apart from them, only a few intrinsics lack safety. So this PR deals with the APIs with non-numerical operations in priority.
2025-03-16 09:40:06 +08:00
许杰友 Jieyou Xu (Joe)
e0846806db
Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc
Remove `#[cfg(not(test))]` gates in `core`

These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-16 09:40:05 +08:00
许杰友 Jieyou Xu (Joe)
4946818306
Rollup merge of #133055 - kpreid:clone-uninit-doc, r=Mark-Simulacrum
Expand `CloneToUninit` documentation.

* Clarify relationship to `dyn` after #133003.
* Add an example of using it with `dyn` as #133003 enabled.
* Replace parameter name `dst` with `dest` to avoid confusion between abbreviations for “DeSTination” and “Dynamically-Sized Type”.
* Add an example of implementing it.
* Add links to Rust Reference for the mentioned concepts.
* Mention that its method should rarely be called.
* Various small corrections.

Please review the `unsafe` code closely, as I am not an expert in the best possible ways to express these operations. (It might also be better to omit the implementation example entirely.)

cc `@zachs18` #126799
2025-03-16 09:40:01 +08:00
okaneco
e1388bfb03 core/slice: Mark some split_off variants unstably const
Introduce feature `const_split_off_first_last`
Mark `split_off_first`, `split_off_first_mut`, `split_off_last`, and
`split_off_last_mut` unstably const
2025-03-15 14:21:47 -04:00
Yotam Ofek
bfe536342f Optimize multi-char string patterns 2025-03-15 14:14:25 +00:00
León Orell Valerian Liehr
c42866f89d
Rollup merge of #138477 - compiler-errors:deny-bikeshed-guaranteed-no-drop, r=lcnr
Deny impls for `BikeshedGuaranteedNoDrop`

r? lcnr
2025-03-14 17:26:36 +01:00
León Orell Valerian Liehr
ffa96fe451
Rollup merge of #138353 - RalfJung:expose-provenance-must-use, r=ibraheemdev
remove must_use from <*const T>::expose_provenance

`<*mut T>::expose_provenance` does not have this attribute, and in fact the function is documented to have a side-effect, so there are perfectly legitimate use-cases where the return value would be ignored.
2025-03-14 17:26:20 +01:00
bors
f7b4354283 Auto merge of #138480 - jhpratt:rollup-y3b8wu5, r=jhpratt
Rollup of 16 pull requests

Successful merges:

 - #136001 (Overhaul examples for PermissionsExt)
 - #136230 (Reword incorrect documentation about SocketAddr having varying layout)
 - #136892 (Sync Fuchsia target spec with clang Fuchsia driver)
 - #136911 (Add documentation URL to selected jobs)
 - #137870 ( Improve HashMap docs for const and static initializers)
 - #138179 (Add `src/tools/x` to the main workspace)
 - #138389 (use `expect` instead of `allow`)
 - #138396 (Enable metrics and verbose tests in PR CI)
 - #138398 (atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance)
 - #138432 (fix: remove the check of lld not supporting `@response-file)`
 - #138434 (Visit `PatField` when collecting lint levels)
 - #138441 (update error message)
 - #138442 (EUV: fix place of deref pattern's interior's scrutinee)
 - #138457 (Remove usage of legacy scheme paths on RedoxOS)
 - #138461 (Remove an outdated line from a test comment)
 - #138466 (Remove myself from libs review)

Failed merges:

 - #138452 (Remove `RUN_CHECK_WITH_PARALLEL_QUERIES`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-14 07:02:26 +00:00
Jacob Pratt
91e4bab25f
Rollup merge of #138398 - RalfJung:atomic-intrinsics-provenance, r=nnethercote
atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance

The provenance semantics match what Miri implements and what the `AtomicPtr` API expects.
2025-03-14 01:37:32 -04:00
Jacob Pratt
595c624fbe
Rollup merge of #136230 - clarfonthey:net-memory-layout-assumptions, r=cuviper
Reword incorrect documentation about SocketAddr having varying layout

This has no longer been the case since these types were moved to `core`. The note on portability remains, but it is reworded to not imply that the size varies by target.
2025-03-14 01:37:28 -04:00
bors
523c507d26 Auto merge of #138157 - scottmcm:inline-more-tiny-things, r=oli-obk
Allow more top-down inlining for single-BB callees

This means that things like `<usize as Step>::forward_unchecked` and `<PartialOrd for f32>::le` will inline even if
we've already done a bunch of inlining to find the calls to them.

Fixes #138136

~~Draft as it's built atop #138135, which adds a mir-opt test that's a nice demonstration of this.  To see just this change, look at <48f63e3be5>~~ Rebased to be just the inlining change, as the other existing tests show it great.
2025-03-14 03:51:19 +00:00
Michael Goulet
4c32adbadb Deny impls for BikeshedGuaranteedNoDrop 2025-03-14 03:11:43 +00:00
Matthias Krüger
448aa30b5a
Rollup merge of #138162 - ehuss:library-2024, r=cuviper
Update the standard library to Rust 2024

This updates the standard library to Rust 2024. This includes the following notable changes:

- Macros are updated to use new expression fragment specifiers. This PR includes a test to illustrate the changes, primarily allowing `const {...}` expressions now.
- Some tests show a change in MIR drop order. We do not believe this will be an observable change ([see zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/268952-edition/topic/standard.20library.20migration/near/500972873)).

Fixes https://github.com/rust-lang/rust/issues/133081
2025-03-13 10:58:21 +01:00
Ralf Jung
88b206d582 atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance 2025-03-13 08:14:34 +01:00