about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-24 00:26:14 +0000
committerbors <bors@rust-lang.org>2014-07-24 00:26:14 +0000
commit2224edcfe16ff798fcfa6f21a339822cb8b0f7ba (patch)
treed4c2f6033218e8ab3c9bc20fb018aabadc7274a5 /src/rustllvm/PassWrapper.cpp
parentfb72c4767fa423649feeb197b50385c1fa0a6fd5 (diff)
parent7b7d23cc3d53ae46442367a69966bf2cebccc515 (diff)
downloadrust-2224edcfe16ff798fcfa6f21a339822cb8b0f7ba.tar.gz
rust-2224edcfe16ff798fcfa6f21a339822cb8b0f7ba.zip
auto merge of #15407 : sneves/rust/master, r=aturon
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<T: Int>(x : T) -> T {
        x << One::one()
    }

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

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

This patch allows the much simpler implementation

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

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

All of the above applies similarly to right shifts, i.e., `Shr<uint, T>`.
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions