From d7f97e3018ac664058a507d207676f30fda4bfe4 Mon Sep 17 00:00:00 2001 From: xales Date: Tue, 28 Jan 2014 19:29:10 -0500 Subject: [PATCH 1/3] Rename std::borrow to std::reference. Fixes #11814 --- src/libextra/arc.rs | 4 ++-- src/libextra/sync.rs | 4 ++-- src/libstd/lib.rs | 2 +- src/libstd/{borrow.rs => reference.rs} | 0 src/libstd/rt/task.rs | 4 ++-- src/test/run-pass/borrowck-borrow-from-expr-block.rs | 6 +++--- src/test/run-pass/cast-region-to-uint.rs | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) rename src/libstd/{borrow.rs => reference.rs} (100%) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index bf47e3bdf89..709382358f1 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -47,7 +47,7 @@ use sync::{Mutex, RWLock}; use std::cast; use std::sync::arc::UnsafeArc; use std::task; -use std::borrow; +use std::reference; /// As sync::condvar, a mechanism for unlock-and-descheduling and signaling. pub struct Condvar<'a> { @@ -465,7 +465,7 @@ impl RWArc { // of this cast is removing the mutability.) let new_data = data; // Downgrade ensured the token belonged to us. Just a sanity check. - assert!(borrow::ref_eq(&(*state).data, new_data)); + assert!(reference::ref_eq(&(*state).data, new_data)); // Produce new token RWReadMode { data: new_data, diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 3acaf835256..742b7831202 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -18,7 +18,7 @@ */ -use std::borrow; +use std::reference; use std::comm; use std::unstable::sync::Exclusive; use std::sync::arc::UnsafeArc; @@ -634,7 +634,7 @@ impl RWLock { /// To be called inside of the write_downgrade block. pub fn downgrade<'a>(&self, token: RWLockWriteMode<'a>) -> RWLockReadMode<'a> { - if !borrow::ref_eq(self, token.lock) { + if !reference::ref_eq(self, token.lock) { fail!("Can't downgrade() with a different rwlock's write_mode!"); } unsafe { 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/borrow.rs b/src/libstd/reference.rs similarity index 100% rename from src/libstd/borrow.rs rename to src/libstd/reference.rs 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); } } diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index f108d6cad6f..569acd3c7c6 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,7 +10,7 @@ #[feature(managed_boxes)]; -use std::borrow; +use std::reference; use std::ptr; fn borrow(x: &int, f: |x: &int|) { @@ -20,7 +20,7 @@ fn borrow(x: &int, f: |x: &int|) { fn test1(x: @~int) { borrow(&*(*x).clone(), |p| { let x_a = ptr::to_unsafe_ptr(&**x); - assert!((x_a as uint) != borrow::to_uint(p)); + assert!((x_a as uint) != reference::to_uint(p)); assert_eq!(unsafe{*x_a}, *p); }) } diff --git a/src/test/run-pass/cast-region-to-uint.rs b/src/test/run-pass/cast-region-to-uint.rs index 2a3f79e8245..150e0abe2eb 100644 --- a/src/test/run-pass/cast-region-to-uint.rs +++ b/src/test/run-pass/cast-region-to-uint.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::borrow; +use std::reference; pub fn main() { let x = 3; - info!("&x={:x}", borrow::to_uint(&x)); + info!("&x={:x}", reference::to_uint(&x)); } From d547f7ac216966240d90dd9b24fe2797dbec09e2 Mon Sep 17 00:00:00 2001 From: xales Date: Tue, 28 Jan 2014 19:56:06 -0500 Subject: [PATCH 2/3] Remove double-use of logging. --- src/libstd/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ac95fbd1fb1..b9ecf890458 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -223,7 +223,6 @@ mod std { pub use kinds; pub use local_data; pub use logging; - pub use logging; pub use option; pub use os; pub use rt; From f17d972014625eae13ac6d7fe98ff82a110a14d3 Mon Sep 17 00:00:00 2001 From: xales Date: Tue, 28 Jan 2014 21:05:57 -0500 Subject: [PATCH 3/3] Remove seldom-used std::reference functions. --- src/libextra/arc.rs | 5 ++-- src/libextra/sync.rs | 5 ++-- src/libstd/lib.rs | 2 +- src/libstd/reference.rs | 25 ------------------- src/libstd/rt/task.rs | 3 +-- .../borrowck-borrow-from-expr-block.rs | 3 +-- src/test/run-pass/cast-region-to-uint.rs | 4 +-- 7 files changed, 8 insertions(+), 39 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 709382358f1..7075007c546 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -47,7 +47,6 @@ use sync::{Mutex, RWLock}; use std::cast; use std::sync::arc::UnsafeArc; use std::task; -use std::reference; /// As sync::condvar, a mechanism for unlock-and-descheduling and signaling. pub struct Condvar<'a> { @@ -465,7 +464,7 @@ impl RWArc { // of this cast is removing the mutability.) let new_data = data; // Downgrade ensured the token belonged to us. Just a sanity check. - assert!(reference::ref_eq(&(*state).data, new_data)); + assert!((&(*state).data as *T as uint) == (new_data as *mut T as uint)); // Produce new token RWReadMode { data: new_data, diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 742b7831202..ca1574e1760 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -18,7 +18,6 @@ */ -use std::reference; use std::comm; use std::unstable::sync::Exclusive; use std::sync::arc::UnsafeArc; @@ -634,7 +633,7 @@ impl RWLock { /// To be called inside of the write_downgrade block. pub fn downgrade<'a>(&self, token: RWLockWriteMode<'a>) -> RWLockReadMode<'a> { - if !reference::ref_eq(self, token.lock) { + if !((self as *RWLock) == (token.lock as *RWLock)) { fail!("Can't downgrade() with a different rwlock's write_mode!"); } unsafe { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b9ecf890458..d7a7011319a 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 reference; +mod reference; pub mod rc; pub mod gc; diff --git a/src/libstd/reference.rs b/src/libstd/reference.rs index 66df4334adc..91f03f02892 100644 --- a/src/libstd/reference.rs +++ b/src/libstd/reference.rs @@ -13,18 +13,6 @@ #[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 { @@ -71,16 +59,3 @@ impl<'a, T: TotalEq> TotalEq for &'a T { 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 09b91c138bc..7c43e64f17b 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -14,7 +14,6 @@ //! to implement this. use any::AnyOwnExt; -use reference; use cast; use cleanup; use clone::Clone; @@ -287,7 +286,7 @@ impl Task { impl Drop for Task { fn drop(&mut self) { - rtdebug!("called drop for a task: {}", reference::to_uint(self)); + rtdebug!("called drop for a task: {}", self as *mut Task as uint); rtassert!(self.destroyed); } } diff --git a/src/test/run-pass/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck-borrow-from-expr-block.rs index 569acd3c7c6..fe1be6d06db 100644 --- a/src/test/run-pass/borrowck-borrow-from-expr-block.rs +++ b/src/test/run-pass/borrowck-borrow-from-expr-block.rs @@ -10,7 +10,6 @@ #[feature(managed_boxes)]; -use std::reference; use std::ptr; fn borrow(x: &int, f: |x: &int|) { @@ -20,7 +19,7 @@ fn borrow(x: &int, f: |x: &int|) { fn test1(x: @~int) { borrow(&*(*x).clone(), |p| { let x_a = ptr::to_unsafe_ptr(&**x); - assert!((x_a as uint) != reference::to_uint(p)); + assert!((x_a as uint) != (p as *int as uint)); assert_eq!(unsafe{*x_a}, *p); }) } diff --git a/src/test/run-pass/cast-region-to-uint.rs b/src/test/run-pass/cast-region-to-uint.rs index 150e0abe2eb..a831cd1da69 100644 --- a/src/test/run-pass/cast-region-to-uint.rs +++ b/src/test/run-pass/cast-region-to-uint.rs @@ -8,9 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::reference; - pub fn main() { let x = 3; - info!("&x={:x}", reference::to_uint(&x)); + info!("&x={:x}", (&x as *int as uint)); }