Skip to content

Commit 4904bc3

Browse files
committed
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.
2 parents a7cf7b7 + 7024a9d commit 4904bc3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libstd/borrow.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn to_uint<T>(thing: &T) -> uint {
2222
/// Determine if two borrowed pointers point to the same thing.
2323
#[inline]
2424
pub fn ref_eq<'a, 'b, T>(thing: &'a T, other: &'b T) -> bool {
25-
to_uint(thing) == to_uint(other)
25+
(thing as *T) == (other as *T)
2626
}
2727

2828
// Equality for region pointers
@@ -70,3 +70,17 @@ impl<'self, T: TotalEq> TotalEq for &'self T {
7070
#[inline]
7171
fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
7272
}
73+
74+
#[cfg(test)]
75+
mod tests {
76+
use super::ref_eq;
77+
78+
#[test]
79+
fn test_ref_eq() {
80+
let x = 1;
81+
let y = 1;
82+
83+
assert!(ref_eq(&x, &x));
84+
assert!(!ref_eq(&x, &y));
85+
}
86+
}

0 commit comments

Comments
 (0)