auto merge of #8285 : huonw/rust/deriving+++, r=alexcrichton

Some general clean-up relating to deriving:
- `TotalOrd` was too eager, and evaluated the `.cmp` call for every field, even if it could short-circuit earlier.
- the pointer types didn't have impls for `TotalOrd` or `TotalEq`.
- the Makefiles didn't reach deep enough into libsyntax for dependencies.

(Split out from https://github.com/mozilla/rust/pull/8258.)
This commit is contained in:
bors 2013-08-07 00:56:18 -07:00
commit 4da1cfe923
7 changed files with 143 additions and 20 deletions

View file

@ -58,3 +58,15 @@ impl<'self, T: Ord> Ord for &'self T {
*(*self) > *(*other)
}
}
#[cfg(not(test))]
impl<'self, T: TotalOrd> TotalOrd for &'self T {
#[inline]
fn cmp(&self, other: & &'self T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<'self, T: TotalEq> TotalEq for &'self T {
#[inline]
fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
}

View file

@ -153,7 +153,6 @@ pub fn cmp2<A:TotalOrd,B:TotalOrd>(
Return `o1` if it is not `Equal`, otherwise `o2`. Simulates the
lexical ordering on a type `(int, int)`.
*/
// used in deriving code in libsyntax
#[inline]
pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
match o1 {

View file

@ -12,7 +12,7 @@
use ptr::to_unsafe_ptr;
#[cfg(not(test))] use cmp::{Eq, Ord};
#[cfg(not(test))] use cmp::*;
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
pub static RC_IMMORTAL : uint = 0x77777777;
@ -71,6 +71,29 @@ impl<T:Ord> Ord for @mut T {
fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
}
#[cfg(not(test))]
impl<T: TotalOrd> TotalOrd for @T {
#[inline]
fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<T: TotalOrd> TotalOrd for @mut T {
#[inline]
fn cmp(&self, other: &@mut T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<T: TotalEq> TotalEq for @T {
#[inline]
fn equals(&self, other: &@T) -> bool { (**self).equals(*other) }
}
#[cfg(not(test))]
impl<T: TotalEq> TotalEq for @mut T {
#[inline]
fn equals(&self, other: &@mut T) -> bool { (**self).equals(*other) }
}
#[test]
fn test() {
let x = @3;

View file

@ -10,7 +10,7 @@
//! Operations on unique pointer types
#[cfg(not(test))] use cmp::{Eq, Ord};
#[cfg(not(test))] use cmp::*;
#[cfg(not(test))]
impl<T:Eq> Eq for ~T {
@ -31,3 +31,15 @@ impl<T:Ord> Ord for ~T {
#[inline]
fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
}
#[cfg(not(test))]
impl<T: TotalOrd> TotalOrd for ~T {
#[inline]
fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<T: TotalEq> TotalEq for ~T {
#[inline]
fn equals(&self, other: &~T) -> bool { (**self).equals(*other) }
}