Wrapping<_> implements ShX<usize> but wrapping_shX takes u32

05cfdd9
Opened by jethrogb at 2023-11-18 09:10:10

This is mostly just slightly confusing.

impl ShX for Wrapping<_> (the code refers to #23545, I'm not sure how this is related).

wrapping_shX

  1. This is mostly just slightly confusing.

    impl ShX for Wrapping<_> (the code refers to #23545, I'm not sure how this is related).

    wrapping_shX

    Martin Nordholts at 2023-11-18 09:06:57

  2. The same way Shr/Shl are implemented for all primitive integrals with all primitive integral types for RHS, Shr/Shl should be implemented ∀ Wrapping<T>, where T: primitive with all primitive integral types for RHS.

    Simonas Kazlauskas at 2016-07-14 15:19:51

  3. Does anyone know why this is? It was added by @aturon, and it seems it was intended to be implemented for more types: https://github.com/rust-lang/rust/pull/23549#r26862139. I suspect that this is a side-effect of #23545 since it causes inference regressions, but I'm uncertain (and that seems odd, since I'd expect most/all uses of shifting operations to have the types fairly well defined explicitly...).

    Mark Rousskov at 2017-05-06 18:58:49

  4. I ran into this problem when working on #50465; it appears that neither Wrapping(1u32) >> 2 nor Wrapping(1u32) >> Wrapping(2) work today without type ascription.

    IMHO, it makes the most sense to get rid of the Shr<usize> and Shl<usize> impls and use Wrapping on both sides, but that would be a breaking change. I assume that there's no way to deprecate trait impls either…

    Ideally, we'd want to implement all of the necessary impls for Wrapping >> Wrapping and Wrapping << Wrapping, using all combinations of integer types like the non-wrapping versions, then somehow deprecate the current, lonely usize impl. Ideally, we could outright remove it, but I doubt that'd happen any time soon.

    Clar Fon at 2018-05-07 21:03:13

  5. Triage: I believe this issue can be closed after the disabled impls here have been enabled, which is requires #23545 to be fixed first. Please correct me if that is wrong.

    Martin Nordholts at 2023-11-18 09:10:10