|
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};
|
@@ -425,19 +426,7 @@ pub trait Primitive: Clone
|
425 | 426 | + Num
|
426 | 427 | + NumCast
|
427 | 428 | + Orderable
|
428 |
| - + Bounded |
429 |
| - + Neg<Self> |
430 |
| - + Add<Self,Self> |
431 |
| - + Sub<Self,Self> |
432 |
| - + Mul<Self,Self> |
433 |
| - + Div<Self,Self> |
434 |
| - + Rem<Self,Self> { |
435 |
| - // FIXME (#5527): These should be associated constants |
436 |
| - // FIXME (#8888): Removing `unused_self` requires #8888 to be fixed. |
437 |
| - fn bits(unused_self: Option<Self>) -> uint; |
438 |
| - fn bytes(unused_self: Option<Self>) -> uint; |
439 |
| - fn is_signed(unused_self: Option<Self>) -> bool; |
440 |
| -} |
| 429 | + + Bounded {} |
441 | 430 |
|
442 | 431 | /// A collection of traits relevant to primitive signed and unsigned integers
|
443 | 432 | pub trait Int: Integer
|
@@ -580,7 +569,7 @@ pub trait ToPrimitive {
|
580 | 569 | macro_rules! impl_to_primitive_int_to_int(
|
581 | 570 | ($SrcT:ty, $DstT:ty) => (
|
582 | 571 | {
|
583 |
| - if Primitive::bits(None::<$SrcT>) <= Primitive::bits(None::<$DstT>) { |
| 572 | + if size_of::<$SrcT>() <= size_of::<$DstT>() { |
584 | 573 | Some(*self as $DstT)
|
585 | 574 | } else {
|
586 | 575 | let n = *self as i64;
|
@@ -665,7 +654,7 @@ macro_rules! impl_to_primitive_uint_to_int(
|
665 | 654 | macro_rules! impl_to_primitive_uint_to_uint(
|
666 | 655 | ($SrcT:ty, $DstT:ty) => (
|
667 | 656 | {
|
668 |
| - if Primitive::bits(None::<$SrcT>) <= Primitive::bits(None::<$DstT>) { |
| 657 | + if size_of::<$SrcT>() <= size_of::<$DstT>() { |
669 | 658 | Some(*self as $DstT)
|
670 | 659 | } else {
|
671 | 660 | let zero: $SrcT = Zero::zero();
|
@@ -721,7 +710,7 @@ impl_to_primitive_uint!(u64)
|
721 | 710 |
|
722 | 711 | macro_rules! impl_to_primitive_float_to_float(
|
723 | 712 | ($SrcT:ty, $DstT:ty) => (
|
724 |
| - if Primitive::bits(None::<$SrcT>) <= Primitive::bits(None::<$DstT>) { |
| 713 | + if size_of::<$SrcT>() <= size_of::<$DstT>() { |
725 | 714 | Some(*self as $DstT)
|
726 | 715 | } else {
|
727 | 716 | let n = *self as f64;
|
|
0 commit comments