Skip to content

Commit 8d7e6ef

Browse files
committed
libsyntax: Forbid ~mut and ~const. rs=demuting
1 parent 061a223 commit 8d7e6ef

File tree

9 files changed

+33
-46
lines changed

9 files changed

+33
-46
lines changed

doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ points to.
11261126
11271127
~~~
11281128
let managed = @mut 10;
1129-
let owned = ~mut 20;
1129+
let mut owned = ~20;
11301130

11311131
let mut value = 30;
11321132
let borrowed = &mut value;

src/libcore/owned.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
use cmp::{Eq, Ord};
1414

1515
#[cfg(notest)]
16-
impl<T:Eq> Eq for ~const T {
16+
impl<T:Eq> Eq for ~T {
1717
#[inline(always)]
18-
pure fn eq(&self, other: &~const T) -> bool { *(*self) == *(*other) }
18+
pure fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) }
1919
#[inline(always)]
20-
pure fn ne(&self, other: &~const T) -> bool { *(*self) != *(*other) }
20+
pure fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) }
2121
}
2222

2323
#[cfg(notest)]
24-
impl<T:Ord> Ord for ~const T {
24+
impl<T:Ord> Ord for ~T {
2525
#[inline(always)]
26-
pure fn lt(&self, other: &~const T) -> bool { *(*self) < *(*other) }
26+
pure fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) }
2727
#[inline(always)]
28-
pure fn le(&self, other: &~const T) -> bool { *(*self) <= *(*other) }
28+
pure fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) }
2929
#[inline(always)]
30-
pure fn ge(&self, other: &~const T) -> bool { *(*self) >= *(*other) }
30+
pure fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
3131
#[inline(always)]
32-
pure fn gt(&self, other: &~const T) -> bool { *(*self) > *(*other) }
32+
pure fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
3333
}
3434

src/libstd/arc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use sync;
1717
use sync::{Mutex, mutex_with_condvars, RWlock, rwlock_with_condvars};
1818

