about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-12 13:10:55 -0700
committerbors <bors@rust-lang.org>2013-09-12 13:10:55 -0700
commitcabba6b4d3c0d31f6cd224d4537ce2ff115b039b (patch)
tree4061452a7e4b01eaacbd92cfe8213730e9295360 /src/libstd
parenta6be8d353bc25e160bc988e91744571547d12cab (diff)
parentb7435cf44783c9ab6cf16bc387299ed9891ae90d (diff)
downloadrust-cabba6b4d3c0d31f6cd224d4537ce2ff115b039b.tar.gz
rust-cabba6b4d3c0d31f6cd224d4537ce2ff115b039b.zip
auto merge of #9136 : thestinger/rust/ptr, r=alexcrichton
This is mostly for consistency, as you can now compare raw pointers in
constant expressions or without the standard library.

It also reduces the number of `ptrtoint` instructions in the IR, making
tracking down culprits of what's usually an anti-pattern easier.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ptr.rs68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs
index fafb1511973..6e90e2a1070 100644
--- a/src/libstd/ptr.rs
+++ b/src/libstd/ptr.rs
@@ -383,7 +383,7 @@ impl<T> RawPtr<T> for *mut T {
 }
 
 // Equality for pointers
-#[cfg(not(test))]
+#[cfg(stage0, not(test))]
 impl<T> Eq for *T {
     #[inline]
     fn eq(&self, other: &*T) -> bool {
@@ -393,7 +393,17 @@ impl<T> Eq for *T {
     fn ne(&self, other: &*T) -> bool { !self.eq(other) }
 }
 
-#[cfg(not(test))]
+#[cfg(not(stage0), not(test))]
+impl<T> Eq for *T {
+    #[inline]
+    fn eq(&self, other: &*T) -> bool {
+        *self == *other
+    }
+    #[inline]
+    fn ne(&self, other: &*T) -> bool { !self.eq(other) }
+}
+
+#[cfg(stage0, not(test))]
 impl<T> Eq for *mut T {
     #[inline]
     fn eq(&self, other: &*mut T) -> bool {
@@ -403,6 +413,16 @@ impl<T> Eq for *mut T {
     fn ne(&self, other: &*mut T) -> bool { !self.eq(other) }
 }
 
+#[cfg(not(stage0), not(test))]
+impl<T> Eq for *mut T {
+    #[inline]
+    fn eq(&self, other: &*mut T) -> bool {
+        *self == *other
+    }
+    #[inline]
+    fn ne(&self, other: &*mut T) -> bool { !self.eq(other) }
+}
+
 // Equivalence for pointers
 #[cfg(not(test))]
 impl<T> Equiv<*mut T> for *T {
@@ -460,7 +480,7 @@ mod externfnpointers {
 }
 
 // Comparison for pointers
-#[cfg(not(test))]
+#[cfg(stage0, not(test))]
 impl<T> Ord for *T {
     #[inline]
     fn lt(&self, other: &*T) -> bool {
@@ -480,7 +500,27 @@ impl<T> Ord for *T {
     }
 }
 
-#[cfg(not(test))]
+#[cfg(not(stage0), not(test))]
+impl<T> Ord for *T {
+    #[inline]
+    fn lt(&self, other: &*T) -> bool {
+        *self < *other
+    }
+    #[inline]
+    fn le(&self, other: &*T) -> bool {
+        *self <= *other
+    }
+    #[inline]
+    fn ge(&self, other: &*T) -> bool {
+        *self >= *other
+    }
+    #[inline]
+    fn gt(&self, other: &*T) -> bool {
+        *self > *other
+    }
+}
+
+#[cfg(stage0, not(test))]
 impl<T> Ord for *mut T {
     #[inline]
     fn lt(&self, other: &*mut T) -> bool {
@@ -500,6 +540,26 @@ impl<T> Ord for *mut T {
     }
 }
 
+#[cfg(not(stage0), not(test))]
+impl<T> Ord for *mut T {
+    #[inline]
+    fn lt(&self, other: &*mut T) -> bool {
+        *self < *other
+    }
+    #[inline]
+    fn le(&self, other: &*mut T) -> bool {
+        *self <= *other
+    }
+    #[inline]
+    fn ge(&self, other: &*mut T) -> bool {
+        *self >= *other
+    }
+    #[inline]
+    fn gt(&self, other: &*mut T) -> bool {
+        *self > *other
+    }
+}
+
 #[cfg(test)]
 pub mod ptr_tests {
     use super::*;