Skip to content

Widen the result of widening_mul.#156644

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
bjoernager:widening-mul
May 18, 2026
Merged

Widen the result of widening_mul.#156644
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
bjoernager:widening-mul

Conversation

@bjoernager
Copy link
Copy Markdown
Contributor

@bjoernager bjoernager commented May 16, 2026

Tracking issue: #152016

This PR implements #152016 (comment), which mandates that widening_mul return a single, scalar value rather than a low/high tuple.

Consequently, this method is removed from u128 and i128 as they are the widest integral types. It has also been removed from usize and isize due to portability concerns.

Existing widening_mul usage has been replaced by equivalent calls to carrying_mul (which is logically identical to the old behaviour.) Existing – generic – non-doc tests have been removed.

Public API

impl u8 {
    pub const fn widening_mul(self, rhs: Self) -> u16;
}

impl u16 {
    pub const fn widening_mul(self, rhs: Self) -> u32;
}

impl u32 {
    pub const fn widening_mul(self, rhs: Self) -> u64;
}

impl u64 {
    pub const fn widening_mul(self, rhs: Self) -> u128;
}

impl i8 {
    pub const fn widening_mul(self, rhs: Self) -> i16;
}

impl i16 {
    pub const fn widening_mul(self, rhs: Self) -> i32;
}

impl i32 {
    pub const fn widening_mul(self, rhs: Self) -> i64;
}

impl i64 {
    pub const fn widening_mul(self, rhs: Self) -> i128;
}

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 16, 2026
@rust-log-analyzer

This comment has been minimized.

@bjoernager bjoernager marked this pull request as ready for review May 16, 2026 18:41
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 16, 2026

Some changes occurred in integer formatting

cc @tgross35

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 16, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 16, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates

@bjoernager
Copy link
Copy Markdown
Contributor Author

@rustbot label +T-libs-api -T-libs

r? libs-api

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 16, 2026
@rustbot rustbot assigned the8472 and unassigned Mark-Simulacrum May 16, 2026
@programmerjake
Copy link
Copy Markdown
Member

IMO we need generic integers (which lets us have u<256>/i<256>) in order to support widening_mul on usize/isize/u128/i128 since Rust allows usize/isize to be 128-bit.

@bjoernager
Copy link
Copy Markdown
Contributor Author

bjoernager commented May 16, 2026

I suppose we could just let those implementation remain unstable. Or should we outright remove them as well?

@programmerjake
Copy link
Copy Markdown
Member

I suppose we could just let those implementation remain unstable. Or should we outright remove them as well?

I think we should remove them unless we get a usizex2 type or something. Rust generally avoids having things that change type depending on the pointer size.

@clarfonthey
Copy link
Copy Markdown
Contributor

Yeah, I thought I had replied to this, but apparently not. Definitely, I feel like usize and isize should not implement this method and people should be used to use carrying_mul instead with a carry of zero. We already have an efficient way of doing this; it's just that the widening_mul primitive is particularly useful as an API, although only when it actually makes sense to say "an integer twice as wide."

Comment thread library/core/src/fmt/num.rs Outdated
Comment thread library/core/src/num/imp/diy_float.rs Outdated
Comment thread library/core/src/num/mod.rs
@tgross35
Copy link
Copy Markdown
Contributor

r? libs

@rustbot label +T-libs-api -T-libs

r? libs-api

libs-api already discussed this change, somebody from libs can check it

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 18, 2026

The review request libs corresponds to 7 reviewer(s).
However, none of them are available for a review at this time.
Use r? to specify someone else to assign.

@tgross35
Copy link
Copy Markdown
Contributor

r? tgross35

@rustbot rustbot assigned tgross35 and unassigned the8472 May 18, 2026
@tgross35
Copy link
Copy Markdown
Contributor

Actually r? clarfonthey since you've looked at this already, feel free to kick it back if you don't have the time.

@rustbot rustbot assigned clarfonthey and unassigned tgross35 May 18, 2026
@clarfonthey
Copy link
Copy Markdown
Contributor

Looks good to me.

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 18, 2026

📌 Commit 0a07235 has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 18, 2026
rust-bors Bot pushed a commit that referenced this pull request May 18, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #156709 (stdarch subtree update)
 - #155006 (stabilize `feature(cfg_target_has_atomic_equal_alignment)`)
 - #156444 (Implement `OsStr::split_at`)
 - #156582 (Allow `global_asm!` in statement positions)
 - #156661 (Remove `UncheckedIterator`)
 - #152367 (Derives `Copy` for `ffi::FromBytesUntilNulError`)
 - #156443 (Fix invalid suggestion for parenthesized break)
 - #156606 (Add pext/pdep as aliases for extract_bits/deposit_bits)
 - #156630 (Replace `println!` with `assert!` in HashMap documentation examples)
 - #156644 (Widen the result of `widening_mul`.)
 - #156653 (Update `sysinfo` version to `0.39.2`)
 - #156697 (Add diagnostic items for IoBufReader and StdinLock)
 - #156704 (reduce usage of `box_patterns` in tests)
@rust-bors rust-bors Bot merged commit 3605c1f into rust-lang:main May 18, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 18, 2026
rust-timer added a commit that referenced this pull request May 18, 2026
Rollup merge of #156644 - bjoernager:widening-mul, r=clarfonthey

Widen the result of `widening_mul`.

Tracking issue: #152016

This PR implements <#152016 (comment)>, which mandates that `widening_mul` return a single, scalar value rather than a low/high tuple.

Consequently, this method is removed from `u128` and `i128` as they are the widest integral types. It has also been removed from `usize` and `isize` due to portability concerns.

Existing `widening_mul` usage has been replaced by equivalent calls to `carrying_mul` (which is logically identical to the old behaviour.) Existing &ndash; generic &ndash; non-doc tests have been removed.

# Public API

```rust
impl u8 {
    pub const fn widening_mul(self, rhs: Self) -> u16;
}

impl u16 {
    pub const fn widening_mul(self, rhs: Self) -> u32;
}

impl u32 {
    pub const fn widening_mul(self, rhs: Self) -> u64;
}

impl u64 {
    pub const fn widening_mul(self, rhs: Self) -> u128;
}

impl i8 {
    pub const fn widening_mul(self, rhs: Self) -> i16;
}

impl i16 {
    pub const fn widening_mul(self, rhs: Self) -> i32;
}

impl i32 {
    pub const fn widening_mul(self, rhs: Self) -> i64;
}

impl i64 {
    pub const fn widening_mul(self, rhs: Self) -> i128;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants