]> git.lizzy.rs Git - rust.git/commitdiff
Replace NonCopyable usage with NoPod
authorFlavio Percoco <flaper87@gmail.com>
Sun, 26 Jan 2014 10:42:46 +0000 (11:42 +0100)
committerFlavio Percoco <flaper87@gmail.com>
Mon, 3 Feb 2014 23:15:27 +0000 (00:15 +0100)
cc #10834

src/libextra/sync/mod.rs
src/libstd/cell.rs
src/libstd/option.rs
src/libstd/sync/atomics.rs
src/libstd/task.rs
src/libstd/util.rs
src/libsyntax/parse/parser.rs
src/test/compile-fail/borrowck-struct-update-with-dtor.rs
src/test/run-pass/fsu-moves-and-copies.rs

index 21ebcf1272009435d66428a0f5472389911ff39f..03bf1101f1f293ef292bed66229afdff54616edc 100644 (file)
 
 use std::cast;
 use std::comm;
+use std::kinds::marker;
 use std::sync::arc::UnsafeArc;
 use std::sync::atomics;
 use std::unstable::finally::Finally;
 use std::util;
-use std::util::NonCopyable;
 
 use arc::MutexArc;
 
@@ -191,7 +191,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 token: util::NonCopyable,
+    priv nopod: marker::NoPod,
 }
 
 impl<'a> Condvar<'a> {
@@ -334,7 +334,7 @@ pub fn access_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
             blk(&Condvar {
                 sem: self,
                 order: Nothing,
-                token: NonCopyable
+                nopod: marker::NoPod
             })
         })
     }
@@ -574,7 +574,7 @@ pub fn write_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
             (&self.order_lock).release();
             let opt_lock = Just(&self.order_lock);
             blk(&Condvar { sem: cond.sem, order: opt_lock,
-                           token: NonCopyable })
+                           nopod: marker::NoPod })
         })
     }
 
@@ -609,7 +609,7 @@ pub fn write_downgrade<U>(&self, blk: |v: RWLockWriteMode| -> U) -> U {
         (&self.access_lock).acquire();
         (&self.order_lock).release();
         (|| {
-            blk(RWLockWriteMode { lock: self, token: NonCopyable })
+            blk(RWLockWriteMode { lock: self, nopod: marker::NoPod })
         }).finally(|| {
             let writer_or_last_reader;
             // Check if we're releasing from read mode or from write mode.
@@ -662,16 +662,16 @@ pub fn downgrade<'a>(&self, token: RWLockWriteMode<'a>)
                 (&self.access_lock).release();
             }
         }
-        RWLockReadMode { lock: token.lock, token: NonCopyable }
+        RWLockReadMode { lock: token.lock, nopod: marker::NoPod }
     }
 }
 
 /// The "write permission" token used for rwlock.write_downgrade().
 
-pub struct RWLockWriteMode<'a> { priv lock: &'a RWLock, priv token: NonCopyable }
+pub struct RWLockWriteMode<'a> { priv lock: &'a RWLock, priv nopod: marker::NoPod }
 /// The "read permission" token used for rwlock.write_downgrade().
 pub struct RWLockReadMode<'a> { priv lock: &'a RWLock,
-                                   priv token: NonCopyable }
+                                   priv nopod: marker::NoPod }
 
 impl<'a> RWLockWriteMode<'a> {
     /// Access the pre-downgrade rwlock in write mode.
@@ -682,7 +682,7 @@ pub fn write_cond<U>(&self, blk: |c: &Condvar| -> U) -> U {
         // access lock. See comment in RWLock::write_cond for why.
         blk(&Condvar { sem:        &self.lock.access_lock,
                        order: Just(&self.lock.order_lock),
-                       token: NonCopyable })
+                       nopod: marker::NoPod })
     }
 }
 
index eb7d62b7bd3f136722f4e5af7b7de885bd3e0613..e19b8ae712f9a0d9e6aa4ace2ff549b974f773e5 100644 (file)
@@ -12,8 +12,7 @@
 
 use prelude::*;
 use cast;
-use util::NonCopyable;
-use kinds::{marker,Pod};
+use kinds::{marker, Pod};
 
 /// A mutable memory location that admits only `Pod` data.
 pub struct Cell<T> {
@@ -57,9 +56,9 @@ fn clone(&self) -> Cell<T> {
 pub struct RefCell<T> {
     priv value: T,
     priv borrow: BorrowFlag,
-    priv nc: NonCopyable,
     priv marker1: marker::InvariantType<T>,
     priv marker2: marker::NoFreeze,
+    priv marker3: marker::NoPod,
 }
 
 // Values [1, MAX-1] represent the number of `Ref` active
@@ -74,9 +73,9 @@ pub fn new(value: T) -> RefCell<T> {
         RefCell {
             marker1: marker::InvariantType::<T>,
             marker2: marker::NoFreeze,
+            marker3: marker::NoPod,
             value: value,
             borrow: UNUSED,
-            nc: NonCopyable
         }
     }
 
index 19478e3dbb3c8ed99e5faa8177d6634f1ff95be8..39b516aeb12a725fb6b2ff39f8b65c0707eb97c4 100644 (file)
@@ -481,6 +481,7 @@ mod tests {
     use iter::range;
     use str::StrSlice;
     use util;
+    use kinds::marker;
     use vec::ImmutableVector;
 
     #[test]
@@ -551,7 +552,7 @@ fn test_option_dance() {
 
     #[test] #[should_fail]
     fn test_option_too_much_dance() {
-        let mut y = Some(util::NonCopyable);
+        let mut y = Some(marker::NoPod);
         let _y2 = y.take_unwrap();
         let _y3 = y.take_unwrap();
     }
index fb62bed9ed0ae674fe88cba64d9381b7036b089d..9b90e43449107acc1ce4dc990384753654c0da38 100644 (file)
 
 use unstable::intrinsics;
 use cast;
+use std::kinds::marker;
 use option::{Option,Some,None};
 use ops::Drop;
-use util::NonCopyable;
 
 /**
  * A simple atomic flag, that can be set and cleared. The most basic atomic type.
  */
 pub struct AtomicFlag {
     priv v: int,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 
 /**
@@ -40,7 +40,7 @@ pub struct AtomicFlag {
  */
 pub struct AtomicBool {
     priv v: uint,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 
 /**
@@ -48,7 +48,7 @@ pub struct AtomicBool {
  */
 pub struct AtomicInt {
     priv v: int,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 
 /**
@@ -56,7 +56,7 @@ pub struct AtomicInt {
  */
 pub struct AtomicUint {
     priv v: uint,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 
 /**
@@ -66,7 +66,7 @@ pub struct AtomicUint {
 #[cfg(not(stage0))]
 pub struct AtomicU64 {
     priv v: u64,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 
 /**
@@ -75,12 +75,12 @@ pub struct AtomicU64 {
 #[cfg(not(stage0))]
 pub struct AtomicPtr<T> {
     priv p: uint,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 #[cfg(stage0)]
 pub struct AtomicPtr<T> {
     priv p: *mut T,
-    priv nocopy: NonCopyable
+    priv nopod: marker::NoPod
 }
 
 /**
@@ -105,17 +105,17 @@ pub enum Ordering {
     SeqCst
 }
 
-pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v: 0, nocopy: NonCopyable };
-pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: 0, nocopy: NonCopyable };
-pub static INIT_ATOMIC_INT  : AtomicInt  = AtomicInt  { v: 0, nocopy: NonCopyable };
-pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nocopy: NonCopyable };
+pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v: 0, nopod: marker::NoPod };
+pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: 0, nopod: marker::NoPod };
+pub static INIT_ATOMIC_INT  : AtomicInt  = AtomicInt  { v: 0, nopod: marker::NoPod };
+pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nopod: marker::NoPod };
 #[cfg(not(stage0))]
-pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nocopy: NonCopyable };
+pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nopod: marker::NoPod };
 
 impl AtomicFlag {
 
     pub fn new() -> AtomicFlag {
-        AtomicFlag { v: 0, nocopy: NonCopyable }
+        AtomicFlag { v: 0, nopod: marker::NoPod}
     }
 
     /**
@@ -138,7 +138,7 @@ pub fn test_and_set(&mut self, order: Ordering) -> bool {
 
 impl AtomicBool {
     pub fn new(v: bool) -> AtomicBool {
-        AtomicBool { v: if v { 1 } else { 0 }, nocopy: NonCopyable }
+        AtomicBool { v: if v { 1 } else { 0 }, nopod: marker::NoPod }
     }
 
     #[inline]
@@ -203,7 +203,7 @@ pub fn fetch_xor(&mut self, val: bool, order: Ordering) -> bool {
 
 impl AtomicInt {
     pub fn new(v: int) -> AtomicInt {
-        AtomicInt { v:v, nocopy: NonCopyable }
+        AtomicInt { v:v, nopod: marker::NoPod}
     }
 
     #[inline]
@@ -242,7 +242,7 @@ pub fn fetch_sub(&mut self, val: int, order: Ordering) -> int {
 #[cfg(not(stage0))]
 impl AtomicU64 {
     pub fn new(v: u64) -> AtomicU64 {
-        AtomicU64 { v:v, nocopy: NonCopyable }
+        AtomicU64 { v:v, nopod: marker::NoPod }
     }
 
     #[inline]
@@ -278,7 +278,7 @@ pub fn fetch_sub(&mut self, val: u64, order: Ordering) -> u64 {
 
 impl AtomicUint {
     pub fn new(v: uint) -> AtomicUint {
-        AtomicUint { v:v, nocopy: NonCopyable }
+        AtomicUint { v:v, nopod: marker::NoPod }
     }
 
     #[inline]
@@ -317,11 +317,11 @@ pub fn fetch_sub(&mut self, val: uint, order: Ordering) -> uint {
 impl<T> AtomicPtr<T> {
     #[cfg(stage0)]
     pub fn new(p: *mut T) -> AtomicPtr<T> {
-        AtomicPtr { p: p, nocopy: NonCopyable }
+        AtomicPtr { p: p, nopod: marker::NoPod }
     }
     #[cfg(not(stage0))]
     pub fn new(p: *mut T) -> AtomicPtr<T> {
-        AtomicPtr { p: p as uint, nocopy: NonCopyable }
+        AtomicPtr { p: p as uint, nopod: marker::NoPod }
     }
 
     #[inline]
index 5fa0c6431ab5caa5c7e31f55fd904368a5809660..078933be78fdd01fdd806c3ea30b52f3e90e02af 100644 (file)
@@ -56,7 +56,7 @@
 use any::Any;
 use comm::{Chan, Port};
 use io::Writer;
-use kinds::Send;
+use kinds::{Send, marker};
 use logging::Logger;
 use option::{None, Some, Option};
 use result::{Result, Ok, Err};
@@ -64,7 +64,6 @@
 use rt::task::Task;
 use send_str::{SendStr, IntoSendStr};
 use str::Str;
-use util;
 
 #[cfg(test)] use any::{AnyOwnExt, AnyRefExt};
 #[cfg(test)] use comm::SharedChan;
@@ -126,7 +125,7 @@ pub struct TaskOpts {
 pub struct TaskBuilder {
     opts: TaskOpts,
     priv gen_body: Option<proc(v: proc()) -> proc()>,
-    priv can_not_copy: Option<util::NonCopyable>,
+    priv nopod: Option<marker::NoPod>,
 }
 
 /**
@@ -138,7 +137,7 @@ pub fn task() -> TaskBuilder {
     TaskBuilder {
         opts: TaskOpts::new(),
         gen_body: None,
-        can_not_copy: None,
+        nopod: None,
     }
 }
 
index 06c7923bfeda15c36d90668ed5a2e315a36be98c..c075f9b4ba84f73e2d3c0314ff3be9635987699a 100644 (file)
@@ -12,7 +12,6 @@
 
 use cast;
 use ptr;
-use prelude::*;
 use unstable::intrinsics;
 
 /// The identity function.
@@ -53,15 +52,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
     src
 }
 
-/// A non-copyable dummy type.
-#[deriving(Eq, TotalEq, Ord, TotalOrd)]
-#[unsafe_no_drop_flag]
-pub struct NonCopyable;
-
-impl Drop for NonCopyable {
-    fn drop(&mut self) { }
-}
-
 /// A type with no inhabitants
 pub enum Void { }
 
@@ -101,37 +91,11 @@ fn test_swap() {
 
     #[test]
     fn test_replace() {
-        let mut x = Some(NonCopyable);
+        let mut x = Some(~"test");
         let y = replace(&mut x, None);
         assert!(x.is_none());
         assert!(y.is_some());
     }
-
-    #[test]
-    fn test_noncopyable() {
-        assert_eq!(size_of::<NonCopyable>(), 0);
-
-        // verify that `#[unsafe_no_drop_flag]` works as intended on a zero-size struct
-
-        static mut did_run: bool = false;
-
-        struct Foo { five: int }
-
-        impl Drop for Foo {
-            fn drop(&mut self) {
-                assert_eq!(self.five, 5);
-                unsafe {
-                    did_run = true;
-                }
-            }
-        }
-
-        {
-            let _a = (NonCopyable, Foo { five: 5 }, NonCopyable);
-        }
-
-        unsafe { assert_eq!(did_run, true); }
-    }
 }
 
 /// Completely miscellaneous language-construct benchmarks.
index dd7cc3a2314359aa8006c6e94fa2fa763c449133..b80c222d4dc8bec94d2d430fcd4f323714685a6d 100644 (file)
@@ -81,6 +81,7 @@
 
 use std::cell::Cell;
 use std::hashmap::HashSet;
+use std::kinds::marker;
 use std::util;
 use std::vec;
 
@@ -317,7 +318,7 @@ pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @Reader)
         obsolete_set: HashSet::new(),
         mod_path_stack: ~[],
         open_braces: ~[],
-        non_copyable: util::NonCopyable
+        nopod: marker::NoPod
     }
 }
 
@@ -348,7 +349,7 @@ pub struct Parser {
     /// Stack of spans of open delimiters. Used for error message.
     open_braces: ~[Span],
     /* do not copy the parser; its state is tied to outside state */
-    priv non_copyable: util::NonCopyable
+    priv nopod: marker::NoPod
 }
 
 fn is_plain_ident_or_underscore(t: &token::Token) -> bool {
index 5a0dae676f1350a1590e23a4bbe92e2255530bdc..0f09f423300228d528bbe9022ff041854cfb945f 100644 (file)
@@ -11,8 +11,9 @@
 // Issue 4691: Ensure that functional-struct-update can only copy, not
 // move, when the struct implements Drop.
 
-use NC = std::util::NonCopyable;
-struct S { a: int, nc: NC }
+// NoPod
+use NP = std::kinds::marker::NoPod;
+struct S { a: int, np: NP }
 impl Drop for S { fn drop(&mut self) { } }
 
 struct T { a: int, mv: ~int }
index a0fb31e64bf673e904bd19ec614cbacbfa14363f..878ea298db3956149607963f6b0b0fcbc72bb496 100644 (file)
 // Issue 4691: Ensure that functional-struct-updates operates
 // correctly and moves rather than copy when appropriate.
 
-use NC = std::util::NonCopyable;
+use NP = std::kinds::marker::NoPod;
 
-struct ncint { nc: NC, v: int }
-fn ncint(v: int) -> ncint { ncint { nc: NC, v: v } }
+struct ncint { np: NP, v: int }
+fn ncint(v: int) -> ncint { ncint { np: NP, v: v } }
 
-struct NoFoo { copied: int, noncopy: ncint, }
+struct NoFoo { copied: int, nopod: ncint, }
 impl NoFoo {
-    fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, noncopy: ncint(y) } }
+    fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, nopod: 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: NonCopyable
+    // Case 1: Nopodable
     let f = DropNoFoo::new(1, 2);
-    let b = DropNoFoo { inner: NoFoo { noncopy: ncint(3), ..f.inner }};
-    let c = DropNoFoo { inner: NoFoo { noncopy: ncint(4), ..f.inner }};
+    let b = DropNoFoo { inner: NoFoo { nopod: ncint(3), ..f.inner }};
+    let c = DropNoFoo { inner: NoFoo { nopod: ncint(4), ..f.inner }};
     assert_eq!(f.inner.copied,    1);
-    assert_eq!(f.inner.noncopy.v, 2);
+    assert_eq!(f.inner.nopod.v, 2);
 
     assert_eq!(b.inner.copied,    1);
-    assert_eq!(b.inner.noncopy.v, 3);
+    assert_eq!(b.inner.nopod.v, 3);
 
     assert_eq!(c.inner.copied,    1);
-    assert_eq!(c.inner.noncopy.v, 4);
+    assert_eq!(c.inner.nopod.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 {noncopy: ncint(23), ..f};
+    let b = NoFoo {nopod: ncint(23), ..f};
     let c = NoFoo {copied: 24, ..f};
     assert_eq!(b.copied,    21);
-    assert_eq!(b.noncopy.v, 23);
+    assert_eq!(b.nopod.v, 23);
     assert_eq!(c.copied,    24);
-    assert_eq!(c.noncopy.v, 22);
+    assert_eq!(c.nopod.v, 22);
 }
 
 pub fn main() {