Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>`.
- Loading branch information
Showing
4 changed files
with
17 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters