Skip to content

Commit 2877928

Browse files
committed
auto merge of #12016 : FlaPer87/rust/remove-non-copyable, r=alexcrichton
cc #10834
2 parents fde11e7 + c6b1bce commit 2877928

File tree

9 files changed

+58
-93
lines changed

9 files changed

+58
-93
lines changed

Diff for: src/libextra/sync/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
use std::cast;
2121
use std::comm;
22+
use std::kinds::marker;
2223
use std::sync::arc::UnsafeArc;
2324
use std::sync::atomics;
2425
use std::unstable::finally::Finally;
2526
use std::util;
26-
use std::util::NonCopyable;
2727

2828
use arc::MutexArc;
2929

@@ -191,7 +191,7 @@ pub struct Condvar<'a> {
191191
// See the comment in write_cond for more detail.
192192
priv order: ReacquireOrderLock<'a>,
193193
// Make sure condvars are non-copyable.
194-
priv token: util::NonCopyable,
194+
priv nopod: marker::NoPod,
195195
}
196196

197197
impl<'a> Condvar<'a> {
@@ -334,7 +334,7 @@ impl Sem<~[WaitQueue]> {
334334
blk(&Condvar {
335335
sem: self,
336336
order: Nothing,
337-
token: NonCopyable
337+
nopod: marker::NoPod
338338
})
339339
})
340340
}
@@ -574,7 +574,7 @@ impl RWLock {
574574
(&self.order_lock).release();
575575
let opt_lock = Just(&self.order_lock);
576576
blk(&Condvar { sem: cond.sem, order: opt_lock,
577-
token: NonCopyable })
577+
nopod: marker::NoPod })
578578
})
579579
}
580580

@@ -609,7 +609,7 @@ impl RWLock {
609609
(&self.access_lock).acquire();
610610
(&self.order_lock).release();
611611
(|| {
612-
blk(RWLockWriteMode { lock: self, token: NonCopyable })
612+
blk(RWLockWriteMode { lock: self, nopod: marker::NoPod })
613613
}).finally(|| {
614614
let writer_or_last_reader;
615615
// Check if we're releasing from read mode or from write mode.
@@ -662,16 +662,16 @@ impl RWLock {
662662
(&self.access_lock).release();
663663
}
664664
}
665-
RWLockReadMode { lock: token.lock, token: NonCopyable }
665+
RWLockReadMode { lock: token.lock, nopod: marker::NoPod }
666666
}
667667
}
668668

669669
/// The "write permission" token used for rwlock.write_downgrade().
670670
671-
pub struct RWLockWriteMode<'a> { priv lock: &'a RWLock, priv token: NonCopyable }
671+
pub struct RWLockWriteMode<'a> { priv lock: &'a RWLock, priv nopod: marker::NoPod }
672672
/// The "read permission" token used for rwlock.write_downgrade().
673673
pub struct RWLockReadMode<'a> { priv lock: &'a RWLock,
674-
priv token: NonCopyable }
674+
priv nopod: marker::NoPod }
675675

676676
impl<'a> RWLockWriteMode<'a> {
677677
/// Access the pre-downgrade rwlock in write mode.
@@ -682,7 +682,7 @@ impl<'a> RWLockWriteMode<'a> {
682682
// access lock. See comment in RWLock::write_cond for why.
683683
blk(&Condvar { sem: &self.lock.access_lock,
684684
order: Just(&self.lock.order_lock),
685-
token: NonCopyable })
685+
nopod: marker::NoPod })
686686
}
687687
}
688688

Diff for: src/libstd/cell.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
1313
use prelude::*;
1414
use cast;
15-
use util::NonCopyable;
16-
use kinds::{marker,Pod};
15+
use kinds::{marker, Pod};
1716

