Skip to content

Commit 686ce66

Browse files
committed
Rename OwnedPtr to UniquePtr
1 parent fb803a8 commit 686ce66

File tree

12 files changed

+53
-53
lines changed

12 files changed

+53
-53
lines changed

src/liballoc/boxed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use core::hash::{mod, Hash};
1919
use core::kinds::Sized;
2020
use core::mem;
2121
use core::option::Option;
22-
use core::ptr::OwnedPtr;
22+
use core::ptr::UniquePtr;
2323
use core::raw::TraitObject;
2424
use core::result::Result;
2525
use core::result::Result::{Ok, Err};
@@ -45,7 +45,7 @@ pub static HEAP: () = ();
4545
/// A type that represents a uniquely-owned value.
4646
#[lang = "owned_box"]
4747
#[unstable = "custom allocators will add an additional type parameter (with default)"]
48-
pub struct Box<T>(OwnedPtr<T>);
48+
pub struct Box<T>(UniquePtr<T>);
4949

5050
#[stable]
5151
impl<T: Default> Default for Box<T> {

src/libcollections/vec.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use core::kinds::marker::{ContravariantLifetime, InvariantType};
5858
use core::mem;
5959
use core::num::{Int, UnsignedInt};
6060
use core::ops;
61-
use core::ptr::{mod, OwnedPtr};
61+
use core::ptr::{mod, UniquePtr};
6262
use core::raw::Slice as RawSlice;
6363
use core::uint;
6464

@@ -133,7 +133,7 @@ use slice::CloneSliceExt;
133133
#[unsafe_no_drop_flag]
134134
#[stable]
135135
pub struct Vec<T> {
136-
ptr: OwnedPtr<T>,
136+
ptr: UniquePtr<T>,
137137
len: uint,
138138
cap: uint,
139139
}
@@ -176,7 +176,7 @@ impl<T> Vec<T> {
176176
// non-null value which is fine since we never call deallocate on the ptr
177177
// if cap is 0. The reason for this is because the pointer of a slice
178178
// being NULL would break the null pointer optimization for enums.
179-
Vec { ptr: OwnedPtr(EMPTY as *mut T), len: 0, cap: 0 }
179+
Vec { ptr: UniquePtr(EMPTY as *mut T), len: 0, cap: 0 }
180180
}
181181

182182
/// Constructs a new, empty `Vec<T>` with the specified capacity.
@@ -209,15 +209,15 @@ impl<T> Vec<T> {
209209
#[stable]
210210
pub fn with_capacity(capacity: uint) -> Vec<T> {
211211
if mem::size_of::<T>() == 0 {
212-
Vec { ptr: OwnedPtr(EMPTY as *mut T), len: 0, cap: uint::MAX }
212+
Vec { ptr: UniquePtr(EMPTY as *mut T), len: 0, cap: uint::MAX }
213213
} else if capacity == 0 {
214214
Vec::new()
215215
} else {
216216
let size = capacity.checked_mul(mem::size_of::<T>())
217217
.expect("capacity overflow");
218218
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
219219
if ptr.is_null() { ::alloc::oom() }
220-
Vec { ptr: OwnedPtr(ptr as *mut T), len: 0, cap: capacity }
220+
Vec { ptr: UniquePtr(ptr as *mut T), len: 0, cap: capacity }
221221
}
222222
}
223223

@@ -284,7 +284,7 @@ impl<T> Vec<T> {
284284
#[unstable = "needs finalization"]
285285
pub unsafe fn from_raw_parts(ptr: *mut T, length: uint,
286286
capacity: uint) -> Vec<T> {
287-
Vec { ptr: OwnedPtr(ptr), len: length, cap: capacity }
287+
Vec { ptr: UniquePtr(ptr), len: length, cap: capacity }
288288
}
289289

290290
/// Creates a vector by copying the elements from a raw pointer.
@@ -803,7 +803,7 @@ impl<T> Vec<T> {
803803
unsafe {
804804
// Overflow check is unnecessary as the vector is already at
805805
// least this large.
806-
self.ptr = OwnedPtr(reallocate(self.ptr.0 as *mut u8,
806+
self.ptr = UniquePtr(reallocate(self.ptr.0 as *mut u8,
807807
self.cap * mem::size_of::<T>(),
808808
self.len * mem::size_of::<T>(),
809809
mem::min_align_of::<T>()) as *mut T);
@@ -1110,7 +1110,7 @@ impl<T> Vec<T> {
11101110
let size = max(old_size, 2 * mem::size_of::<T>()) * 2;
11111111
if old_size > size { panic!("capacity overflow") }
11121112
unsafe {
1113-
self.ptr = OwnedPtr(alloc_or_realloc(self.ptr.0, old_size, size));
1113+
self.ptr = UniquePtr(alloc_or_realloc(self.ptr.0, old_size, size));
11141114
if self.ptr.0.is_null() { ::alloc::oom() }
11151115
}
11161116
self.cap = max(self.cap, 2) * 2;
@@ -1231,7 +1231,7 @@ impl<T> Vec<T> {
12311231
let size = capacity.checked_mul(mem::size_of::<T>())
12321232
.expect("capacity overflow");
12331233
unsafe {
1234-
self.ptr = OwnedPtr(alloc_or_realloc(self.ptr.0,
1234+
self.ptr = UniquePtr(alloc_or_realloc(self.ptr.0,
12351235
self.cap * mem::size_of::<T>(),
12361236
size));
12371237
if self.ptr.0.is_null() { ::alloc::oom() }
@@ -1420,7 +1420,7 @@ impl<T> IntoIter<T> {
14201420
for _x in self { }
14211421
let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self;
14221422
mem::forget(self);
1423-
Vec { ptr: OwnedPtr(allocation), cap: cap, len: 0 }
1423+
Vec { ptr: UniquePtr(allocation), cap: cap, len: 0 }
14241424
}
14251425
}
14261426

src/libcore/ptr.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -505,28 +505,28 @@ impl<T> PartialOrd for *mut T {
505505

506506
/// A wrapper around a raw `*mut T` that indicates that the possessor
507507
/// of this wrapper owns the referent. This in turn implies that the
508-
/// `OwnedPtr<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a
508+
/// `UniquePtr<T>` is `Send`/`Sync` if `T` is `Send`/`Sync`, unlike a
509509
/// raw `*mut T` (which conveys no particular ownership semantics).
510510
/// Useful for building abstractions like `Vec<T>` or `Box<T>`, which
511511
/// internally use raw pointers to manage the memory that they own.
512-
pub struct OwnedPtr<T>(pub *mut T);
512+
pub struct UniquePtr<T>(pub *mut T);
513513

514-
/// `OwnedPtr` pointers are `Send` if `T` is `Send` because the data they
514+
/// `UniquePtr` pointers are `Send` if `T` is `Send` because the data they
515515
/// reference is unaliased. Note that this aliasing invariant is
516516
/// unenforced by the type system; the abstraction using the
517-
/// `OwnedPtr` must enforce it.
518-
impl<T:Send> Send for OwnedPtr<T> { }
517+
/// `UniquePtr` must enforce it.
518+
impl<T:Send> Send for UniquePtr<T> { }
519519

520-
/// `OwnedPtr` pointers are `Sync` if `T` is `Sync` because the data they
520+
/// `UniquePtr` pointers are `Sync` if `T` is `Sync` because the data they
521521
/// reference is unaliased. Note that this aliasing invariant is
522522
/// unenforced by the type system; the abstraction using the
523-
/// `OwnedPtr` must enforce it.
524-
impl<T:Sync> Sync for OwnedPtr<T> { }
523+
/// `UniquePtr` must enforce it.
524+
impl<T:Sync> Sync for UniquePtr<T> { }
525525

526-
impl<T> OwnedPtr<T> {
527-
/// Returns a null OwnedPtr.
528-
pub fn null() -> OwnedPtr<T> {
529-
OwnedPtr(RawPtr::null())
526+
impl<T> UniquePtr<T> {
527+
/// Returns a null UniquePtr.
528+
pub fn null() -> UniquePtr<T> {
529+
UniquePtr(RawPtr::null())
530530
}
531531

532532
/// Return an (unsafe) pointer into the memory owned by `self`.

src/libflate/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern crate libc;
2929

3030
use libc::{c_void, size_t, c_int};
3131
use std::c_vec::CVec;
32-
use std::ptr::OwnedPtr;
32+
use std::ptr::UniquePtr;
3333

3434
#[link(name = "miniz", kind = "static")]
3535
extern {
@@ -60,7 +60,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
6060
&mut outsz,
6161
flags);
6262
if !res.is_null() {
63-
let res = OwnedPtr(res);
63+
let res = UniquePtr(res);
6464
Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0)))
6565
} else {
6666
None
@@ -86,7 +86,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
8686
&mut outsz,
8787
flags);
8888
if !res.is_null() {
89-
let res = OwnedPtr(res);
89+
let res = UniquePtr(res);
9090
Some(CVec::new_with_dtor(res.0 as *mut u8, outsz as uint, move|:| libc::free(res.0)))
9191
} else {
9292
None

src/librustc/middle/mem_categorization.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub struct Upvar {
113113
// different kinds of pointers:
114114
#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show)]
115115
pub enum PointerKind {
116-
OwnedPtr,
116+
UniquePtr,
117117
BorrowedPtr(ty::BorrowKind, ty::Region),
118118
Implicit(ty::BorrowKind, ty::Region), // Implicit deref of a borrowed ptr.
119119
UnsafePtr(ast::Mutability)
@@ -199,7 +199,7 @@ pub fn opt_deref_kind(t: Ty) -> Option<deref_kind> {
199199
match t.sty {
200200
ty::ty_uniq(_) |
201201
ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
202-
Some(deref_ptr(OwnedPtr))
202+
Some(deref_ptr(UniquePtr))
203203
}
204204

205205
ty::ty_rptr(r, mt) => {
@@ -315,7 +315,7 @@ impl MutabilityCategory {
315315
pub fn from_pointer_kind(base_mutbl: MutabilityCategory,
316316
ptr: PointerKind) -> MutabilityCategory {
317317
match ptr {
318-
OwnedPtr => {
318+
UniquePtr => {
319319
base_mutbl.inherit()
320320
}
321321
BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
@@ -1351,7 +1351,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
13511351
Implicit(..) => {
13521352
"dereference (dereference is implicit, due to indexing)".to_string()
13531353
}
1354-
OwnedPtr => format!("dereference of `{}`", ptr_sigil(pk)),
1354+
UniquePtr => format!("dereference of `{}`", ptr_sigil(pk)),
13551355
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
13561356
}
13571357
}
@@ -1412,7 +1412,7 @@ impl<'tcx> cmt_<'tcx> {
14121412
}
14131413
cat_downcast(ref b, _) |
14141414
cat_interior(ref b, _) |
1415-
cat_deref(ref b, _, OwnedPtr) => {
1415+
cat_deref(ref b, _, UniquePtr) => {
14161416
b.guarantor()
14171417
}
14181418
}
@@ -1431,7 +1431,7 @@ impl<'tcx> cmt_<'tcx> {
14311431
cat_deref(ref b, _, BorrowedPtr(ty::UniqueImmBorrow, _)) |
14321432
cat_deref(ref b, _, Implicit(ty::UniqueImmBorrow, _)) |
14331433
cat_downcast(ref b, _) |
1434-
cat_deref(ref b, _, OwnedPtr) |
1434+
cat_deref(ref b, _, UniquePtr) |
14351435
cat_interior(ref b, _) => {
14361436
// Aliasability depends on base cmt
14371437
b.freely_aliasable(ctxt)
@@ -1523,7 +1523,7 @@ impl<'tcx> Repr<'tcx> for categorization<'tcx> {
15231523

15241524
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
15251525
match ptr {
1526-
OwnedPtr => "Box",
1526+
UniquePtr => "Box",
15271527
BorrowedPtr(ty::ImmBorrow, _) |
15281528
Implicit(ty::ImmBorrow, _) => "&",
15291529
BorrowedPtr(ty::MutBorrow, _) |

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ use std::rc::Rc;
3333

3434
// FIXME (#16118): These functions are intended to allow the borrow checker to
3535
// be less precise in its handling of Box while still allowing moves out of a
36-
// Box. They should be removed when OwnedPtr is removed from LoanPath.
36+
// Box. They should be removed when UniquePtr is removed from LoanPath.
3737

3838
fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<'tcx> {
39-
//! Returns the base of the leftmost dereference of an OwnedPtr in
40-
//! `loan_path`. If there is no dereference of an OwnedPtr in `loan_path`,
39+
//! Returns the base of the leftmost dereference of an UniquePtr in
40+
//! `loan_path`. If there is no dereference of an UniquePtr in `loan_path`,
4141
//! then it just returns `loan_path` itself.
4242
4343
return match helper(loan_path) {
@@ -48,7 +48,7 @@ fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<
4848
fn helper<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> Option<&'a LoanPath<'tcx>> {
4949
match loan_path.kind {
5050
LpVar(_) | LpUpvar(_) => None,
51-
LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) => {
51+
LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => {
5252
match helper(&**lp_base) {
5353
v @ Some(_) => v,
5454
None => Some(&**lp_base)
@@ -72,7 +72,7 @@ fn owned_ptr_base_path_rc<'tcx>(loan_path: &Rc<LoanPath<'tcx>>) -> Rc<LoanPath<'
7272
fn helper<'tcx>(loan_path: &Rc<LoanPath<'tcx>>) -> Option<Rc<LoanPath<'tcx>>> {
7373
match loan_path.kind {
7474
LpVar(_) | LpUpvar(_) => None,
75-
LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) => {
75+
LpExtend(ref lp_base, _, LpDeref(mc::UniquePtr)) => {
7676
match helper(lp_base) {
7777
v @ Some(_) => v,
7878
None => Some(lp_base.clone())
@@ -880,7 +880,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
880880
}
881881
}
882882

883-
mc::cat_deref(b, _, mc::OwnedPtr) => {
883+
mc::cat_deref(b, _, mc::UniquePtr) => {
884884
assert_eq!(cmt.mutbl, mc::McInherited);
885885
cmt = b;
886886
}

src/librustc_borrowck/borrowck/fragments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ fn add_fragment_siblings<'tcx>(this: &MoveData<'tcx>,
291291
add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id);
292292
}
293293

294-
// *LV for OwnedPtr consumes the contents of the box (at
294+
// *LV for UniquePtr consumes the contents of the box (at
295295
// least when it is non-copy...), so propagate inward.
296-
LpExtend(ref loan_parent, _, LpDeref(mc::OwnedPtr)) => {
296+
LpExtend(ref loan_parent, _, LpDeref(mc::UniquePtr)) => {
297297
add_fragment_siblings(this, tcx, gathered_fragments, loan_parent.clone(), origin_id);
298298
}
299299

src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn check_and_get_illegal_move_origin<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
190190
}
191191
}
192192

193-
mc::cat_deref(ref b, _, mc::OwnedPtr) => {
193+
mc::cat_deref(ref b, _, mc::UniquePtr) => {
194194
check_and_get_illegal_move_origin(bccx, b)
195195
}
196196
}

src/librustc_borrowck/borrowck/gather_loans/lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
8484
}
8585

8686
mc::cat_downcast(ref base, _) |
87-
mc::cat_deref(ref base, _, mc::OwnedPtr) | // L-Deref-Send
87+
mc::cat_deref(ref base, _, mc::UniquePtr) | // L-Deref-Send
8888
mc::cat_interior(ref base, _) => { // L-Field
8989
self.check(base, discr_scope)
9090
}
@@ -129,7 +129,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
129129
r
130130
}
131131
mc::cat_downcast(ref cmt, _) |
132-
mc::cat_deref(ref cmt, _, mc::OwnedPtr) |
132+
mc::cat_deref(ref cmt, _, mc::UniquePtr) |
133133
mc::cat_interior(ref cmt, _) => {
134134
self.scope(cmt)
135135
}

src/librustc_borrowck/borrowck/gather_loans/restrictions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
107107

108108
mc::cat_deref(cmt_base, _, pk) => {
109109
match pk {
110-
mc::OwnedPtr => {
110+
mc::UniquePtr => {
111111
// R-Deref-Send-Pointer
112112
//
113113
// When we borrow the interior of an owned pointer, we

src/librustc_typeck/check/regionck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ fn link_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
14601460
}
14611461

14621462
mc::cat_downcast(cmt_base, _) |
1463-
mc::cat_deref(cmt_base, _, mc::OwnedPtr) |
1463+
mc::cat_deref(cmt_base, _, mc::UniquePtr) |
14641464
mc::cat_interior(cmt_base, _) => {
14651465
// Borrowing interior or owned data requires the base
14661466
// 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>,
16841684
cmt.repr(rcx.tcx()));
16851685

16861686
match cmt.cat.clone() {
1687-
mc::cat_deref(base, _, mc::OwnedPtr) |
1687+
mc::cat_deref(base, _, mc::UniquePtr) |
16881688
mc::cat_interior(base, _) |
16891689
mc::cat_downcast(base, _) => {
16901690
// 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
17311731
cmt.repr(rcx.tcx()));
17321732

17331733
match cmt.cat.clone() {
1734-
mc::cat_deref(base, _, mc::OwnedPtr) |
1734+
mc::cat_deref(base, _, mc::UniquePtr) |
17351735
mc::cat_interior(base, _) |
17361736
mc::cat_downcast(base, _) => {
17371737
// Interior or owned data is unique if base is

src/libstd/collections/hash/table.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use num::{Int, UnsignedInt};
2323
use ops::{Deref, DerefMut, Drop};
2424
use option::Option;
2525
use option::Option::{Some, None};
26-
use ptr::{OwnedPtr, RawPtr, copy_nonoverlapping_memory, zero_memory};
26+
use ptr::{UniquePtr, RawPtr, copy_nonoverlapping_memory, zero_memory};
2727
use ptr;
2828
use rt::heap::{allocate, deallocate};
2929

@@ -69,7 +69,7 @@ const EMPTY_BUCKET: u64 = 0u64;
6969
pub struct RawTable<K, V> {
7070
capacity: uint,
7171
size: uint,
72-
hashes: OwnedPtr<u64>,
72+
hashes: UniquePtr<u64>,
7373
// Because K/V do not appear directly in any of the types in the struct,
7474
// inform rustc that in fact instances of K and V are reachable from here.
7575
marker: marker::CovariantType<(K,V)>,
@@ -563,7 +563,7 @@ impl<K, V> RawTable<K, V> {
563563
return RawTable {
564564
size: 0,
565565
capacity: 0,
566-
hashes: OwnedPtr::null(),
566+
hashes: UniquePtr::null(),
567567
marker: marker::CovariantType,
568568
};
569569
}
@@ -602,7 +602,7 @@ impl<K, V> RawTable<K, V> {
602602
RawTable {
603603
capacity: capacity,
604604
size: 0,
605-
hashes: OwnedPtr(hashes),
605+
hashes: UniquePtr(hashes),
606606
marker: marker::CovariantType,
607607
}
608608
}

0 commit comments

Comments
 (0)