diff options
| author | blake2-ppc <blake2-ppc> | 2013-09-18 06:03:22 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-09-18 06:05:06 +0200 |
| commit | 7024a9d5298a6ead78cfead653b3697a40a1b8b7 (patch) | |
| tree | e03b66e125d951a57a428e2d4d2be9f02edabf71 | |
| parent | c135cb268355afe77d2ce0313a8d3e20a4e2fdd3 (diff) | |
| download | rust-7024a9d5298a6ead78cfead653b3697a40a1b8b7.tar.gz rust-7024a9d5298a6ead78cfead653b3697a40a1b8b7.zip | |
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.
| -rw-r--r-- | src/libstd/borrow.rs | 16 |
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)); + } +} |
