Skip to content

Replace NonCopyable usage with NoPod #12016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/libextra/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -334,7 +334,7 @@ impl Sem<~[WaitQueue]> {
blk(&Condvar {
sem: self,
order: Nothing,
token: NonCopyable
nopod: marker::NoPod
})
})
}
Expand Down Expand Up @@ -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 })
})
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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 })
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ mod tests {
use iter::range;
use str::StrSlice;
use util;
use kinds::marker;
use vec::ImmutableVector;

#[test]
Expand Down Expand Up @@ -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();
}
Expand Down
40 changes: 20 additions & 20 deletions src/libstd/sync/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,40 @@

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
}

/**
* An atomic boolean type.
*/
pub struct AtomicBool {
priv v: uint,
priv nocopy: NonCopyable
priv nopod: marker::NoPod
}

/**
* A signed atomic integer type, supporting basic atomic arithmetic operations
*/
pub struct AtomicInt {
priv v: int,
priv nocopy: NonCopyable
priv nopod: marker::NoPod
}

/**
* An unsigned atomic integer type, supporting basic atomic arithmetic operations
*/
pub struct AtomicUint {
priv v: uint,
priv nocopy: NonCopyable
priv nopod: marker::NoPod
}

/**
Expand All @@ -66,7 +66,7 @@ pub struct AtomicUint {
#[cfg(not(stage0))]
pub struct AtomicU64 {
priv v: u64,
priv nocopy: NonCopyable
priv nopod: marker::NoPod
}

/**
Expand All @@ -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
}

/**
Expand All @@ -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}
}

/**
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions src/libstd/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@
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};
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;
Expand Down Expand Up @@ -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>,
}

/**
Expand All @@ -138,7 +137,7 @@ pub fn task() -> TaskBuilder {
TaskBuilder {
opts: TaskOpts::new(),
gen_body: None,
can_not_copy: None,
nopod: None,
}
}

Expand Down
38 changes: 1 addition & 37 deletions src/libstd/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use cast;
use ptr;
use prelude::*;
use unstable::intrinsics;

/// The identity function.
Expand Down Expand Up @@ -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 { }

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand Down
Loading