From 81ec1f3c186cd64450d8141aab467f0a1f3a7ebd Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Thu, 27 Mar 2014 00:01:11 +0100 Subject: [PATCH] Rename Pod into Copy Summary: So far, we've used the term POD "Plain Old Data" to refer to types that can be safely copied. However, this term is not consistent with the other built-in bounds that use verbs instead. This patch renames the Pod kind into Copy. RFC: 0003-opt-in-builtin-traits Test Plan: make check Reviewers: cmr Differential Revision: http://phabricator.octayn.net/D3 --- src/doc/guide-unsafe.md | 2 +- src/doc/rust.md | 4 +- src/etc/vim/syntax/rust.vim | 2 +- src/libarena/lib.rs | 78 ++++++++--------- src/libcollections/hashmap.rs | 14 +-- src/librustc/metadata/tydecode.rs | 2 +- src/librustc/metadata/tyencode.rs | 2 +- src/librustc/middle/lang_items.rs | 8 +- src/librustc/middle/ty.rs | 14 +-- src/librustc/util/ppaux.rs | 4 +- src/libstd/cell.rs | 14 +-- src/libstd/intrinsics.rs | 2 +- src/libstd/kinds.rs | 23 ++++- src/libstd/mem.rs | 2 +- src/libstd/num/mod.rs | 4 +- src/libstd/option.rs | 2 +- src/libstd/prelude.rs | 2 +- src/libstd/slice.rs | 6 +- src/libstd/sync/atomics.rs | 22 ++--- src/libstd/task.rs | 4 +- src/libsync/raw.rs | 6 +- src/libsyntax/ast_map.rs | 2 +- src/libsyntax/parse/parser.rs | 4 +- src/test/auxiliary/kinds_in_metadata.rs | 4 +- .../auxiliary/trait_superkinds_in_metadata.rs | 2 +- .../borrowck-move-out-of-static-item.rs | 4 +- .../borrowck-struct-update-with-dtor.rs | 4 +- src/test/compile-fail/kindck-copy.rs | 86 +++++++++++++++++++ src/test/compile-fail/kindck-pod.rs | 86 ------------------- .../{marker-no-pod.rs => marker-no-copy.rs} | 4 +- .../compile-fail/static-items-cant-move.rs | 4 +- .../builtin-superkinds-in-metadata.rs | 4 +- src/test/run-pass/can-copy-pod.rs | 4 +- src/test/run-pass/fsu-moves-and-copies.rs | 24 +++--- src/test/run-pass/kinds-in-metadata.rs | 2 +- 35 files changed, 233 insertions(+), 218 deletions(-) create mode 100644 src/test/compile-fail/kindck-copy.rs delete mode 100644 src/test/compile-fail/kindck-pod.rs rename src/test/compile-fail/{marker-no-pod.rs => marker-no-copy.rs} (86%) diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index 9835e50d54765..2339f23f56e23 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -595,7 +595,7 @@ Other features provided by lang items include: - stack unwinding and general failure; the `eh_personality`, `fail_` and `fail_bounds_checks` lang items. - the traits in `std::kinds` used to indicate types that satisfy - various kinds; lang items `send`, `share` and `pod`. + various kinds; lang items `send`, `share` and `copy`. - the marker types and variance indicators found in `std::kinds::markers`; lang items `covariant_type`, `contravariant_lifetime`, `no_share_bound`, etc. diff --git a/src/doc/rust.md b/src/doc/rust.md index ef66fc7abe2e1..8222d88f9b428 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -3439,12 +3439,12 @@ The kinds are: This kind includes scalars, owning pointers, owned closures, and structural types containing only other owned types. All `Send` types are `'static`. -`Pod` +`Copy` : Types of this kind consist of "Plain Old Data" which can be copied by simply moving bits. All values of this kind can be implicitly copied. This kind includes scalars and immutable references, - as well as structural types containing other `Pod` types. + as well as structural types containing other `Copy` types. `'static` : Types of this kind do not contain any references (except for references with the `static` lifetime, which are allowed). diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index c63948d3ed16a..40250d6629464 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -52,7 +52,7 @@ syn keyword rustType f64 i8 i16 i32 i64 str Self " to make it easy to update. " Core operators {{{3 -syn keyword rustTrait Freeze Pod Send Sized +syn keyword rustTrait Freeze Copy Send Sized syn keyword rustTrait Add Sub Mul Div Rem Neg Not syn keyword rustTrait BitAnd BitOr BitXor syn keyword rustTrait Drop diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 94e340368feb4..49340008ce88d 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -48,7 +48,7 @@ use std::intrinsics; struct Chunk { data: Rc >>, fill: Cell, - is_pod: Cell, + is_copy: Cell, } impl Chunk { fn capacity(&self) -> uint { @@ -86,7 +86,7 @@ pub struct Arena { // microoptimization, to avoid needing to case on the list to // access the head. priv head: Chunk, - priv pod_head: Chunk, + priv copy_head: Chunk, priv chunks: RefCell<@List>, } @@ -98,17 +98,17 @@ impl Arena { pub fn new_with_size(initial_size: uint) -> Arena { Arena { head: chunk(initial_size, false), - pod_head: chunk(initial_size, true), + copy_head: chunk(initial_size, true), chunks: RefCell::new(@Nil), } } } -fn chunk(size: uint, is_pod: bool) -> Chunk { +fn chunk(size: uint, is_copy: bool) -> Chunk { Chunk { data: Rc::new(RefCell::new(Vec::with_capacity(size))), fill: Cell::new(0u), - is_pod: Cell::new(is_pod), + is_copy: Cell::new(is_copy), } } @@ -118,7 +118,7 @@ impl Drop for Arena { unsafe { destroy_chunk(&self.head); for chunk in self.chunks.get().iter() { - if !chunk.is_pod.get() { + if !chunk.is_copy.get() { destroy_chunk(chunk); } } @@ -173,41 +173,41 @@ fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) { impl Arena { fn chunk_size(&self) -> uint { - self.pod_head.capacity() + self.copy_head.capacity() } // Functions for the POD part of the arena - fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 { + fn alloc_copy_grow(&mut self, n_bytes: uint, align: uint) -> *u8 { // Allocate a new chunk. let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size()); - self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get())); - self.pod_head = + self.chunks.set(@Cons(self.copy_head.clone(), self.chunks.get())); + self.copy_head = chunk(num::next_power_of_two(new_min_chunk_size + 1u), true); - return self.alloc_pod_inner(n_bytes, align); + return self.alloc_copy_inner(n_bytes, align); } #[inline] - fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 { + fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 { unsafe { let this = transmute_mut_region(self); - let start = round_up(this.pod_head.fill.get(), align); + let start = round_up(this.copy_head.fill.get(), align); let end = start + n_bytes; if end > self.chunk_size() { - return this.alloc_pod_grow(n_bytes, align); + return this.alloc_copy_grow(n_bytes, align); } - this.pod_head.fill.set(end); + this.copy_head.fill.set(end); //debug!("idx = {}, size = {}, align = {}, fill = {}", // start, n_bytes, align, head.fill.get()); - this.pod_head.as_ptr().offset(start as int) + this.copy_head.as_ptr().offset(start as int) } } #[inline] - fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T { + fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { - let ptr = self.alloc_pod_inner(mem::size_of::(), mem::min_align_of::()); + let ptr = self.alloc_copy_inner(mem::size_of::(), mem::min_align_of::()); let ptr: *mut T = transmute(ptr); mem::move_val_init(&mut (*ptr), op()); return transmute(ptr); @@ -215,7 +215,7 @@ impl Arena { } // Functions for the non-POD part of the arena - fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint) + fn alloc_noncopy_grow(&mut self, n_bytes: uint, align: uint) -> (*u8, *u8) { // Allocate a new chunk. let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size()); @@ -223,11 +223,11 @@ impl Arena { self.head = chunk(num::next_power_of_two(new_min_chunk_size + 1u), false); - return self.alloc_nonpod_inner(n_bytes, align); + return self.alloc_noncopy_inner(n_bytes, align); } #[inline] - fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint) + fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint) -> (*u8, *u8) { unsafe { let start; @@ -245,7 +245,7 @@ impl Arena { } if end > self.head.capacity() { - return self.alloc_nonpod_grow(n_bytes, align); + return self.alloc_noncopy_grow(n_bytes, align); } let head = transmute_mut_region(&mut self.head); @@ -260,11 +260,11 @@ impl Arena { } #[inline] - fn alloc_nonpod<'a, T>(&'a mut self, op: || -> T) -> &'a T { + fn alloc_noncopy<'a, T>(&'a mut self, op: || -> T) -> &'a T { unsafe { let tydesc = get_tydesc::(); let (ty_ptr, ptr) = - self.alloc_nonpod_inner(mem::size_of::(), mem::min_align_of::()); + self.alloc_noncopy_inner(mem::size_of::(), mem::min_align_of::()); let ty_ptr: *mut uint = transmute(ty_ptr); let ptr: *mut T = transmute(ptr); // Write in our tydesc along with a bit indicating that it @@ -287,9 +287,9 @@ impl Arena { // FIXME: Borrow check let this = transmute_mut(self); if intrinsics::needs_drop::() { - this.alloc_nonpod(op) + this.alloc_noncopy(op) } else { - this.alloc_pod(op) + this.alloc_copy(op) } } } @@ -496,7 +496,7 @@ mod tests { } #[test] - pub fn test_pod() { + pub fn test_copy() { let arena = TypedArena::new(); for _ in range(0, 100000) { arena.alloc(Point { @@ -508,7 +508,7 @@ mod tests { } #[bench] - pub fn bench_pod(bh: &mut BenchHarness) { + pub fn bench_copy(bh: &mut BenchHarness) { let arena = TypedArena::new(); bh.iter(|| { arena.alloc(Point { @@ -520,7 +520,7 @@ mod tests { } #[bench] - pub fn bench_pod_nonarena(bh: &mut BenchHarness) { + pub fn bench_copy_nonarena(bh: &mut BenchHarness) { bh.iter(|| { ~Point { x: 1, @@ -531,7 +531,7 @@ mod tests { } #[bench] - pub fn bench_pod_old_arena(bh: &mut BenchHarness) { + pub fn bench_copy_old_arena(bh: &mut BenchHarness) { let arena = Arena::new(); bh.iter(|| { arena.alloc(|| { @@ -544,16 +544,16 @@ mod tests { }) } - struct Nonpod { + struct Noncopy { string: ~str, array: Vec , } #[test] - pub fn test_nonpod() { + pub fn test_noncopy() { let arena = TypedArena::new(); for _ in range(0, 100000) { - arena.alloc(Nonpod { + arena.alloc(Noncopy { string: ~"hello world", array: vec!( 1, 2, 3, 4, 5 ), }); @@ -561,10 +561,10 @@ mod tests { } #[bench] - pub fn bench_nonpod(bh: &mut BenchHarness) { + pub fn bench_noncopy(bh: &mut BenchHarness) { let arena = TypedArena::new(); bh.iter(|| { - arena.alloc(Nonpod { + arena.alloc(Noncopy { string: ~"hello world", array: vec!( 1, 2, 3, 4, 5 ), }) @@ -572,9 +572,9 @@ mod tests { } #[bench] - pub fn bench_nonpod_nonarena(bh: &mut BenchHarness) { + pub fn bench_noncopy_nonarena(bh: &mut BenchHarness) { bh.iter(|| { - ~Nonpod { + ~Noncopy { string: ~"hello world", array: vec!( 1, 2, 3, 4, 5 ), } @@ -582,10 +582,10 @@ mod tests { } #[bench] - pub fn bench_nonpod_old_arena(bh: &mut BenchHarness) { + pub fn bench_noncopy_old_arena(bh: &mut BenchHarness) { let arena = Arena::new(); bh.iter(|| { - arena.alloc(|| Nonpod { + arena.alloc(|| Noncopy { string: ~"hello world", array: vec!( 1, 2, 3, 4, 5 ), }) diff --git a/src/libcollections/hashmap.rs b/src/libcollections/hashmap.rs index b03cfced7cdbe..2d3f7d512c3d8 100644 --- a/src/libcollections/hashmap.rs +++ b/src/libcollections/hashmap.rs @@ -110,7 +110,7 @@ mod table { /// Represents an index into a `RawTable` with no key or value in it. pub struct EmptyIndex { priv idx: int, - priv nopod: marker::NoPod, + priv nocopy: marker::NoCopy, } /// Represents an index into a `RawTable` with a key, value, and hash @@ -118,7 +118,7 @@ mod table { pub struct FullIndex { priv idx: int, priv hash: SafeHash, - priv nopod: marker::NoPod, + priv nocopy: marker::NoCopy, } impl FullIndex { @@ -237,19 +237,19 @@ mod table { let idx = index as int; let hash = unsafe { *self.hashes.offset(idx) }; - let nopod = marker::NoPod; + let nocopy = marker::NoCopy; match hash { EMPTY_BUCKET => Empty(EmptyIndex { idx: idx, - nopod: nopod + nocopy: nocopy }), full_hash => Full(FullIndex { idx: idx, hash: SafeHash { hash: full_hash }, - nopod: nopod, + nocopy: nocopy, }) } } @@ -320,7 +320,7 @@ mod table { self.size += 1; - FullIndex { idx: idx, hash: hash, nopod: marker::NoPod } + FullIndex { idx: idx, hash: hash, nocopy: marker::NoCopy } } /// Removes a key and value from the hashtable. @@ -347,7 +347,7 @@ mod table { self.size -= 1; - (EmptyIndex { idx: idx, nopod: marker::NoPod }, k, v) + (EmptyIndex { idx: idx, nocopy: marker::NoCopy }, k, v) } } diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 9ee2779079cf0..d0d79093cabce 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -591,7 +591,7 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds { param_bounds.builtin_bounds.add(ty::BoundSized); } 'P' => { - param_bounds.builtin_bounds.add(ty::BoundPod); + param_bounds.builtin_bounds.add(ty::BoundCopy); } 'T' => { param_bounds.builtin_bounds.add(ty::BoundShare); diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 5b3c2962ac0ed..e2c25a2536608 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -394,7 +394,7 @@ fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) { ty::BoundSend => mywrite!(w, "S"), ty::BoundStatic => mywrite!(w, "O"), ty::BoundSized => mywrite!(w, "Z"), - ty::BoundPod => mywrite!(w, "P"), + ty::BoundCopy => mywrite!(w, "P"), ty::BoundShare => mywrite!(w, "T"), } } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 2ba408bfa005b..f93d90d273543 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -86,8 +86,8 @@ impl LanguageItems { Some(ty::BoundSend) } else if Some(id) == self.sized_trait() { Some(ty::BoundSized) - } else if Some(id) == self.pod_trait() { - Some(ty::BoundPod) + } else if Some(id) == self.copy_trait() { + Some(ty::BoundCopy) } else if Some(id) == self.share_trait() { Some(ty::BoundShare) } else { @@ -210,7 +210,7 @@ lets_do_this! { // Variant name, Name, Method name; SendTraitLangItem, "send", send_trait; SizedTraitLangItem, "sized", sized_trait; - PodTraitLangItem, "pod", pod_trait; + CopyTraitLangItem, "copy", copy_trait; ShareTraitLangItem, "share", share_trait; DropTraitLangItem, "drop", drop_trait; @@ -271,7 +271,7 @@ lets_do_this! { InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime; NoSendItem, "no_send_bound", no_send_bound; - NoPodItem, "no_pod_bound", no_pod_bound; + NoCopyItem, "no_copy_bound", no_copy_bound; NoShareItem, "no_share_bound", no_share_bound; ManagedItem, "managed_bound", managed_bound; } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 7d6f44494cb13..3ec928d5f4669 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -842,7 +842,7 @@ pub enum BuiltinBound { BoundStatic, BoundSend, BoundSized, - BoundPod, + BoundCopy, BoundShare, } @@ -1905,7 +1905,7 @@ def_type_content_sets!( // Things that make values considered not POD (would be same // as `Moves`, but for the fact that managed data `@` is // not considered POD) - Nonpod = 0b0000_0000__0000_1111__0000, + Noncopy = 0b0000_0000__0000_1111__0000, // Bits to set when a managed value is encountered // @@ -1929,7 +1929,7 @@ impl TypeContents { BoundStatic => self.is_static(cx), BoundSend => self.is_sendable(cx), BoundSized => self.is_sized(cx), - BoundPod => self.is_pod(cx), + BoundCopy => self.is_copy(cx), BoundShare => self.is_sharable(cx), } } @@ -1966,8 +1966,8 @@ impl TypeContents { !self.intersects(TC::Nonsized) } - pub fn is_pod(&self, _: &ctxt) -> bool { - !self.intersects(TC::Nonpod) + pub fn is_copy(&self, _: &ctxt) -> bool { + !self.intersects(TC::Noncopy) } pub fn interior_unsafe(&self) -> bool { @@ -2263,7 +2263,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { tc | TC::ReachesNonsendAnnot } else if Some(did) == cx.lang_items.managed_bound() { tc | TC::Managed - } else if Some(did) == cx.lang_items.no_pod_bound() { + } else if Some(did) == cx.lang_items.no_copy_bound() { tc | TC::OwnsAffine } else if Some(did) == cx.lang_items.no_share_bound() { tc | TC::ReachesNoShare @@ -2345,7 +2345,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { BoundStatic => TC::Nonstatic, BoundSend => TC::Nonsendable, BoundSized => TC::Nonsized, - BoundPod => TC::Nonpod, + BoundCopy => TC::Noncopy, BoundShare => TC::Nonsharable, }; }); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 1a017340c9509..42a6438b58cb8 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -665,7 +665,7 @@ impl Repr for ty::ParamBounds { ty::BoundStatic => ~"'static", ty::BoundSend => ~"Send", ty::BoundSized => ~"Sized", - ty::BoundPod => ~"Pod", + ty::BoundCopy => ~"Pod", ty::BoundShare => ~"Share", }); } @@ -952,7 +952,7 @@ impl UserString for ty::BuiltinBound { ty::BoundStatic => ~"'static", ty::BoundSend => ~"Send", ty::BoundSized => ~"Sized", - ty::BoundPod => ~"Pod", + ty::BoundCopy => ~"Pod", ty::BoundShare => ~"Share", } } diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index e0912b826cd59..a826521ab6ba5 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -14,18 +14,18 @@ use cast; use clone::Clone; use cmp::Eq; use fmt; -use kinds::{marker, Pod}; +use kinds::{marker, Copy}; use ops::{Deref, DerefMut, Drop}; use option::{None, Option, Some}; use ty::Unsafe; -/// A mutable memory location that admits only `Pod` data. +/// A mutable memory location that admits only `Copy` data. pub struct Cell { priv value: Unsafe, priv noshare: marker::NoShare, } -impl Cell { +impl Cell { /// Creates a new `Cell` containing the given value. pub fn new(value: T) -> Cell { Cell { @@ -49,13 +49,13 @@ impl Cell { } } -impl Clone for Cell { +impl Clone for Cell { fn clone(&self) -> Cell { Cell::new(self.get()) } } -impl Eq for Cell { +impl Eq for Cell { fn eq(&self, other: &Cell) -> bool { self.get() == other.get() } @@ -71,7 +71,7 @@ impl fmt::Show for Cell { pub struct RefCell { priv value: Unsafe, priv borrow: BorrowFlag, - priv nopod: marker::NoPod, + priv nocopy: marker::NoCopy, priv noshare: marker::NoShare, } @@ -86,7 +86,7 @@ impl RefCell { pub fn new(value: T) -> RefCell { RefCell { value: Unsafe::new(value), - nopod: marker::NoPod, + nocopy: marker::NoCopy, noshare: marker::NoShare, borrow: UNUSED, } diff --git a/src/libstd/intrinsics.rs b/src/libstd/intrinsics.rs index 55e7746a44ddc..97e275ae983b1 100644 --- a/src/libstd/intrinsics.rs +++ b/src/libstd/intrinsics.rs @@ -296,7 +296,7 @@ extern "rust-intrinsic" { /// Create a value initialized to zero. /// /// `init` is unsafe because it returns a zeroed-out datum, - /// which is unsafe unless T is Pod. + /// which is unsafe unless T is Copy. pub fn init() -> T; /// Create an uninitialized value. diff --git a/src/libstd/kinds.rs b/src/libstd/kinds.rs index f116f61509e11..c01b09dd5ac56 100644 --- a/src/libstd/kinds.rs +++ b/src/libstd/kinds.rs @@ -33,10 +33,16 @@ pub trait Sized { } /// Types that can be copied by simply copying bits (i.e. `memcpy`). -/// -/// The name "POD" stands for "Plain Old Data" and is borrowed from C++. +#[cfg(stage0)] #[lang="pod"] -pub trait Pod { +pub trait Copy { + // Empty. +} + +/// Types that can be copied by simply copying bits (i.e. `memcpy`). +#[cfg(not(stage0))] +#[lang="copy"] +pub trait Copy { // Empty. } @@ -264,9 +270,18 @@ pub mod marker { /// A type which is considered "not POD", meaning that it is not /// implicitly copyable. This is typically embedded in other types to /// ensure that they are never copied, even if they lack a destructor. + #[cfg(not(stage0))] + #[lang="no_copy_bound"] + #[deriving(Eq,Clone)] + pub struct NoCopy; + + /// A type which is considered "not POD", meaning that it is not + /// implicitly copyable. This is typically embedded in other types to + /// ensure that they are never copied, even if they lack a destructor. + #[cfg(stage0)] #[lang="no_pod_bound"] #[deriving(Eq,Clone)] - pub struct NoPod; + pub struct NoCopy; /// A type which is considered "not sharable", meaning that /// its contents are not threadsafe, hence they cannot be diff --git a/src/libstd/mem.rs b/src/libstd/mem.rs index e124ada08c767..1f0a3b5b0bdf9 100644 --- a/src/libstd/mem.rs +++ b/src/libstd/mem.rs @@ -79,7 +79,7 @@ pub fn pref_align_of_val(_val: &T) -> uint { /// Create a value initialized to zero. /// /// `init` is unsafe because it returns a zeroed-out datum, -/// which is unsafe unless T is Pod. +/// which is unsafe unless T is Copy. #[inline] pub unsafe fn init() -> T { intrinsics::init() diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 202e26e2c93c1..d09cf28357bcd 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -17,7 +17,7 @@ use clone::Clone; use cmp::{Eq, Ord}; -use kinds::Pod; +use kinds::Copy; use mem::size_of; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr}; @@ -276,7 +276,7 @@ pub trait Bitwise: Bounded /// Specifies the available operations common to all of Rust's core numeric primitives. /// These may not always make sense from a purely mathematical point of view, but /// may be useful for systems programming. -pub trait Primitive: Pod +pub trait Primitive: Copy + Clone + Num + NumCast diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 14dc42195e190..a1b7060018641 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -684,7 +684,7 @@ mod tests { #[test] #[should_fail] fn test_option_too_much_dance() { - let mut y = Some(marker::NoPod); + let mut y = Some(marker::NoCopy); let _y2 = y.take_unwrap(); let _y3 = y.take_unwrap(); } diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index a42ee80b53a51..0a4b32f5a8995 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -20,7 +20,7 @@ generally useful to many Rust programs. */ // Reexported core operators -pub use kinds::{Pod, Send, Sized, Share}; +pub use kinds::{Copy, Send, Sized, Share}; pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not}; pub use ops::{BitAnd, BitOr, BitXor}; pub use ops::{Drop, Deref, DerefMut}; diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index 8788a584f30ef..8602c65352342 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -2304,12 +2304,12 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { MutItems{ptr: p, end: (p as uint + self.len()) as *mut T, marker: marker::ContravariantLifetime::<'a>, - marker2: marker::NoPod} + marker2: marker::NoCopy} } else { MutItems{ptr: p, end: p.offset(self.len() as int), marker: marker::ContravariantLifetime::<'a>, - marker2: marker::NoPod} + marker2: marker::NoCopy} } } } @@ -2670,7 +2670,7 @@ pub struct MutItems<'a, T> { priv ptr: *mut T, priv end: *mut T, priv marker: marker::ContravariantLifetime<'a>, - priv marker2: marker::NoPod + priv marker2: marker::NoCopy } macro_rules! iterator { diff --git a/src/libstd/sync/atomics.rs b/src/libstd/sync/atomics.rs index d5f6fac2296e9..bca7cf259444c 100644 --- a/src/libstd/sync/atomics.rs +++ b/src/libstd/sync/atomics.rs @@ -117,25 +117,25 @@ use ty::Unsafe; /// An atomic boolean type. pub struct AtomicBool { priv v: Unsafe, - priv nopod: marker::NoPod + priv nocopy: marker::NoCopy } /// A signed atomic integer type, supporting basic atomic arithmetic operations pub struct AtomicInt { priv v: Unsafe, - priv nopod: marker::NoPod + priv nocopy: marker::NoCopy } /// An unsigned atomic integer type, supporting basic atomic arithmetic operations pub struct AtomicUint { priv v: Unsafe, - priv nopod: marker::NoPod + priv nocopy: marker::NoCopy } /// An unsafe atomic pointer. Only supports basic atomic operations pub struct AtomicPtr { priv p: Unsafe, - priv nopod: marker::NoPod + priv nocopy: marker::NoCopy } /// An atomic, nullable unique pointer @@ -180,15 +180,15 @@ pub enum Ordering { /// An `AtomicBool` initialized to `false` pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: Unsafe{value: 0, marker1: marker::InvariantType}, - nopod: marker::NoPod }; + nocopy: marker::NoCopy }; /// An `AtomicInt` initialized to `0` pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: Unsafe{value: 0, marker1: marker::InvariantType}, - nopod: marker::NoPod }; + nocopy: marker::NoCopy }; /// An `AtomicUint` initialized to `0` pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: Unsafe{value: 0, marker1: marker::InvariantType}, - nopod: marker::NoPod }; + nocopy: marker::NoCopy }; // NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly static UINT_TRUE: uint = -1; @@ -197,7 +197,7 @@ impl AtomicBool { /// Create a new `AtomicBool` pub fn new(v: bool) -> AtomicBool { let val = if v { UINT_TRUE } else { 0 }; - AtomicBool { v: Unsafe::new(val), nopod: marker::NoPod } + AtomicBool { v: Unsafe::new(val), nocopy: marker::NoCopy } } /// Load the value @@ -400,7 +400,7 @@ impl AtomicBool { impl AtomicInt { /// Create a new `AtomicInt` pub fn new(v: int) -> AtomicInt { - AtomicInt {v: Unsafe::new(v), nopod: marker::NoPod} + AtomicInt {v: Unsafe::new(v), nocopy: marker::NoCopy} } /// Load the value @@ -467,7 +467,7 @@ impl AtomicInt { impl AtomicUint { /// Create a new `AtomicUint` pub fn new(v: uint) -> AtomicUint { - AtomicUint { v: Unsafe::new(v), nopod: marker::NoPod } + AtomicUint { v: Unsafe::new(v), nocopy: marker::NoCopy } } /// Load the value @@ -534,7 +534,7 @@ impl AtomicUint { impl AtomicPtr { /// Create a new `AtomicPtr` pub fn new(p: *mut T) -> AtomicPtr { - AtomicPtr { p: Unsafe::new(p as uint), nopod: marker::NoPod } + AtomicPtr { p: Unsafe::new(p as uint), nocopy: marker::NoCopy } } /// Load the value diff --git a/src/libstd/task.rs b/src/libstd/task.rs index c158ddf0d8380..c3d0223694808 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -87,7 +87,7 @@ pub struct TaskBuilder { /// Options to spawn the new task with opts: TaskOpts, priv gen_body: Option proc:Send()>, - priv nopod: Option, + priv nocopy: Option, } /** @@ -98,7 +98,7 @@ pub fn task() -> TaskBuilder { TaskBuilder { opts: TaskOpts::new(), gen_body: None, - nopod: None, + nocopy: None, } } diff --git a/src/libsync/raw.rs b/src/libsync/raw.rs index 0cb9bf77ac925..ba53b3b2e95fd 100644 --- a/src/libsync/raw.rs +++ b/src/libsync/raw.rs @@ -192,7 +192,7 @@ impl Sem> { pub fn access_cond<'a>(&'a self) -> SemCondGuard<'a> { SemCondGuard { guard: self.access(), - cvar: Condvar { sem: self, order: Nothing, nopod: marker::NoPod }, + cvar: Condvar { sem: self, order: Nothing, nocopy: marker::NoCopy }, } } } @@ -218,7 +218,7 @@ pub struct Condvar<'a> { // See the comment in write_cond for more detail. priv order: ReacquireOrderLock<'a>, // Make sure condvars are non-copyable. - priv nopod: marker::NoPod, + priv nocopy: marker::NoCopy, } impl<'a> Condvar<'a> { @@ -565,7 +565,7 @@ impl RWLock { cond: Condvar { sem: &self.access_lock, order: Just(&self.order_lock), - nopod: marker::NoPod, + nocopy: marker::NoCopy, } } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 90c23a54426c1..5db353b7262a5 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -68,7 +68,7 @@ impl<'a> Iterator for LinkedPath<'a> { #[deriving(Clone)] pub struct Values<'a, T>(slice::Items<'a, T>); -impl<'a, T: Pod> Iterator for Values<'a, T> { +impl<'a, T: Copy> Iterator for Values<'a, T> { fn next(&mut self) -> Option { let &Values(ref mut items) = self; items.next().map(|&x| x) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d6ccea7331d72..0ae43db831584 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -306,7 +306,7 @@ pub fn Parser<'a>(sess: &'a ParseSess, cfg: ast::CrateConfig, rdr: ~Reader:) obsolete_set: HashSet::new(), mod_path_stack: Vec::new(), open_braces: Vec::new(), - nopod: marker::NoPod + nocopy: marker::NoCopy } } @@ -337,7 +337,7 @@ pub struct Parser<'a> { /// Stack of spans of open delimiters. Used for error message. open_braces: Vec , /* do not copy the parser; its state is tied to outside state */ - priv nopod: marker::NoPod + priv nocopy: marker::NoCopy } fn is_plain_ident_or_underscore(t: &token::Token) -> bool { diff --git a/src/test/auxiliary/kinds_in_metadata.rs b/src/test/auxiliary/kinds_in_metadata.rs index 387767f374f63..7ca11c8925f54 100644 --- a/src/test/auxiliary/kinds_in_metadata.rs +++ b/src/test/auxiliary/kinds_in_metadata.rs @@ -11,9 +11,9 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -// Tests that metadata serialization works for the `Pod` kind. +// Tests that metadata serialization works for the `Copy` kind. #[crate_type="lib"]; -pub fn f() {} +pub fn f() {} diff --git a/src/test/auxiliary/trait_superkinds_in_metadata.rs b/src/test/auxiliary/trait_superkinds_in_metadata.rs index e49ed1f9cf717..40ae0ad45831f 100644 --- a/src/test/auxiliary/trait_superkinds_in_metadata.rs +++ b/src/test/auxiliary/trait_superkinds_in_metadata.rs @@ -15,4 +15,4 @@ pub trait RequiresShare : Share { } pub trait RequiresRequiresShareAndSend : RequiresShare + Send { } -pub trait RequiresPod : Pod { } +pub trait RequiresCopy : Copy { } diff --git a/src/test/compile-fail/borrowck-move-out-of-static-item.rs b/src/test/compile-fail/borrowck-move-out-of-static-item.rs index a7e5573ccfc66..ea36c76ea4058 100644 --- a/src/test/compile-fail/borrowck-move-out-of-static-item.rs +++ b/src/test/compile-fail/borrowck-move-out-of-static-item.rs @@ -14,10 +14,10 @@ use std::kinds::marker; struct Foo { foo: int, - nopod: marker::NoPod + nocopy: marker::NoCopy } -static BAR: Foo = Foo{foo: 5, nopod: marker::NoPod}; +static BAR: Foo = Foo{foo: 5, nocopy: marker::NoCopy}; fn test(f: Foo) { diff --git a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs index 0f09f42330022..651104d1eda44 100644 --- a/src/test/compile-fail/borrowck-struct-update-with-dtor.rs +++ b/src/test/compile-fail/borrowck-struct-update-with-dtor.rs @@ -11,8 +11,8 @@ // Issue 4691: Ensure that functional-struct-update can only copy, not // move, when the struct implements Drop. -// NoPod -use NP = std::kinds::marker::NoPod; +// NoCopy +use NP = std::kinds::marker::NoCopy; struct S { a: int, np: NP } impl Drop for S { fn drop(&mut self) { } } diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs new file mode 100644 index 0000000000000..a1b8b06ab955a --- /dev/null +++ b/src/test/compile-fail/kindck-copy.rs @@ -0,0 +1,86 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test which of the builtin types are considered POD. + +#[feature(managed_boxes)]; + +use std::rc::Rc; + +fn assert_copy() { } +trait Dummy { } + +struct MyStruct { + x: int, + y: int, +} + +struct MyNoncopyStruct { + x: ~int, +} + +fn test<'a,T,U:Copy>(_: &'a int) { + // lifetime pointers are ok... + assert_copy::<&'static int>(); + assert_copy::<&'a int>(); + assert_copy::<&'a str>(); + assert_copy::<&'a [int]>(); + + // ...unless they are mutable + assert_copy::<&'static mut int>(); //~ ERROR does not fulfill + assert_copy::<&'a mut int>(); //~ ERROR does not fulfill + + // ~ pointers are not ok + assert_copy::<~int>(); //~ ERROR does not fulfill + assert_copy::<~str>(); //~ ERROR does not fulfill + assert_copy:: >(); //~ ERROR does not fulfill + assert_copy::<~&'a mut int>(); //~ ERROR does not fulfill + + // borrowed object types are generally ok + assert_copy::<&'a Dummy>(); + assert_copy::<&'a Dummy:Copy>(); + assert_copy::<&'static Dummy:Copy>(); + + // owned object types are not ok + assert_copy::<~Dummy>(); //~ ERROR does not fulfill + assert_copy::<~Dummy:Copy>(); //~ ERROR does not fulfill + + // mutable object types are not ok + assert_copy::<&'a mut Dummy:Copy>(); //~ ERROR does not fulfill + + // closures are like an `&mut` object + assert_copy::<||>(); //~ ERROR does not fulfill + + // unsafe ptrs are ok + assert_copy::<*int>(); + assert_copy::<*&'a mut int>(); + + // regular old ints and such are ok + assert_copy::(); + assert_copy::(); + assert_copy::<()>(); + + // tuples are ok + assert_copy::<(int,int)>(); + + // structs of POD are ok + assert_copy::(); + + // structs containing non-POD are not ok + assert_copy::(); //~ ERROR does not fulfill + + // managed or ref counted types are not ok + assert_copy::<@int>(); //~ ERROR does not fulfill + assert_copy::>(); //~ ERROR does not fulfill +} + +pub fn main() { +} + diff --git a/src/test/compile-fail/kindck-pod.rs b/src/test/compile-fail/kindck-pod.rs deleted file mode 100644 index 94902d4e68ea5..0000000000000 --- a/src/test/compile-fail/kindck-pod.rs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test which of the builtin types are considered POD. - -#[feature(managed_boxes)]; - -use std::rc::Rc; - -fn assert_pod() { } -trait Dummy { } - -struct MyStruct { - x: int, - y: int, -} - -struct MyNonpodStruct { - x: ~int, -} - -fn test<'a,T,U:Pod>(_: &'a int) { - // lifetime pointers are ok... - assert_pod::<&'static int>(); - assert_pod::<&'a int>(); - assert_pod::<&'a str>(); - assert_pod::<&'a [int]>(); - - // ...unless they are mutable - assert_pod::<&'static mut int>(); //~ ERROR does not fulfill `Pod` - assert_pod::<&'a mut int>(); //~ ERROR does not fulfill `Pod` - - // ~ pointers are not ok - assert_pod::<~int>(); //~ ERROR does not fulfill `Pod` - assert_pod::<~str>(); //~ ERROR does not fulfill `Pod` - assert_pod:: >(); //~ ERROR does not fulfill `Pod` - assert_pod::<~&'a mut int>(); //~ ERROR does not fulfill `Pod` - - // borrowed object types are generally ok - assert_pod::<&'a Dummy>(); - assert_pod::<&'a Dummy:Pod>(); - assert_pod::<&'static Dummy:Pod>(); - - // owned object types are not ok - assert_pod::<~Dummy>(); //~ ERROR does not fulfill `Pod` - assert_pod::<~Dummy:Pod>(); //~ ERROR does not fulfill `Pod` - - // mutable object types are not ok - assert_pod::<&'a mut Dummy:Pod>(); //~ ERROR does not fulfill `Pod` - - // closures are like an `&mut` object - assert_pod::<||>(); //~ ERROR does not fulfill `Pod` - - // unsafe ptrs are ok - assert_pod::<*int>(); - assert_pod::<*&'a mut int>(); - - // regular old ints and such are ok - assert_pod::(); - assert_pod::(); - assert_pod::<()>(); - - // tuples are ok - assert_pod::<(int,int)>(); - - // structs of POD are ok - assert_pod::(); - - // structs containing non-POD are not ok - assert_pod::(); //~ ERROR does not fulfill `Pod` - - // managed or ref counted types are not ok - assert_pod::<@int>(); //~ ERROR does not fulfill `Pod` - assert_pod::>(); //~ ERROR does not fulfill `Pod` -} - -pub fn main() { -} - diff --git a/src/test/compile-fail/marker-no-pod.rs b/src/test/compile-fail/marker-no-copy.rs similarity index 86% rename from src/test/compile-fail/marker-no-pod.rs rename to src/test/compile-fail/marker-no-copy.rs index 90b277a743238..5a7cddc250a16 100644 --- a/src/test/compile-fail/marker-no-pod.rs +++ b/src/test/compile-fail/marker-no-copy.rs @@ -10,9 +10,9 @@ use std::kinds::marker; -fn foo(p: P) { } +fn foo(p: P) { } fn main() { - foo(marker::NoPod); //~ ERROR does not fulfill `Pod` + foo(marker::NoCopy); //~ ERROR does not fulfill } diff --git a/src/test/compile-fail/static-items-cant-move.rs b/src/test/compile-fail/static-items-cant-move.rs index f089904dd9149..28e73f74ff3fc 100644 --- a/src/test/compile-fail/static-items-cant-move.rs +++ b/src/test/compile-fail/static-items-cant-move.rs @@ -14,10 +14,10 @@ use std::kinds::marker; struct Foo { foo: int, - nopod: marker::NoPod + nocopy: marker::NoCopy } -static BAR: Foo = Foo{foo: 5, nopod: marker::NoPod}; +static BAR: Foo = Foo{foo: 5, nocopy: marker::NoCopy}; fn test(f: Foo) { diff --git a/src/test/run-pass/builtin-superkinds-in-metadata.rs b/src/test/run-pass/builtin-superkinds-in-metadata.rs index 7b2977d031c13..5261ea9d1e109 100644 --- a/src/test/run-pass/builtin-superkinds-in-metadata.rs +++ b/src/test/run-pass/builtin-superkinds-in-metadata.rs @@ -16,7 +16,7 @@ extern crate trait_superkinds_in_metadata; use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare}; -use trait_superkinds_in_metadata::{RequiresPod}; +use trait_superkinds_in_metadata::{RequiresCopy}; struct X(T); @@ -24,6 +24,6 @@ impl RequiresShare for X { } impl RequiresRequiresShareAndSend for X { } -impl RequiresPod for X { } +impl RequiresCopy for X { } pub fn main() { } diff --git a/src/test/run-pass/can-copy-pod.rs b/src/test/run-pass/can-copy-pod.rs index a6a56a68c5a04..8375aafb5b7ba 100644 --- a/src/test/run-pass/can-copy-pod.rs +++ b/src/test/run-pass/can-copy-pod.rs @@ -11,11 +11,11 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -// Tests that type parameters with the `Pod` are implicitly copyable. +// Tests that type parameters with the `Copy` are implicitly copyable. #[allow(dead_code)]; -fn can_copy_pod(v: T) { +fn can_copy_copy(v: T) { let _a = v; let _b = v; } diff --git a/src/test/run-pass/fsu-moves-and-copies.rs b/src/test/run-pass/fsu-moves-and-copies.rs index 878ea298db395..571ef4bd7b4a4 100644 --- a/src/test/run-pass/fsu-moves-and-copies.rs +++ b/src/test/run-pass/fsu-moves-and-copies.rs @@ -11,14 +11,14 @@ // Issue 4691: Ensure that functional-struct-updates operates // correctly and moves rather than copy when appropriate. -use NP = std::kinds::marker::NoPod; +use NP = std::kinds::marker::NoCopy; struct ncint { np: NP, v: int } fn ncint(v: int) -> ncint { ncint { np: NP, v: v } } -struct NoFoo { copied: int, nopod: ncint, } +struct NoFoo { copied: int, nocopy: ncint, } impl NoFoo { - fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, nopod: ncint(y) } } + fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, nocopy: ncint(y) } } } struct MoveFoo { copied: int, moved: ~int, } @@ -44,18 +44,18 @@ fn test0() { // (and thus it is okay that these are Drop; compare against // compile-fail test: borrowck-struct-update-with-dtor.rs). - // Case 1: Nopodable + // Case 1: Nocopyable let f = DropNoFoo::new(1, 2); - let b = DropNoFoo { inner: NoFoo { nopod: ncint(3), ..f.inner }}; - let c = DropNoFoo { inner: NoFoo { nopod: ncint(4), ..f.inner }}; + let b = DropNoFoo { inner: NoFoo { nocopy: ncint(3), ..f.inner }}; + let c = DropNoFoo { inner: NoFoo { nocopy: ncint(4), ..f.inner }}; assert_eq!(f.inner.copied, 1); - assert_eq!(f.inner.nopod.v, 2); + assert_eq!(f.inner.nocopy.v, 2); assert_eq!(b.inner.copied, 1); - assert_eq!(b.inner.nopod.v, 3); + assert_eq!(b.inner.nocopy.v, 3); assert_eq!(c.inner.copied, 1); - assert_eq!(c.inner.nopod.v, 4); + assert_eq!(c.inner.nocopy.v, 4); // Case 2: Owned let f = DropMoveFoo::new(5, 6); @@ -86,12 +86,12 @@ fn test1() { fn test2() { // move non-copyable field let f = NoFoo::new(21, 22); - let b = NoFoo {nopod: ncint(23), ..f}; + let b = NoFoo {nocopy: ncint(23), ..f}; let c = NoFoo {copied: 24, ..f}; assert_eq!(b.copied, 21); - assert_eq!(b.nopod.v, 23); + assert_eq!(b.nocopy.v, 23); assert_eq!(c.copied, 24); - assert_eq!(c.nopod.v, 22); + assert_eq!(c.nocopy.v, 22); } pub fn main() { diff --git a/src/test/run-pass/kinds-in-metadata.rs b/src/test/run-pass/kinds-in-metadata.rs index 7799bd7016217..05f58acd94979 100644 --- a/src/test/run-pass/kinds-in-metadata.rs +++ b/src/test/run-pass/kinds-in-metadata.rs @@ -14,7 +14,7 @@ /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ -// Tests that metadata serialization works for the `Pod` kind. +// Tests that metadata serialization works for the `Copy` kind. extern crate kinds_in_metadata;