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.
This commit is contained in:
parent
c135cb2683
commit
7024a9d529
|
@ -22,7 +22,7 @@ pub fn to_uint<T>(thing: &T) -> uint {
|
||||||
/// Determine if two borrowed pointers point to the same thing.
|
/// Determine if two borrowed pointers point to the same thing.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
|
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
|
// Equality for region pointers
|
||||||
|
@ -70,3 +70,17 @@ impl<'self, T: TotalEq> TotalEq for &'self T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue