diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-12-18 04:42:50 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-12-18 04:42:50 -0700 |
commit | eea49ee1d986c306a8eec32b64be9b10cb2278fc (patch) | |
tree | 5c9555bd62fbb7375fab1561cb62660ea1022b7d /components/util | |
parent | d7b3900431598883212162460254c846bf5f8b52 (diff) | |
parent | bf4480bb791cd918a00fb4bdea234fde676b28e0 (diff) | |
download | servo-eea49ee1d986c306a8eec32b64be9b10cb2278fc.tar.gz servo-eea49ee1d986c306a8eec32b64be9b10cb2278fc.zip |
auto merge of #4420 : servo/servo/fix-warnings, r=Ms2ger
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/geometry.rs | 12 | ||||
-rw-r--r-- | components/util/logical_geometry.rs | 33 | ||||
-rw-r--r-- | components/util/range.rs | 69 |
3 files changed, 46 insertions, 68 deletions
diff --git a/components/util/geometry.rs b/components/util/geometry.rs index 8be6b50dbee..2dc9fe61b4c 100644 --- a/components/util/geometry.rs +++ b/components/util/geometry.rs @@ -6,11 +6,12 @@ use geom::length::Length; use geom::point::Point2D; use geom::rect::Rect; use geom::size::Size2D; +use geom::num::Zero; use serialize::{Encodable, Encoder}; use std::default::Default; use std::i32; -use std::num::{Float, NumCast, Zero}; +use std::num::{Float, NumCast}; use std::fmt; // Units for use with geom::length and geom::scale_factor. @@ -64,7 +65,7 @@ pub enum PagePx {} // See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info. // // FIXME: Implement Au using Length and ScaleFactor instead of a custom type. -#[deriving(Clone, Hash, PartialEq, PartialOrd, Eq, Ord, Zero)] +#[deriving(Clone, Hash, PartialEq, PartialOrd, Eq, Ord)] pub struct Au(pub i32); impl Default for Au { @@ -74,6 +75,13 @@ impl Default for Au { } } +impl Zero for Au { + #[inline] + fn zero() -> Au { + Au(0) + } +} + pub static ZERO_POINT: Point2D<Au> = Point2D { x: Au(0), y: Au(0), diff --git a/components/util/logical_geometry.rs b/components/util/logical_geometry.rs index 96664cc5605..e21039ce758 100644 --- a/components/util/logical_geometry.rs +++ b/components/util/logical_geometry.rs @@ -5,9 +5,9 @@ //! Geometry in flow-relative space. use geom::{Size2D, Point2D, SideOffsets2D, Rect}; +use geom::num::Zero; use std::cmp::{min, max}; use std::fmt::{Show, Formatter, FormatError}; -use std::num::Zero; bitflags!( #[deriving(Encodable)] @@ -158,11 +158,6 @@ impl<T: Zero> LogicalSize<T> { debug_writing_mode: DebugWritingMode::new(mode), } } - - #[inline] - pub fn is_zero(&self) -> bool { - self.inline.is_zero() && self.block.is_zero() - } } impl<T: Copy> LogicalSize<T> { @@ -295,11 +290,6 @@ impl<T: Zero> LogicalPoint<T> { debug_writing_mode: DebugWritingMode::new(mode), } } - - #[inline] - pub fn is_zero(&self) -> bool { - self.i.is_zero() && self.b.is_zero() - } } impl<T: Copy> LogicalPoint<T> { @@ -476,14 +466,6 @@ impl<T: Zero> LogicalMargin<T> { debug_writing_mode: DebugWritingMode::new(mode), } } - - #[inline] - pub fn is_zero(&self) -> bool { - self.block_start.is_zero() && - self.inline_end.is_zero() && - self.block_end.is_zero() && - self.inline_start.is_zero() - } } impl<T: Copy> LogicalMargin<T> { @@ -666,6 +648,14 @@ impl<T: Copy> LogicalMargin<T> { } } +impl<T: PartialEq + Zero> LogicalMargin<T> { + #[inline] + pub fn is_zero(&self) -> bool { + self.block_start == Zero::zero() && self.inline_end == Zero::zero() && + self.block_end == Zero::zero() && self.inline_start == Zero::zero() + } +} + impl<T: Add<T, T>> LogicalMargin<T> { #[inline] pub fn inline_start_end(&self) -> T { @@ -756,11 +746,6 @@ impl<T: Zero> LogicalRect<T> { debug_writing_mode: DebugWritingMode::new(mode), } } - - #[inline] - pub fn is_zero(&self) -> bool { - self.start.is_zero() && self.size.is_zero() - } } impl<T: Copy> LogicalRect<T> { diff --git a/components/util/range.rs b/components/util/range.rs index 2cdb49e27b6..103f6d3c91d 100644 --- a/components/util/range.rs +++ b/components/util/range.rs @@ -6,29 +6,15 @@ use std::cmp::{max, min}; use std::iter; use std::fmt; use std::num; -use std::num::{Int, Bounded, Zero}; +use std::num::Int; /// An index type to be used by a `Range` -pub trait RangeIndex: Copy - + Clone - + fmt::Show - + PartialEq - + PartialOrd - + Eq - + Ord - + Add<Self, Self> - + Sub<Self, Self> - + Neg<Self> - + Zero {} - -pub trait IntRangeIndex<T>: RangeIndex + Copy { +pub trait RangeIndex<T>: Int + fmt::Show { fn new(x: T) -> Self; fn get(self) -> T; } -impl RangeIndex for int {} - -impl IntRangeIndex<int> for int { +impl RangeIndex<int> for int { #[inline] fn new(x: int) -> int { x } @@ -40,7 +26,7 @@ impl IntRangeIndex<int> for int { #[macro_export] macro_rules! int_range_index { ($(#[$attr:meta])* struct $Self:ident($T:ty)) => ( - #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show, Zero)] + #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)] $(#[$attr])* pub struct $Self(pub $T); @@ -51,7 +37,18 @@ macro_rules! int_range_index { } } - impl RangeIndex for $Self {} + impl RangeIndex<$T> for $Self { + #[inline] + fn new(x: $T) -> $Self { + $Self(x) + } + + #[inline] + fn get(self) -> $T { + match self { $Self(x) => x } + } + } + impl ::std::num::Int for $Self { fn zero() -> $Self { $Self(0) } fn one() -> $Self { $Self(1) } @@ -77,18 +74,6 @@ macro_rules! int_range_index { } } - impl IntRangeIndex<$T> for $Self { - #[inline] - fn new(x: $T) -> $Self { - $Self(x) - } - - #[inline] - fn get(self) -> $T { - match self { $Self(x) => x } - } - } - impl Add<$Self, $Self> for $Self { #[inline] fn add(&self, other: &$Self) -> $Self { @@ -196,7 +181,7 @@ pub struct Range<I> { length: I, } -impl<I: RangeIndex> fmt::Show for Range<I> { +impl<I: RangeIndex<T>, T> fmt::Show for Range<I> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "[{} .. {})", self.begin(), self.end()) } @@ -207,14 +192,14 @@ pub struct EachIndex<T, I> { it: iter::Range<T>, } -pub fn each_index<T: Int, I: IntRangeIndex<T>>(start: I, stop: I) -> EachIndex<T, I> { +pub fn each_index<T: Int, I: RangeIndex<T>>(start: I, stop: I) -> EachIndex<T, I> { EachIndex { it: iter::range(start.get(), stop.get()) } } -impl<T: Int, I: IntRangeIndex<T>> Iterator<I> for EachIndex<T, I> { +impl<T: Int, I: RangeIndex<T>> Iterator<I> for EachIndex<T, I> { #[inline] fn next(&mut self) -> Option<I> { - self.it.next().map(|i| IntRangeIndex::new(i)) + self.it.next().map(|i| RangeIndex::new(i)) } #[inline] @@ -223,7 +208,7 @@ impl<T: Int, I: IntRangeIndex<T>> Iterator<I> for EachIndex<T, I> { } } -impl<I: RangeIndex> Range<I> { +impl<I: RangeIndex<T>, T> Range<I> { /// Create a new range from beginning and length offsets. This could be /// denoted as `[begin, begin + length)`. /// @@ -239,7 +224,7 @@ impl<I: RangeIndex> Range<I> { #[inline] pub fn empty() -> Range<I> { - Range::new(num::zero(), num::zero()) + Range::new(Int::zero(), Int::zero()) } /// The index offset to the beginning of the range. @@ -287,7 +272,7 @@ impl<I: RangeIndex> Range<I> { /// `true` if the offset from the beginning to the end of the range is zero. #[inline] pub fn is_empty(&self) -> bool { - self.length().is_zero() + self.length() == Int::zero() } /// Shift the entire range by the supplied index delta. @@ -360,7 +345,7 @@ impl<I: RangeIndex> Range<I> { } /// Methods for `Range`s with indices based on integer values -impl<T: Int+Bounded, I: IntRangeIndex<T>> Range<I> { +impl<T: Int, I: RangeIndex<T>> Range<I> { /// Returns an iterater that increments over `[begin, end)`. #[inline] pub fn each_index(&self) -> EachIndex<T, I> { @@ -372,7 +357,7 @@ impl<T: Int+Bounded, I: IntRangeIndex<T>> Range<I> { let s_len = s.len(); match num::cast::<uint, T>(s_len) { Some(len) => { - let len = IntRangeIndex::new(len); + let len = RangeIndex::new(len); self.begin() < len && self.end() <= len && self.length() <= len @@ -381,8 +366,8 @@ impl<T: Int+Bounded, I: IntRangeIndex<T>> Range<I> { debug!("Range<T>::is_valid_for_string: string length (len={}) is longer than the \ max value for the range index (max={})", s_len, { - let max: T = Bounded::max_value(); - let val: I = IntRangeIndex::new(max); + let max: T = Int::max_value(); + let val: I = RangeIndex::new(max); val }); false |