1919
use core::cast;
20+
use core::cell::Cell;
2021
use core::pipes;
2122
use core::prelude::*;
2223
use core::private::{SharedMutableState, shared_mutable_state};
@@ -532,17 +533,17 @@ mod tests {
532533
let arc = ~MutexARC(false);
533534
let arc2 = ~arc.clone();
534535
let (p,c) = comm::oneshot();
535-
let (c,p) = (~mut Some(c), ~mut Some(p));
536+
let (c,p) = (Cell(c), Cell(p));
536537
do task::spawn || {
537538
// wait until parent gets in
538-
comm::recv_one(option::swap_unwrap(p));
539+
comm::recv_one(p.take());
539540
do arc2.access_cond |state, cond| {
540541
*state = true;
541542
cond.signal();
542543
}
543544
}
544545
do arc.access_cond |state, cond| {
545-
comm::send_one(option::swap_unwrap(c), ());
546+
comm::send_one(c.take(), ());
546547
assert !*state;
547548
while !*state {
548549
cond.wait();

src/libstd/future.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use core::cast::copy_lifetime;
2525
use core::cast;
26+
use core::cell::Cell;
2627
use core::either::Either;
2728
use core::option;
2829
use core::comm::{oneshot, ChanOne, PortOne, send_one, recv_one};
@@ -103,11 +104,9 @@ pub fn from_port<A:Owned>(port: PortOne<A>) ->
103104
* waiting for the result to be received on the port.
104105
*/
105106
106-
let port = ~mut Some(port);
107+
let port = Cell(port);
107108
do from_fn || {
108-
let mut port_ = None;
109-
port_ <-> *port;
110-
let port = option::unwrap(port_);
109+
let port = port.take();
111110
match recv(port) {
112111
oneshot::send(data) => data
113112
}
@@ -136,9 +135,9 @@ pub fn spawn<A:Owned>(blk: fn~() -> A) -> Future<A> {
136135
137136
let (chan, port) = oneshot::init();
138137
139-
let chan = ~mut Some(chan);
138+
let chan = Cell(chan);
140139
do task::spawn || {
141-
let chan = option::swap_unwrap(&mut *chan);
140+
let chan = chan.take();
142141
send_one(chan, blk());
143142
}
144143

src/libstd/sync.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* in std.
1616
*/
1717

18+
use core::cell::Cell;
1819
use core::option;
1920
use core::pipes;
2021
use core::prelude::*;
@@ -799,9 +800,9 @@ mod tests {
799800
let s = ~semaphore(1);
800801
let s2 = ~s.clone();
801802
let (p,c) = comm::stream();
802-
let child_data = ~mut Some((s2, c));
803+
let child_data = Cell((s2, c));
803804
do s.access {
804-
let (s2,c) = option::swap_unwrap(child_data);
805+
let (s2, c) = child_data.take();
805806
do task::spawn || {
806807
c.send(());
807808
do s2.access { }
@@ -976,13 +977,13 @@ mod tests {
976977
let mut sibling_convos = ~[];
977978
for 2.times {
978979
let (p,c) = comm::stream();
979-
let c = ~mut Some(c);
980+
let c = Cell(c);
980981
sibling_convos.push(p);
981982
let mi = ~m2.clone();
982983
// spawn sibling task
983-
do task::spawn || { // linked
984+
do task::spawn { // linked
984985
do mi.lock_cond |cond| {
985-
let c = option::swap_unwrap(c);
986+
let c = c.take();
986987
c.send(()); // tell sibling to go ahead
987988
let _z = SendOnFailure(c);
988989
cond.wait(); // block forever

src/libstd/workcache.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use sha1;
1515
use serialize::{Encoder, Encodable, Decoder, Decodable};
1616
use sort;
1717

18+
use core::cell::Cell;
1819
use core::cmp;
1920
use core::either::{Either, Left, Right};
2021
use core::io;
@@ -339,11 +340,11 @@ impl TPrep for @Mut<Prep> {
339340
let mut blk = None;
340341
blk <-> bo;
341342
let blk = blk.unwrap();
342-
let chan = ~mut Some(chan);
343+
let chan = Cell(chan);
343344
do task::spawn || {
344345
let exe = Exec{discovered_inputs: LinearMap::new(),
345346
discovered_outputs: LinearMap::new()};
346-
let chan = option::swap_unwrap(&mut *chan);
347+
let chan = chan.take();
347348
let v = blk(&exe);
348349
send_one(chan, (exe, v));
349350
}

src/libsyntax/parse/obsolete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub impl Parser {
128128
"write `+` between trait bounds"
129129
),
130130
ObsoleteMutOwnedPointer => (
131-
"mutable owned pointer",
131+
"const or mutable owned pointer",
132132
"mutability inherits through `~` pointers; place the `~` box
133133
in a mutable location, like a mutable local variable or an \
134134
`@mut` box"

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ pub impl Parser {
678678
// reflected in the AST type.
679679
let mt = self.parse_mt();
680680

681-
if mt.mutbl == m_mutbl && sigil == OwnedSigil {
681+
if mt.mutbl != m_imm && sigil == OwnedSigil {
682682
self.obsolete(*self.last_span, ObsoleteMutOwnedPointer);
683683
}
684684

@@ -1574,6 +1574,10 @@ pub impl Parser {
15741574
token::TILDE => {
15751575
self.bump();
15761576
let m = self.parse_mutability();
1577+
if m != m_imm {
1578+
self.obsolete(*self.last_span, ObsoleteMutOwnedPointer);
1579+
}
1580+
15771581
let e = self.parse_prefix_expr();
15781582
hi = e.span.hi;
15791583
// HACK: turn ~[...] into a ~-evec

src/test/compile-fail/mutable-huh-unique-assign.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)