Skip to content

Commit

Permalink
auto merge of #9292 : blake2-ppc/rust/borrow-ref-eq, r=huonw
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Sep 19, 2013
2 parents a7cf7b7 + 7024a9d commit 4904bc3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/libstd/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 4904bc3

Please sign in to comment.