about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-19 03:01:05 -0700
committerbors <bors@rust-lang.org>2013-09-19 03:01:05 -0700
commit4904bc33cc20044709286794d3998d7464277ab4 (patch)
tree83c84fbb91bac94f9753f1849dcabc3ec8e7d1a5 /src/libstd
parenta7cf7b7b0b3392bc3219e2bea44a0a18283aae50 (diff)
parent7024a9d5298a6ead78cfead653b3697a40a1b8b7 (diff)
downloadrust-4904bc33cc20044709286794d3998d7464277ab4.tar.gz
rust-4904bc33cc20044709286794d3998d7464277ab4.zip
auto merge of #9292 : blake2-ppc/rust/borrow-ref-eq, r=huonw
std::borrow: Use raw pointer comparison for `ref_eq`

Compare as `*T` in `ref_eq` instead of casting to uint, to match what
std::ptr does.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/borrow.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libstd/borrow.rs b/src/libstd/borrow.rs
index 6c3d4c5f1fb..0626b3fc618 100644
--- a/src/libstd/borrow.rs
+++ b/src/libstd/borrow.rs
@@ -22,7 +22,7 @@ pub fn to_uint<T>(thing: &T) -> uint {
 /// Determine if two borrowed pointers point to the same thing.
 #[inline]
 pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
-    to_uint(thing) == to_uint(other)
+    (thing as *T) == (other as *T)
 }
 
 // Equality for region pointers
@@ -70,3 +70,17 @@ impl<'self, T: TotalEq> TotalEq for &'self T {
     #[inline]
     fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::ref_eq;
+
+    #[test]
+    fn test_ref_eq() {
+        let x = 1;
+        let y = 1;
+
+        assert!(ref_eq(&x, &x));
+        assert!(!ref_eq(&x, &y));
+    }
+}