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};
/// 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> {
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,
}
// 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.
#[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 {
.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 }
}
}
#[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.
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);
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;
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() }
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 }
}
}
/// 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`.
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 {
&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
&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
// 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)
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) => {
pub fn from_pointer_kind(base_mutbl: MutabilityCategory,
ptr: PointerKind) -> MutabilityCategory {
match ptr {
- UniquePtr => {
+ Unique => {
base_mutbl.inherit()
}
BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
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))
}
}
}
cat_downcast(ref b, _) |
cat_interior(ref b, _) |
- cat_deref(ref b, _, UniquePtr) => {
+ cat_deref(ref b, _, Unique) => {
b.guarantor()
}
}
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)
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
match ptr {
- UniquePtr => "Box",
+ Unique => "Box",
BorrowedPtr(ty::ImmBorrow, _) |
Implicit(ty::ImmBorrow, _) => "&",
BorrowedPtr(ty::MutBorrow, _) |
// 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) {
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)
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())
}
}
- mc::cat_deref(b, _, mc::UniquePtr) => {
+ mc::cat_deref(b, _, mc::Unique) => {
assert_eq!(cmt.mutbl, mc::McInherited);
cmt = b;
}
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);
}
}
}
- mc::cat_deref(ref b, _, mc::UniquePtr) => {
+ mc::cat_deref(ref b, _, mc::Unique) => {
check_and_get_illegal_move_origin(bccx, b)
}
}
}
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)
}
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)
}
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
}
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.
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
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
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};
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)>,
return RawTable {
size: 0,
capacity: 0,
- hashes: UniquePtr::null(),
+ hashes: Unique::null(),
marker: marker::CovariantType,
};
}
RawTable {
capacity: capacity,
size: 0,
- hashes: UniquePtr(hashes),
+ hashes: Unique(hashes),
marker: marker::CovariantType,
}
}