rust-lang/rust — pull request #15407 by sneves (2014-07-04 09:11:14+00:00)
Title: Change Shl<T, T> (resp Shr<T, T>) for Int to Shl<uint, T> (resp Shr<uint, T>)

At the moment, writing generic functions for integer types that involve shifting is rather verbose. For example, a function at shifts an integer left by 1 currently requires

use std::num::One;
fn f(x : T) -> T {
x << One::one()
}

If the shift amount is not 1, it's even worse:

use std::num::FromPrimitive;
fn f(x: T) -> T {
x << FromPrimitive::from_int(2).unwrap()
}

This patch allows the much simpler implementation

fn f(x: T) -> T {
x << 2
}

It accomplishes this by changing the built-in integer types (and the `Int` trait) to implement `Shl` instead of `Shl` as it currently is defined. Note that the internal implementations of `shl` already cast the right-hand side to `uint`. `BigInt` also implements `Shl`, so this increases consistency.

All of the above applies similarly to right shifts, i.e., `Shr`.