Skip to content

Commit e7b0b71

Browse files
committed
Remove moves from *T and implement in another way
1 parent eb48c29 commit e7b0b71

File tree

4 files changed

+12
-30
lines changed

4 files changed

+12
-30
lines changed

src/libextra/c_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: @fn())
122122
*/
123123
pub fn get<T:Copy>(t: CVec<T>, ofs: uint) -> T {
124124
assert!(ofs < len(t));
125-
return unsafe { *ptr::mut_offset(t.base, ofs) };
125+
return unsafe { copy *ptr::mut_offset(t.base, ofs) };
126126
}
127127

128128
/**

src/libstd/pipes.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ bounded and unbounded protocols allows for less code duplication.
8585
#[allow(missing_doc)];
8686

8787
use container::Container;
88-
use cast::{forget, transmute, transmute_copy};
88+
use cast::{forget, transmute, transmute_copy, transmute_mut};
89+
use cast;
8990
use either::{Either, Left, Right};
9091
use iterator::IteratorUtil;
9192
use kinds::Owned;
@@ -102,10 +103,6 @@ use util::replace;
102103

103104
static SPIN_COUNT: uint = 0;
104105

105-
macro_rules! move_it (
106-
{ $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
107-
)
108-
109106
#[deriving(Eq)]
110107
enum State {
111108
Empty,
@@ -316,9 +313,11 @@ impl<T> Drop for BufferResource<T> {
316313
fn finalize(&self) {
317314
unsafe {
318315
// FIXME(#4330) Need self by value to get mutability.
319-
let this: &mut BufferResource<T> = transmute(self);
316+
let this: &mut BufferResource<T> = transmute_mut(self);
317+
318+
let null_buffer: ~Buffer<T> = transmute(ptr::null::<Buffer<T>>());
319+
let mut b = replace(&mut this.buffer, null_buffer);
320320

321-
let mut b = move_it!(this.buffer);
322321
//let p = ptr::to_unsafe_ptr(*b);
323322
//error!("drop %?", p);
324323
let old_count = intrinsics::atomic_xsub_rel(

src/libstd/task/spawn.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ use iterator::{IteratorUtil};
9898
#[cfg(test)] use comm;
9999
#[cfg(test)] use task;
100100

101-
macro_rules! move_it (
102-
{ $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
103-
)
104-
105101
type TaskSet = HashSet<*rust_task>;
106102

107103
fn new_taskset() -> TaskSet {
@@ -638,23 +634,16 @@ fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) {
638634
notify_chan: Option<Chan<TaskResult>>,
639635
f: ~fn())
640636
-> ~fn() {
641-
let child_data = Cell::new((child_arc, ancestors));
637+
let child_data = Cell::new((notify_chan, child_arc, ancestors));
642638
let result: ~fn() = || {
643639
// Agh. Get move-mode items into the closure. FIXME (#2829)
644-
let mut (child_arc, ancestors) = child_data.take();
640+
let mut (notify_chan, child_arc, ancestors) = child_data.take();
645641
// Child task runs this code.
646642

647643
// Even if the below code fails to kick the child off, we must
648644
// send Something on the notify channel.
649645

650-
//let mut notifier = None;//notify_chan.map(|c| AutoNotify(c));
651-
let notifier = match notify_chan {
652-
Some(ref notify_chan_value) => {
653-
let moved_ncv = move_it!(*notify_chan_value);
654-
Some(AutoNotify(moved_ncv))
655-
}
656-
_ => None
657-
};
646+
let notifier = notify_chan.map_consume(|c| AutoNotify(c));
658647

659648
if enlist_many(child, &child_arc, &mut ancestors) {
660649
let group = @@mut TCB(child,

src/test/run-pass/pipe-bank-proto.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,18 @@ proto! bank (
4545
}
4646
)
4747

48-
macro_rules! move_it (
49-
{ $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } }
50-
)
51-
5248
fn switch<T:Owned,U>(endp: pipes::RecvPacket<T>,
5349
f: &fn(v: Option<T>) -> U) -> U {
5450
f(pipes::try_recv(endp))
5551
}
5652

57-
fn move_it<T>(x: T) -> T { x }
58-
5953
macro_rules! follow (
6054
{
6155
$($message:path$(($($x: ident),+))||* -> $next:ident $e:expr)+
6256
} => (
6357
|m| match m {
6458
$(Some($message($($($x,)+)* next)) => {
65-
let $next = move_it!(next);
59+
let $next = next;
6660
$e })+
6761
_ => { fail!() }
6862
}
@@ -96,7 +90,7 @@ fn bank_client(bank: bank::client::login) {
9690
let bank = client::login(bank, ~"theincredibleholk", ~"1234");
9791
let bank = match try_recv(bank) {
9892
Some(ok(connected)) => {
99-
move_it!(connected)
93+
connected
10094
}
10195
Some(invalid(_)) => { fail!("login unsuccessful") }
10296
None => { fail!("bank closed the connection") }

0 commit comments

Comments
 (0)