rust/src/tools
Stuart Cook d06b3b432f
Rollup merge of #143949 - clarfonthey:const-arith-ops, r=Amanieu
Constify remaining traits/impls for `const_ops`

Tracking issue: rust-lang/rust#143802

This is split into two commits for ease of reviewability:

1. Updates the `forward_ref_*` macros to accept multiple attributes (in anticipation of needing `rust_const_unstable` attributes) and also *require* attributes in these macros. Since the default attribute only helps for the initial implementations, it means it's easy to get wrong for future implementations, as shown for the saturating implementations which were incorrect before.
2. Actually constify the traits/impls.

A few random other notes on the implementation specifically:

* I unindented the attributes that were passed to the `forward_ref_*` macro calls because in some places rustfmt wanted them to be unindented, and in others it was allowed because they were themselves inside of macro bodies. I chose the consistent indenting even though I (personally) think it looks worse.

----

As far as the actual changes go, this constifies the following additional traits:

* `Neg`
* `Not`
* `BitAnd`
* `BitOr`
* `BitXor`
* `Shl`
* `Shr`
* `AddAssign`
* `SubAssign`
* `MulAssign`
* `DivAssign`
* `RemAssign`
* `BitAndAssign`
* `BitOrAssign`
* `BitXorAssign`
* `ShlAssign`
* `ShrAssign`

In terms of constified implementations of these traits, it adds the reference-forwarded versions of all the arithmetic operators, which are defined by the macros in `library/core/src/internal_macros.rs`. I'm not going to fully enumerate these because we'd be here all day, but sufficed to say, it effectively allows adding an `&` to one or both sides of an operator for primitives.

Additionally, I constified the implementations for `Wrapping`, `Saturating`, and `NonZero` as well, since all of them forward to already-const-stable methods. (potentially via intrinsics, to avoid extra overhead)

There are three "non-primitive" types which implement these traits, listed below. Note that I put "non-primitive" in quotes since I'm including `Wrapping`, `Saturating`, and `NonZero`, which are just wrappers over primitives.

* `Duration` (arithmetic operations)
* `SystemTime` (arithmetic operations)
* `Ipv4Addr` (bit operations)
* `Ipv6Addr` (bit operations)

Additionally, because the methods on `SystemTime` needed to make these operations const were not marked const, a separate tracking issue for const-stabilising those methods is rust-lang/rust#144517.

Stuff left out of this PR:

* `Assume` (this could trivially be made const, but since the docs indicate this is still under heavy design, I figured I'd leave it out)
* `Instant` (this could be made const, but cannot reasonably be constructed at constant time, so, isn't useful)
* `SystemTime` (will submit separate PR)
* SIMD types (I'm tackling these all at once later; see rust-lang/portable-simd#467)

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_CONCERN-ISSUE_START -->

> [!NOTE]
> # Concerns (0 active)
>
> - ~~[May break Clippy](https://github.com/rust-lang/rust/pull/143949#issuecomment-3081466077)~~ resolved in [this comment](https://github.com/rust-lang/rust/pull/143949#issuecomment-3083628215)
>
> *Managed by ```@rustbot`—see`` [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*

<!-- TRIAGEBOT_CONCERN-ISSUE_END -->
<!-- TRIAGEBOT_END -->
2025-08-11 12:21:06 +10:00
..
build-manifest Add windows-gnullvm hosts to the manifest 2025-06-26 01:42:44 +02:00
bump-stage0 Remove git_repository field from GitConfig 2025-04-23 10:41:20 +02:00
cargo@840b83a10f Update cargo 2025-07-31 10:03:06 -04:00
cargotest
clippy Constify remaining operators 2025-08-10 01:11:45 -04:00
collect-license-metadata
compiletest Rollup merge of #143093 - lqd:polonius-pre-alpha, r=jackh726 2025-08-10 19:45:46 +10:00
coverage-dump Update miniz_oxide dependency of coverage_dump 2025-05-10 18:35:20 +02:00
enzyme@58af4e9e6c update enzyme submodule to handle llvm 21 2025-08-07 16:31:00 -07:00
error_index_generator
features-status-dump Remove backtrace dep from anyhow in features status dump tool 2025-05-01 07:45:47 -04:00
generate-copyright bump cargo_metadata 2025-07-27 12:47:39 +03:00
generate-windows-sys
html-checker
jsondocck Compiletest: Simplify {Html,Json}DocCk directive handling 2025-07-13 16:00:23 +02:00
jsondoclint rustdoc_json: represent generic args consistently. 2025-06-21 13:52:46 +10:00
libcxx-version
linkchecker add --link-targets-dir flag to linkchecker 2025-07-28 11:23:11 +02:00
lint-docs Rollup merge of #143631 - hkBst:update-escaper-2, r=compiler-errors 2025-07-17 10:41:45 +02:00
lld-wrapper
llvm-bitcode-linker
miri Auto merge of #145126 - tgross35:rollup-6w87usd, r=tgross35 2025-08-08 20:53:33 +00:00
miropt-test-tools miropt: move to edition 2024 2025-07-22 15:02:34 +00:00
nix-dev-shell
opt-dist Update codegen_{cranelift,gcc} and opt-dist to use build.compiletest-allow-stage0 2025-07-30 19:55:07 +08:00
remote-test-client remote-test-client: Exit code 128 + <signal-number> instead of 3 2025-07-04 20:44:26 +02:00
remote-test-server
replace-version-placeholder
run-make-support Rollup merge of #144931 - dpaoliello:msvc-wholearchive, r=jieyouxu 2025-08-08 12:52:54 +10:00
rust-analyzer remove P 2025-08-09 15:47:01 +08:00
rust-installer Update README.md 2025-06-29 12:29:28 +03:00
rustbook cargo update 2025-08-03 00:27:18 +00:00
rustc-perf@dde879cf10 Update rustc-perf submodule 2025-07-29 16:18:52 +02:00
rustdoc
rustdoc-gui Update browser-ui-test version to 0.21.1 2025-07-03 18:08:23 +02:00
rustdoc-gui-test integrate build_helper::npm into js checks and package.json usage 2025-07-19 14:56:42 -05:00
rustdoc-js Update rustdoc search tester to new alias output 2025-07-16 14:27:22 +02:00
rustdoc-themes
rustfmt remove P 2025-08-09 15:47:01 +08:00
test-float-parse Remove uncessary parens in closure body with unused lint 2025-07-10 09:25:56 +08:00
tidy Rollup merge of #141624 - jyn514:env-var-stubs, r=BoxyUwU 2025-08-10 19:45:45 +10:00
tier-check tiercheck: edition 2024 2025-07-14 08:30:27 +00:00
unicode-table-generator unicode-table-gen: more clippy fixes 2025-07-18 15:03:43 +00:00
unstable-book-gen Rollup merge of #141624 - jyn514:env-var-stubs, r=BoxyUwU 2025-08-10 19:45:45 +10:00
wasm-component-ld Update wasm-component-ld to 0.5.14 2025-06-24 15:59:35 -07:00
x x: use let-else 2025-07-11 05:38:05 +00:00
cherry-pick.sh
publish_toolstate.py