|
17 | 17 |
|
18 | 18 | use clone::{Clone, DeepClone};
|
19 | 19 | use cmp::{Eq, Ord};
|
| 20 | +use mem::size_of; |
20 | 21 | use ops::{Add, Sub, Mul, Div, Rem, Neg};
|
21 | 22 | use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
|
22 | 23 | use option::{Option, Some, None};
|
@@ -381,19 +382,7 @@ pub trait Primitive: Clone
|
381 | 382 | + Num
|
382 | 383 | + NumCast
|
383 | 384 | + Orderable
|
384 |
| - + Bounded |
385 |
| - + Neg<Self> |
386 |
| - + Add<Self,Self> |
387 |
| - + Sub<Self,Self> |
388 |
| - + Mul<Self,Self> |
389 |
| - + Div<Self,Self> |
390 |
| - + Rem<Self,Self> { |
391 |
| - // FIXME (#5527): These should be associated constants |
392 |
| - // FIXME (#8888): Removing `unused_self` requires #8888 to be fixed. |
393 |
| - fn bits(unused_self: Option<Self>) -> uint; |
394 |
| - fn bytes(unused_self: Option<Self>) -> uint; |
395 |
| - fn is_signed(unused_self: Option<Self>) -> bool; |
396 |
| -} |
| 385 | + + Bounded {} |
397 | 386 |
|
398 | 387 | /// A collection of traits relevant to primitive signed and unsigned integers
|
399 | 388 | pub trait Int: Integer
|
@@ -536,7 +525,7 @@ pub trait ToPrimitive {
|
536 | 525 | macro_rules! impl_to_primitive_int_to_int(
|
537 | 526 | ($SrcT:ty, $DstT:ty) => (
|
538 | 527 | {
|
539 |
| - if Primitive::bits(None::<$SrcT>) <= Primitive::bits(None::<$DstT>) { |
| 528 | + if size_of::<$SrcT>() <= size_of::<$DstT>() { |
540 | 529 | Some(*self as $DstT)
|
541 | 530 | } else {
|
542 | 531 | let n = *self as i64;
|
@@ -621,7 +610,7 @@ macro_rules! impl_to_primitive_uint_to_int(
|
621 | 610 | macro_rules! impl_to_primitive_uint_to_uint(
|
622 | 611 | ($SrcT:ty, $DstT:ty) => (
|
623 | 612 | {
|
624 |
| - if Primitive::bits(None::<$SrcT>) <= Primitive::bits(None::<$DstT>) { |
| 613 | + if size_of::<$SrcT>() <= size_of::<$DstT>() { |
625 | 614 | Some(*self as $DstT)
|
626 | 615 | } else {
|
627 | 616 | let zero: $SrcT = Zero::zero();
|
@@ -677,7 +666,7 @@ impl_to_primitive_uint!(u64)
|
677 | 666 |
|
678 | 667 | macro_rules! impl_to_primitive_float_to_float(
|
679 | 668 | ($SrcT:ty, $DstT:ty) => (
|
680 |
| - if Primitive::bits(None::<$SrcT>) <= Primitive::bits(None::<$DstT>) { |
| 669 | + if size_of::<$SrcT>() <= size_of::<$DstT>() { |
681 | 670 | Some(*self as $DstT)
|
682 | 671 | } else {
|
683 | 672 | let n = *self as f64;
|
|
0 commit comments