From d7f97e3018ac664058a507d207676f30fda4bfe4 Mon Sep 17 00:00:00 2001 From: xales Date: Tue, 28 Jan 2014 19:29:10 -0500 Subject: Rename std::borrow to std::reference. Fixes #11814 --- src/libstd/borrow.rs | 86 ------------------------------------------------- src/libstd/lib.rs | 2 +- src/libstd/reference.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ src/libstd/rt/task.rs | 4 +-- 4 files changed, 89 insertions(+), 89 deletions(-) delete mode 100644 src/libstd/borrow.rs create mode 100644 src/libstd/reference.rs (limited to 'src/libstd') diff --git a/src/libstd/borrow.rs b/src/libstd/borrow.rs deleted file mode 100644 index 66df4334adc..00000000000 --- a/src/libstd/borrow.rs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Utilities for references - -#[cfg(not(test))] -use prelude::*; - -/// Cast a region pointer - &T - to a uint. -#[inline] -pub fn to_uint(thing: &T) -> uint { - thing as *T as 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 { - (thing as *T) == (other as *T) -} - -// Equality for region pointers -#[cfg(not(test))] -impl<'a, T: Eq> Eq for &'a T { - #[inline] - fn eq(&self, other: & &'a T) -> bool { - *(*self) == *(*other) - } - #[inline] - fn ne(&self, other: & &'a T) -> bool { - *(*self) != *(*other) - } -} - -// Comparison for region pointers -#[cfg(not(test))] -impl<'a, T: Ord> Ord for &'a T { - #[inline] - fn lt(&self, other: & &'a T) -> bool { - *(*self) < *(*other) - } - #[inline] - fn le(&self, other: & &'a T) -> bool { - *(*self) <= *(*other) - } - #[inline] - fn ge(&self, other: & &'a T) -> bool { - *(*self) >= *(*other) - } - #[inline] - fn gt(&self, other: & &'a T) -> bool { - *(*self) > *(*other) - } -} - -#[cfg(not(test))] -impl<'a, T: TotalOrd> TotalOrd for &'a T { - #[inline] - fn cmp(&self, other: & &'a T) -> Ordering { (**self).cmp(*other) } -} - -#[cfg(not(test))] -impl<'a, T: TotalEq> TotalEq for &'a T { - #[inline] - fn equals(&self, other: & &'a 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)); - } -} diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 17b6c24773a..ac95fbd1fb1 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -123,7 +123,7 @@ pub mod send_str; pub mod ptr; pub mod owned; pub mod managed; -pub mod borrow; +pub mod reference; pub mod rc; pub mod gc; diff --git a/src/libstd/reference.rs b/src/libstd/reference.rs new file mode 100644 index 00000000000..66df4334adc --- /dev/null +++ b/src/libstd/reference.rs @@ -0,0 +1,86 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Utilities for references + +#[cfg(not(test))] +use prelude::*; + +/// Cast a region pointer - &T - to a uint. +#[inline] +pub fn to_uint(thing: &T) -> uint { + thing as *T as 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 { + (thing as *T) == (other as *T) +} + +// Equality for region pointers +#[cfg(not(test))] +impl<'a, T: Eq> Eq for &'a T { + #[inline] + fn eq(&self, other: & &'a T) -> bool { + *(*self) == *(*other) + } + #[inline] + fn ne(&self, other: & &'a T) -> bool { + *(*self) != *(*other) + } +} + +// Comparison for region pointers +#[cfg(not(test))] +impl<'a, T: Ord> Ord for &'a T { + #[inline] + fn lt(&self, other: & &'a T) -> bool { + *(*self) < *(*other) + } + #[inline] + fn le(&self, other: & &'a T) -> bool { + *(*self) <= *(*other) + } + #[inline] + fn ge(&self, other: & &'a T) -> bool { + *(*self) >= *(*other) + } + #[inline] + fn gt(&self, other: & &'a T) -> bool { + *(*self) > *(*other) + } +} + +#[cfg(not(test))] +impl<'a, T: TotalOrd> TotalOrd for &'a T { + #[inline] + fn cmp(&self, other: & &'a T) -> Ordering { (**self).cmp(*other) } +} + +#[cfg(not(test))] +impl<'a, T: TotalEq> TotalEq for &'a T { + #[inline] + fn equals(&self, other: & &'a 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)); + } +} diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index e99e7fa4edd..09b91c138bc 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -14,7 +14,7 @@ //! to implement this. use any::AnyOwnExt; -use borrow; +use reference; use cast; use cleanup; use clone::Clone; @@ -287,7 +287,7 @@ impl Task { impl Drop for Task { fn drop(&mut self) { - rtdebug!("called drop for a task: {}", borrow::to_uint(self)); + rtdebug!("called drop for a task: {}", reference::to_uint(self)); rtassert!(self.destroyed); } } -- cgit 1.4.1-3-g733a5