diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6825a42ef08..3c6b2d2cbc0 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -19,7 +19,7 @@ use core::hash::{mod, Hash}; use core::kinds::Sized; use core::mem; use core::option::Option; -use core::ptr::UniquePtr; +use core::ptr::Unique; use core::raw::TraitObject; use core::result::Result; use core::result::Result::{Ok, Err}; @@ -45,7 +45,7 @@ pub static HEAP: () = (); /// A type that represents a uniquely-owned value. #[lang = "owned_box"] #[unstable = "custom allocators will add an additional type parameter (with default)"] -pub struct Box(UniquePtr); +pub struct Box(Unique); #[stable] impl Default for Box { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index e4522597b9d..d700b187e8a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -58,7 +58,7 @@ use core::kinds::marker::{ContravariantLifetime, InvariantType}; use core::mem; use core::num::{Int, UnsignedInt}; use core::ops; -use core::ptr::{mod, UniquePtr}; +use core::ptr::{mod, Unique}; use core::raw::Slice as RawSlice; use core::uint; @@ -133,7 +133,7 @@ use slice::CloneSliceExt; #[unsafe_no_drop_flag] #[stable] pub struct Vec { - ptr: UniquePtr, + ptr: Unique, len: uint, cap: uint, } @@ -176,7 +176,7 @@ impl Vec { // non-null value which is fine since we never call deallocate on the ptr // if cap is 0. The reason for this is because the pointer of a slice // being NULL would break the null pointer optimization for enums. - Vec { ptr: UniquePtr(EMPTY as *mut T), len: 0, cap: 0 } + Vec { ptr: Unique(EMPTY as *mut T), len: 0, cap: 0 } } /// Constructs a new, empty `Vec` with the specified capacity. @@ -209,7 +209,7 @@ impl Vec { #[stable] pub fn with_capacity(capacity: uint) -> Vec { if mem::size_of::() == 0 { - Vec { ptr: UniquePtr(EMPTY as *mut T), len: 0, cap: uint::MAX } + Vec { ptr: Unique(EMPTY as *mut T), len: 0, cap: uint::MAX } } else if capacity == 0 { Vec::new() } else { @@ -217,7 +217,7 @@ impl Vec { .expect("capacity overflow"); let ptr = unsafe { allocate(size, mem::min_align_of::()) }; if ptr.is_null() { ::alloc::oom() } - Vec { ptr: UniquePtr(ptr as *mut T), len: 0, cap: capacity } + Vec { ptr: Unique(ptr as *mut T), len: 0, cap: capacity } } } @@ -284,7 +284,7 @@ impl Vec { #[unstable = "needs finalization"] pub unsafe fn from_raw_parts(ptr: *mut T, length: uint, capacity: uint) -> Vec { - Vec { ptr: UniquePtr(ptr), len: length, cap: capacity } + Vec { ptr: Unique(ptr), len: length, cap: capacity } } /// Creates a vector by copying the elements from a raw pointer. @@ -803,7 +803,7 @@ impl Vec { unsafe { // Overflow check is unnecessary as the vector is already at // least this large. - self.ptr = UniquePtr(reallocate(self.ptr.0 as *mut u8, + self.ptr = Unique(reallocate(self.ptr.0 as *mut u8, self.cap * mem::size_of::(), self.len * mem::size_of::(), mem::min_align_of::()) as *mut T); @@ -1110,7 +1110,7 @@ impl Vec { let size = max(old_size, 2 * mem::size_of::()) * 2; if old_size > size { panic!("capacity overflow") } unsafe { - self.ptr = UniquePtr(alloc_or_realloc(self.ptr.0, old_size, size)); + self.ptr = Unique(alloc_or_realloc(self.ptr.0, old_size, size)); if self.ptr.0.is_null() { ::alloc::oom() } } self.cap = max(self.cap, 2) * 2; @@ -1231,7 +1231,7 @@ impl Vec { let size = capacity.checked_mul(mem::size_of::()) .expect("capacity overflow"); unsafe { - self.ptr = UniquePtr(alloc_or_realloc(self.ptr.0, + self.ptr = Unique(alloc_or_realloc(self.ptr.0, self.cap * mem::size_of::(), size)); if self.ptr.0.is_null() { ::alloc::oom() } @@ -1420,7 +1420,7 @@ impl IntoIter { for _x in self { } let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self; mem::forget(self); - Vec { ptr: UniquePtr(allocation), cap: cap, len: 0 } + Vec { ptr: Unique(allocation), cap: cap, len: 0 } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 402e85b4d8b..8c9d77a0e9c 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -505,28 +505,28 @@ impl PartialOrd for *mut T { /// A wrapper around a raw `*mut T` that indicates that the possessor /// of this wrapper owns the referent. This in turn implies that the -/// `UniquePtr` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a +/// `Unique` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a /// raw `*mut T` (which conveys no particular ownership semantics). /// Useful for building abstractions like `Vec` or `Box`, which /// internally use raw pointers to manage the memory that they own. -pub struct UniquePtr(pub *mut T); +pub struct Unique(pub *mut T); -/// `UniquePtr` pointers are `Send` if `T` is `Send` because the data they +/// `Unique` pointers are `Send` if `T` is `Send` because the data they /// reference is unaliased. Note that this aliasing invariant is /// unenforced by the type system; the abstraction using the -/// `UniquePtr` must enforce it. -unsafe impl Send for UniquePtr { } +/// `Unique` must enforce it. +unsafe impl Send for Unique { } -/// `UniquePtr` pointers are `Sync` if `T` is `Sync` because the data they +/// `Unique` pointers are `Sync` if `T` is `Sync` because the data they /// reference is unaliased. Note that this aliasing invariant is /// unenforced by the type system; the abstraction using the -/// `UniquePtr` must enforce it. -unsafe impl Sync for UniquePtr { } +/// `Unique` must enforce it. +unsafe impl Sync for Unique { } -impl UniquePtr { - /// Returns a null UniquePtr. - pub fn null() -> UniquePtr { - UniquePtr(RawPtr::null()) +impl Unique { + /// Returns a null Unique. + pub fn null() -> Unique { + Unique(RawPtr::null()) } /// Return an (unsafe) pointer into the memory owned by `self`. diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 3326960baa8..8c4f74027a5 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -29,7 +29,7 @@ extern crate libc; use libc::{c_void, size_t, c_int}; use std::c_vec::CVec; -use std::ptr::UniquePtr; +use std::ptr::Unique; #[link(name = "miniz", kind = "static")] extern { @@ -60,7 +60,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option> { &mut outsz, flags); if !res.is_null() { - let res = UniquePtr(res); + let res = Unique(res); Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0))) } else { None @@ -86,7 +86,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option> { &mut outsz, flags); if !res.is_null() { - let res = UniquePtr(res); + let res = Unique(res); Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0))) } else { None diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index ad74c8d8bda..d81894a3daf 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -113,7 +113,7 @@ pub struct Upvar { // different kinds of pointers: #[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)] pub enum PointerKind { - UniquePtr, + Unique, BorrowedPtr(ty::BorrowKind, ty::Region), Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr. UnsafePtr(ast::Mutability) @@ -199,7 +199,7 @@ pub fn opt_deref_kind(t: Ty) -> Option { match t.sty { ty::ty_uniq(_) | ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => { - Some(deref_ptr(UniquePtr)) + Some(deref_ptr(Unique)) } ty::ty_rptr(r, mt) => { @@ -315,7 +315,7 @@ impl MutabilityCategory { pub fn from_pointer_kind(base_mutbl: MutabilityCategory, ptr: PointerKind) -> MutabilityCategory { match ptr { - UniquePtr => { + Unique => { base_mutbl.inherit() } BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => { @@ -1351,7 +1351,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { Implicit(..) => { "dereference (dereference is implicit, due to indexing)".to_string() } - UniquePtr => format!("dereference of `{}`", ptr_sigil(pk)), + Unique => format!("dereference of `{}`", ptr_sigil(pk)), _ => format!("dereference of `{}`-pointer", ptr_sigil(pk)) } } @@ -1412,7 +1412,7 @@ impl<'tcx> cmt_<'tcx> { } cat_downcast(ref b, _) | cat_interior(ref b, _) | - cat_deref(ref b, _, UniquePtr) => { + cat_deref(ref b, _, Unique) => { b.guarantor() } } @@ -1431,7 +1431,7 @@ impl<'tcx> cmt_<'tcx> { cat_deref(ref b, _, BorrowedPtr(ty::UniqueImmBorrow, _)) | cat_deref(ref b, _, Implicit(ty::UniqueImmBorrow, _)) | cat_downcast(ref b, _) | - cat_deref(ref b, _, UniquePtr) | + cat_deref(ref b, _, Unique) | cat_interior(ref b, _) => { // Aliasability depends on base cmt b.freely_aliasable(ctxt) @@ -1523,7 +1523,7 @@ impl<'tcx> Repr<'tcx> for categorization<'tcx> { pub fn ptr_sigil(ptr: PointerKind) -> &'static str { match ptr { - UniquePtr => "Box", + Unique => "Box", BorrowedPtr(ty::ImmBorrow, _) | Implicit(ty::ImmBorrow, _) => "&", BorrowedPtr(ty::MutBorrow, _) | diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 4ae9e60299a..4ad060202ee 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -33,11 +33,11 @@ use std::rc::Rc; // FIXME (#16118): These functions are intended to allow the borrow checker to // be less precise in its handling of Box while still allowing moves out of a -// Box. They should be removed when UniquePtr is removed from LoanPath. +// Box. They should be removed when Unique is removed from LoanPath. fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<'tcx> { - //! Returns the base of the leftmost dereference of an UniquePtr in - //! `loan_path`. If there is no dereference of an UniquePtr in `loan_path`, + //! Returns the base of the leftmost dereference of an Unique in + //! `loan_path`. If there is no dereference of an Unique in `loan_path`, //! then it just returns `loan_path` itself. return match helper(loan_path) { @@ -48,7 +48,7 @@ fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath< fn helper<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> Option<&'a LoanPath<'tcx>> { match loan_path.kind { LpVar(_) | LpUpvar(_) => None, - LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => { + LpExtend(ref lp_base, _, LpDeref(mc::Unique)) => { match helper(&**lp_base) { v @ Some(_) => v, None => Some(&**lp_base) @@ -72,7 +72,7 @@ fn owned_ptr_base_path_rc<'tcx>(loan_path: &Rc>) -> Rc(loan_path: &Rc>) -> Option>> { match loan_path.kind { LpVar(_) | LpUpvar(_) => None, - LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => { + LpExtend(ref lp_base, _, LpDeref(mc::Unique)) => { match helper(lp_base) { v @ Some(_) => v, None => Some(lp_base.clone()) @@ -880,7 +880,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { } } - mc::cat_deref(b, _, mc::UniquePtr) => { + mc::cat_deref(b, _, mc::Unique) => { assert_eq!(cmt.mutbl, mc::McInherited); cmt = b; } diff --git a/src/librustc_borrowck/borrowck/fragments.rs b/src/librustc_borrowck/borrowck/fragments.rs index 5530b8f39ec..ef9130bb607 100644 --- a/src/librustc_borrowck/borrowck/fragments.rs +++ b/src/librustc_borrowck/borrowck/fragments.rs @@ -291,9 +291,9 @@ fn add_fragment_siblings<'tcx>(this: &MoveData<'tcx>, add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id); } - // *LV for UniquePtr consumes the contents of the box (at + // *LV for Unique consumes the contents of the box (at // least when it is non-copy...), so propagate inward. - LpExtend(ref loan_parent, _, LpDeref(mc::UniquePtr)) => { + LpExtend(ref loan_parent, _, LpDeref(mc::Unique)) => { add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id); } diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 5eb16447057..ed5abda6f7c 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -190,7 +190,7 @@ fn check_and_get_illegal_move_origin<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, } } - mc::cat_deref(ref b, _, mc::UniquePtr) => { + mc::cat_deref(ref b, _, mc::Unique) => { check_and_get_illegal_move_origin(bccx, b) } } diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs index 39670314cd1..1c57097ae26 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { } mc::cat_downcast(ref base, _) | - mc::cat_deref(ref base, _, mc::UniquePtr) | // L-Deref-Send + mc::cat_deref(ref base, _, mc::Unique) | // L-Deref-Send mc::cat_interior(ref base, _) => { // L-Field self.check(base, discr_scope) } @@ -129,7 +129,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { r } mc::cat_downcast(ref cmt, _) | - mc::cat_deref(ref cmt, _, mc::UniquePtr) | + mc::cat_deref(ref cmt, _, mc::Unique) | mc::cat_interior(ref cmt, _) => { self.scope(cmt) } diff --git a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs index d940b1079fc..1773e8cb233 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs @@ -107,7 +107,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> { mc::cat_deref(cmt_base, _, pk) => { match pk { - mc::UniquePtr => { + mc::Unique => { // R-Deref-Send-Pointer // // When we borrow the interior of an owned pointer, we diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index dda6240ad82..87fa8261575 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -1460,7 +1460,7 @@ fn link_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, } mc::cat_downcast(cmt_base, _) | - mc::cat_deref(cmt_base, _, mc::UniquePtr) | + mc::cat_deref(cmt_base, _, mc::Unique) | mc::cat_interior(cmt_base, _) => { // Borrowing interior or owned data requires the base // to be valid and borrowable in the same fashion. @@ -1684,7 +1684,7 @@ fn adjust_upvar_borrow_kind_for_mut<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, cmt.repr(rcx.tcx())); match cmt.cat.clone() { - mc::cat_deref(base, _, mc::UniquePtr) | + mc::cat_deref(base, _, mc::Unique) | mc::cat_interior(base, _) | mc::cat_downcast(base, _) => { // Interior or owned data is mutable if base is @@ -1731,7 +1731,7 @@ fn adjust_upvar_borrow_kind_for_unique<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>, cmt: mc::c cmt.repr(rcx.tcx())); match cmt.cat.clone() { - mc::cat_deref(base, _, mc::UniquePtr) | + mc::cat_deref(base, _, mc::Unique) | mc::cat_interior(base, _) | mc::cat_downcast(base, _) => { // Interior or owned data is unique if base is diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 643c2b7d074..3ae3a8ffbad 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -23,7 +23,7 @@ use num::{Int, UnsignedInt}; use ops::{Deref, DerefMut, Drop}; use option::Option; use option::Option::{Some, None}; -use ptr::{UniquePtr, RawPtr, copy_nonoverlapping_memory, zero_memory}; +use ptr::{Unique, RawPtr, copy_nonoverlapping_memory, zero_memory}; use ptr; use rt::heap::{allocate, deallocate}; @@ -69,7 +69,7 @@ const EMPTY_BUCKET: u64 = 0u64; pub struct RawTable { capacity: uint, size: uint, - hashes: UniquePtr, + hashes: Unique, // Because K/V do not appear directly in any of the types in the struct, // inform rustc that in fact instances of K and V are reachable from here. marker: marker::CovariantType<(K,V)>, @@ -563,7 +563,7 @@ impl RawTable { return RawTable { size: 0, capacity: 0, - hashes: UniquePtr::null(), + hashes: Unique::null(), marker: marker::CovariantType, }; } @@ -602,7 +602,7 @@ impl RawTable { RawTable { capacity: capacity, size: 0, - hashes: UniquePtr(hashes), + hashes: Unique(hashes), marker: marker::CovariantType, } }