Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider modifying the Mul<Self, Output = Self> bound on WrappingMul #344

Open
aerkiaga opened this issue Jan 9, 2025 · 2 comments
Open

Comments

@aerkiaga
Copy link

aerkiaga commented Jan 9, 2025

Currently, the WrappingMul trait has a Mul<Self, Output = Self> bound on it. This is incompatible with compile-time large numeric types types that use const generics to increase their width upon multiplication rather than panicking or overflowing, but which may still want to provide a wrapping version of the operation. I propose removing the Output = Self associated type bound from it.

This is not a breaking change.

@cuviper
Copy link
Member

cuviper commented Jan 9, 2025

It is a breaking change, because users can no longer rely on that equivalence.

use num_traits::WrappingMul;

pub trait WrappingMul2: Sized + std::ops::Mul<Self> {
    fn wrapping_mul(&self, v: &Self) -> Self;
}

fn mul<T: WrappingMul>(x: T, y: T) -> T {
    // We know Mul::Output is T
    x * y
}

fn mul2<T: WrappingMul2>(x: T, y: T) -> T {
    x * y
//  ^^^^^ expected type parameter `T`, found associated type
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ea08daf166ec856c0470515b7e9e51d5

@dzmitry-lahoda
Copy link

for somebody it is breaking change, for others, hopefully, we can see next major version bump in optimistic roadmap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants