]> git.lizzy.rs Git - rust.git/commitdiff
Rename `UniquePtr` to `Unique`
authorFlavio Percoco <flaper87@gmail.com>
Mon, 22 Dec 2014 13:25:58 +0000 (14:25 +0100)
committerFlavio Percoco <flaper87@gmail.com>
Fri, 26 Dec 2014 16:26:33 +0000 (17:26 +0100)
Mostly following the convention in RFC 356

12 files changed:
src/liballoc/boxed.rs
src/libcollections/vec.rs
src/libcore/ptr.rs
src/libflate/lib.rs
src/librustc/middle/mem_categorization.rs
src/librustc_borrowck/borrowck/check_loans.rs
src/librustc_borrowck/borrowck/fragments.rs
src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
src/librustc_typeck/check/regionck.rs
src/libstd/collections/hash/table.rs

index 6825a42ef088e284ce77505e3c68b9af3affbfb5..3c6b2d2cbc068904bc2f87e6aa7b844eafb9f49b 100644 (file)
@@ -19,7 +19,7 @@
 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 @@
 /// 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<T>(UniquePtr<T>);
+pub struct Box<T>(Unique<T>);
 
 #[stable]
 impl<T: Default> Default for Box<T> {
index e4522597b9d93cf00b2cf37f73dbcd2336b13c3e..d700b187e8a6d6265be52aede3006e0cdfaee8cb 100644 (file)
@@ -58,7 +58,7 @@
 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;
 
 #[unsafe_no_drop_flag]
 #[stable]
 pub struct Vec<T> {
-    ptr: UniquePtr<T>,
+    ptr: Unique<T>,
     len: uint,
     cap: uint,
 }
@@ -176,7 +176,7 @@ pub fn new() -> Vec<T> {
         // 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<T>` with the specified capacity.
@@ -209,7 +209,7 @@ pub fn new() -> Vec<T> {
     #[stable]
     pub fn with_capacity(capacity: uint) -> Vec<T> {
         if mem::size_of::<T>() == 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 @@ pub fn with_capacity(capacity: uint) -> Vec<T> {
                                .expect("capacity overflow");
             let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
             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 @@ pub fn from_fn<F>(length: uint, mut op: F) -> Vec<T> where F: FnMut(uint) -> T {
     #[unstable = "needs finalization"]
     pub unsafe fn from_raw_parts(ptr: *mut T, length: uint,
                                  capacity: uint) -> Vec<T> {
-        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 @@ pub fn shrink_to_fit(&mut self) {
             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::<T>(),
                                                self.len * mem::size_of::<T>(),
                                                mem::min_align_of::<T>()) as *mut T);
@@ -1110,7 +1110,7 @@ pub fn push(&mut self, value: T) {
             let size = max(old_size, 2 * mem::size_of::<T>()) * 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 @@ fn grow_capacity(&mut self, capacity: uint) {
             let size = capacity.checked_mul(mem::size_of::<T>())
                                .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::<T>(),
                                                      size));
                 if self.ptr.0.is_null() { ::alloc::oom() }
@@ -1420,7 +1420,7 @@ pub fn into_inner(mut self) -> Vec<T> {
             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 }
         }
     }
 
index 402e85b4d8b22b6c0dd85071a15782584739d146..8c9d77a0e9cd7f48789bda02c81fcb6d92921ae5 100644 (file)
@@ -505,28 +505,28 @@ fn ge(&self, other: &*mut T) -> bool { *self >= *other }
 
 /// 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<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a
+/// `Unique<T>` 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<T>` or `Box<T>`, which
 /// internally use raw pointers to manage the memory that they own.
-pub struct UniquePtr<T>(pub *mut T);
+pub struct Unique<T>(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<T:Send> Send for UniquePtr<T> { }
+/// `Unique` must enforce it.
+unsafe impl<T:Send> Send for Unique<T> { }
 
-/// `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<T:Sync> Sync for UniquePtr<T> { }
+/// `Unique` must enforce it.
+unsafe impl<T:Sync> Sync for Unique<T> { }
 
-impl<T> UniquePtr<T> {
-    /// Returns a null UniquePtr.
-    pub fn null() -> UniquePtr<T> {
-        UniquePtr(RawPtr::null())
+impl<T> Unique<T> {
+    /// Returns a null Unique.
+    pub fn null() -> Unique<T> {
+        Unique(RawPtr::null())
     }
 
     /// Return an (unsafe) pointer into the memory owned by `self`.
index 3326960baa8f432b4501ebe9cac8c1ac80ff4e7e..8c4f74027a52f0a7a9ede9a5b4e7d8b17ebcadb5 100644 (file)
@@ -29,7 +29,7 @@
 
 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<CVec<u8>> {
                                              &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<CVec<u8>> {
                                                &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
index ad74c8d8bda4f2ff73f9359c1c421defc68eebd6..d81894a3dafca4e0ee6606102c757c2b51bd16f0 100644 (file)
@@ -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<deref_kind> {
     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 @@ pub fn from_borrow_kind(borrow_kind: ty::BorrowKind) -> 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 @@ fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String {
                           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 @@ pub fn guarantor(&self) -> 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 @@ pub fn freely_aliasable(&self, ctxt: &ty::ctxt<'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 @@ fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
 
 pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
     match ptr {
-        UniquePtr => "Box",
+        Unique => "Box",
         BorrowedPtr(ty::ImmBorrow, _) |
         Implicit(ty::ImmBorrow, _) => "&",
         BorrowedPtr(ty::MutBorrow, _) |
index 4ae9e60299abc440c099cb8bb00e1fe7467c7643..4ad060202ee43149fa28ff42cf8442d7c41420fe 100644 (file)
 
 // 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<LoanPath<'tcx>>) -> Rc<LoanPath<'
     fn helper<'tcx>(loan_path: &Rc<LoanPath<'tcx>>) -> Option<Rc<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.clone())
@@ -880,7 +880,7 @@ fn mark_variable_as_used_mut<'a, 'tcx>(this: &CheckLoanCtxt<'a, 'tcx>,
                         }
                     }
 
-                    mc::cat_deref(b, _, mc::UniquePtr) => {
+                    mc::cat_deref(b, _, mc::Unique) => {
                         assert_eq!(cmt.mutbl, mc::McInherited);
                         cmt = b;
                     }
index 5530b8f39ec59a9adf6b3416873476c0f43ef338..ef9130bb607d816eb23aaa31579fafde4ab12910 100644 (file)
@@ -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);
         }
 
index 5eb1644705751e8ed1f5fba38d6fc2aedb46e8da..ed5abda6f7cf694392e8cbd3b63ee99209236eb0 100644 (file)
@@ -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)
         }
     }
index 39670314cd13683a10736036636824d3adca16dc..1c57097ae26339a9c70626cc96617836836521a1 100644 (file)
@@ -84,7 +84,7 @@ fn check(&self, cmt: &mc::cmt<'tcx>, discr_scope: Option<ast::NodeId>) -> R {
             }
 
             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 @@ fn scope(&self, cmt: &mc::cmt) -> ty::Region {
                 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)
             }
index d940b1079fc162bfd1fdbdb0ccc51fd95d5a40cb..1773e8cb2335401c281754b41416cc1b9cb18c4a 100644 (file)
@@ -107,7 +107,7 @@ fn restrict(&self,
 
             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
index dda6240ad8286edc5c472a2c9f10b3f4cbab05d7..87fa826157596f92cdc107541f5b9443bee46488 100644 (file)
@@ -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
index 643c2b7d074950d16a447ec2aa485d26141dfff0..3ae3a8ffbad3bfe3399559851dbbecdbec3c1018 100644 (file)
@@ -23,7 +23,7 @@
 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 @@
 pub struct RawTable<K, V> {
     capacity: uint,
     size:     uint,
-    hashes:   UniquePtr<u64>,
+    hashes:   Unique<u64>,
     // 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 @@ unsafe fn new_uninitialized(capacity: uint) -> RawTable<K, V> {
             return RawTable {
                 size: 0,
                 capacity: 0,
-                hashes: UniquePtr::null(),
+                hashes: Unique::null(),
                 marker: marker::CovariantType,
             };
         }
@@ -602,7 +602,7 @@ unsafe fn new_uninitialized(capacity: uint) -> RawTable<K, V> {
         RawTable {
             capacity: capacity,
             size:     0,
-            hashes:   UniquePtr(hashes),
+            hashes:   Unique(hashes),
             marker:   marker::CovariantType,
         }
     }