1817
/// A mutable memory location that admits only `Pod` data.
1918
pub struct Cell<T> {
@@ -57,9 +56,9 @@ impl<T:Pod> Clone for Cell<T> {
5756
pub struct RefCell<T> {
5857
priv value: T,
5958
priv borrow: BorrowFlag,
60-
priv nc: NonCopyable,
6159
priv marker1: marker::InvariantType<T>,
6260
priv marker2: marker::NoFreeze,
61+
priv marker3: marker::NoPod,
6362
}
6463

6564
// Values [1, MAX-1] represent the number of `Ref` active
@@ -74,9 +73,9 @@ impl<T> RefCell<T> {
7473
RefCell {
7574
marker1: marker::InvariantType::<T>,
7675
marker2: marker::NoFreeze,
76+
marker3: marker::NoPod,
7777
value: value,
7878
borrow: UNUSED,
79-
nc: NonCopyable
8079
}
8180
}
8281

Diff for: src/libstd/option.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ mod tests {
481481
use iter::range;
482482
use str::StrSlice;
483483
use util;
484+
use kinds::marker;
484485
use vec::ImmutableVector;
485486

486487
#[test]
@@ -551,7 +552,7 @@ mod tests {
551552

552553
#[test] #[should_fail]
553554
fn test_option_too_much_dance() {
554-
let mut y = Some(util::NonCopyable);
555+
let mut y = Some(marker::NoPod);
555556
let _y2 = y.take_unwrap();
556557
let _y3 = y.take_unwrap();
557558
}

Diff for: src/libstd/sync/atomics.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,40 @@
2323

2424
use unstable::intrinsics;
2525
use cast;
26+
use std::kinds::marker;
2627
use option::{Option,Some,None};
2728
use ops::Drop;
28-
use util::NonCopyable;
2929

3030
/**
3131
* A simple atomic flag, that can be set and cleared. The most basic atomic type.
3232
*/
3333
pub struct AtomicFlag {
3434
priv v: int,
35-
priv nocopy: NonCopyable
35+
priv nopod: marker::NoPod
3636
}
3737

3838
/**
3939
* An atomic boolean type.
4040
*/
4141
pub struct AtomicBool {
4242
priv v: uint,
43-
priv nocopy: NonCopyable
43+
priv nopod: marker::NoPod
4444
}
4545

4646
/**
4747
* A signed atomic integer type, supporting basic atomic arithmetic operations
4848
*/
4949
pub struct AtomicInt {
5050
priv v: int,
51-
priv nocopy: NonCopyable
51+
priv nopod: marker::NoPod
5252
}
5353

5454
/**
5555
* An unsigned atomic integer type, supporting basic atomic arithmetic operations
5656
*/
5757
pub struct AtomicUint {
5858
priv v: uint,
59-
priv nocopy: NonCopyable
59+
priv nopod: marker::NoPod
6060
}
6161

6262
/**
@@ -66,7 +66,7 @@ pub struct AtomicUint {
6666
#[cfg(not(stage0))]
6767
pub struct AtomicU64 {
6868
priv v: u64,
69-
priv nocopy: NonCopyable
69+
priv nopod: marker::NoPod
7070
}
7171

7272
/**
@@ -75,12 +75,12 @@ pub struct AtomicU64 {
7575
#[cfg(not(stage0))]
7676
pub struct AtomicPtr<T> {
7777
priv p: uint,
78-
priv nocopy: NonCopyable
78+
priv nopod: marker::NoPod
7979
}
8080
#[cfg(stage0)]
8181
pub struct AtomicPtr<T> {
8282
priv p: *mut T,
83-
priv nocopy: NonCopyable
83+
priv nopod: marker::NoPod
8484
}
8585

8686
/**
@@ -105,17 +105,17 @@ pub enum Ordering {
105105
SeqCst
106106
}
107107

108-
pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v: 0, nocopy: NonCopyable };
109-
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: 0, nocopy: NonCopyable };
110-
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: 0, nocopy: NonCopyable };
111-
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nocopy: NonCopyable };
108+
pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v: 0, nopod: marker::NoPod };
109+
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: 0, nopod: marker::NoPod };
110+
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: 0, nopod: marker::NoPod };
111+
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nopod: marker::NoPod };
112112
#[cfg(not(stage0))]
113-
pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nocopy: NonCopyable };
113+
pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nopod: marker::NoPod };
114114

115115
impl AtomicFlag {
116116

117117
pub fn new() -> AtomicFlag {
118-
AtomicFlag { v: 0, nocopy: NonCopyable }
118+
AtomicFlag { v: 0, nopod: marker::NoPod}
119119
}
120120

121121
/**
@@ -138,7 +138,7 @@ impl AtomicFlag {
138138

139139
impl AtomicBool {
140140
pub fn new(v: bool) -> AtomicBool {
141-
AtomicBool { v: if v { 1 } else { 0 }, nocopy: NonCopyable }
141+
AtomicBool { v: if v { 1 } else { 0 }, nopod: marker::NoPod }
142142
}
143143

144144
#[inline]
@@ -203,7 +203,7 @@ impl AtomicBool {
203203

204204
impl AtomicInt {
205205
pub fn new(v: int) -> AtomicInt {
206-
AtomicInt { v:v, nocopy: NonCopyable }
206+
AtomicInt { v:v, nopod: marker::NoPod}
207207
}
208208

209209
#[inline]
@@ -242,7 +242,7 @@ impl AtomicInt {
242242
#[cfg(not(stage0))]
243243
impl AtomicU64 {
244244
pub fn new(v: u64) -> AtomicU64 {
245-
AtomicU64 { v:v, nocopy: NonCopyable }
245+
AtomicU64 { v:v, nopod: marker::NoPod }
246246
}
247247

248248
#[inline]
@@ -278,7 +278,7 @@ impl AtomicU64 {
278278

279279
impl AtomicUint {
280280
pub fn new(v: uint) -> AtomicUint {
281-
AtomicUint { v:v, nocopy: NonCopyable }
281+
AtomicUint { v:v, nopod: marker::NoPod }
282282
}
283283

284284
#[inline]
@@ -317,11 +317,11 @@ impl AtomicUint {
317317
impl<T> AtomicPtr<T> {
318318
#[cfg(stage0)]
319319
pub fn new(p: *mut T) -> AtomicPtr<T> {
320-
AtomicPtr { p: p, nocopy: NonCopyable }
320+
AtomicPtr { p: p, nopod: marker::NoPod }
321321
}
322322
#[cfg(not(stage0))]
323323
pub fn new(p: *mut T) -> AtomicPtr<T> {
324-
AtomicPtr { p: p as uint, nocopy: NonCopyable }
324+
AtomicPtr { p: p as uint, nopod: marker::NoPod }
325325
}
326326

327327
#[inline]

Diff for: src/libstd/task.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@
5656
use any::Any;
5757
use comm::{Chan, Port};
5858
use io::Writer;
59-
use kinds::Send;
59+
use kinds::{Send, marker};
6060
use logging::Logger;
6161
use option::{None, Some, Option};
6262
use result::{Result, Ok, Err};
6363
use rt::local::Local;
6464
use rt::task::Task;
6565
use send_str::{SendStr, IntoSendStr};
6666
use str::Str;
67-
use util;
6867

6968
#[cfg(test)] use any::{AnyOwnExt, AnyRefExt};
7069
#[cfg(test)] use comm::SharedChan;
@@ -126,7 +125,7 @@ pub struct TaskOpts {
126125
pub struct TaskBuilder {
127126
opts: TaskOpts,
128127
priv gen_body: Option<proc(v: proc()) -> proc()>,
129-
priv can_not_copy: Option<util::NonCopyable>,
128+
priv nopod: Option<marker::NoPod>,
130129
}
131130

132131
/**
@@ -138,7 +137,7 @@ pub fn task() -> TaskBuilder {
138137
TaskBuilder {
139138
opts: TaskOpts::new(),
140139
gen_body: None,
141-
can_not_copy: None,
140+
nopod: None,
142141
}
143142
}
144143

Diff for: src/libstd/util.rs

+1-37
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use cast;
1414
use ptr;
15-
use prelude::*;
1615
use unstable::intrinsics;
1716

1817
/// The identity function.
@@ -53,15 +52,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
5352
src
5453
}
5554

56-
/// A non-copyable dummy type.
57-
#[deriving(Eq, TotalEq, Ord, TotalOrd)]
58-
#[unsafe_no_drop_flag]
59-
pub struct NonCopyable;
60-
61-
impl Drop for NonCopyable {
62-
fn drop(&mut self) { }
63-
}
64-
6555
/// A type with no inhabitants
6656
pub enum Void { }
6757

@@ -101,37 +91,11 @@ mod tests {
10191

10292
#[test]
10393
fn test_replace() {
104-
let mut x = Some(NonCopyable);
94+
let mut x = Some(~"test");
10595
let y = replace(&mut x, None);
10696
assert!(x.is_none());
10797
assert!(y.is_some());
10898
}
109-
110-
#[test]
111-
fn test_noncopyable() {
112-
assert_eq!(size_of::<NonCopyable>(), 0);
113-
114-
// verify that `#[unsafe_no_drop_flag]` works as intended on a zero-size struct
115-
116-
static mut did_run: bool = false;
117-
118-
struct Foo { five: int }
119-
120-
impl Drop for Foo {
121-
fn drop(&mut self) {
122-
assert_eq!(self.five, 5);
123-
unsafe {
124-
did_run = true;
125-
}
126-
}
127-
}
128-
129-
{
130-
let _a = (NonCopyable, Foo { five: 5 }, NonCopyable);
131-
}
132-
133-
unsafe { assert_eq!(did_run, true); }
134-
}
13599
}
136100

137101
/// Completely miscellaneous language-construct benchmarks.

Diff for: src/libsyntax/parse/parser.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ use opt_vec::OptVec;
8181

8282
use std::cell::Cell;
8383
use std::hashmap::HashSet;
84+
use std::kinds::marker;
8485
use std::util;
8586
use std::vec;
8687

@@ -317,7 +318,7 @@ pub fn Parser(sess: @ParseSess, cfg: ast::CrateConfig, rdr: @Reader)
317318
obsolete_set: HashSet::new(),
318319
mod_path_stack: ~[],
319320
open_braces: ~[],
320-
non_copyable: util::NonCopyable
321+
nopod: marker::NoPod
321322
}
322323
}
323324

@@ -348,7 +349,7 @@ pub struct Parser {
348349
/// Stack of spans of open delimiters. Used for error message.
349350
open_braces: ~[Span],
350351
/* do not copy the parser; its state is tied to outside state */
351-
priv non_copyable: util::NonCopyable
352+
priv nopod: marker::NoPod
352353
}
353354

354355
fn is_plain_ident_or_underscore(t: &token::Token) -> bool {

0 commit comments

Comments
 (0)