parent
d42521aa92
commit
c6b1bce96f
|
@ -19,11 +19,11 @@
|
|||
|
||||
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 @@ impl Sem<~[WaitQueue]> {
|
|||
blk(&Condvar {
|
||||
sem: self,
|
||||
order: Nothing,
|
||||
token: NonCopyable
|
||||
nopod: marker::NoPod
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ impl RWLock {
|
|||
(&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 @@ impl RWLock {
|
|||
(&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 @@ impl RWLock {
|
|||
(&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 @@ impl<'a> RWLockWriteMode<'a> {
|
|||
// 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 })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ impl<T:Pod> Clone for 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 @@ impl<T> RefCell<T> {
|
|||
RefCell {
|
||||
marker1: marker::InvariantType::<T>,
|
||||
marker2: marker::NoFreeze,
|
||||
marker3: marker::NoPod,
|
||||
value: value,
|
||||
borrow: UNUSED,
|
||||
nc: NonCopyable
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ mod tests {
|
|||
|
||||
#[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();
|
||||
}
|
||||
|
|
|
@ -23,16 +23,16 @@
|
|||
|
||||
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 @@ impl AtomicFlag {
|
|||
|
||||
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 @@ impl AtomicBool {
|
|||
|
||||
impl AtomicInt {
|
||||
pub fn new(v: int) -> AtomicInt {
|
||||
AtomicInt { v:v, nocopy: NonCopyable }
|
||||
AtomicInt { v:v, nopod: marker::NoPod}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -242,7 +242,7 @@ impl AtomicInt {
|
|||
#[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 @@ impl AtomicU64 {
|
|||
|
||||
impl AtomicUint {
|
||||
pub fn new(v: uint) -> AtomicUint {
|
||||
AtomicUint { v:v, nocopy: NonCopyable }
|
||||
AtomicUint { v:v, nopod: marker::NoPod }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -317,11 +317,11 @@ impl AtomicUint {
|
|||
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]
|
||||
|
|
|
@ -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::local::Local;
|
|||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 @@ mod tests {
|
|||
|
||||
#[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.
|
||||
|
|
|
@ -81,6 +81,7 @@ use opt_vec::OptVec;
|
|||
|
||||
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 {
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
// 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() {
|
||||
|
|
Loading…
Reference in New Issue