libsyntax: Forbid ~mut
and ~const
. rs=demuting
This commit is contained in:
parent
061a223723
commit
8d7e6ef772
doc
src
libcore
libstd
libsyntax/parse
test/compile-fail
@ -1126,7 +1126,7 @@ points to.
|
||||
|
||||
~~~
|
||||
let managed = @mut 10;
|
||||
let owned = ~mut 20;
|
||||
let mut owned = ~20;
|
||||
|
||||
let mut value = 30;
|
||||
let borrowed = &mut value;
|
||||
|
@ -13,22 +13,22 @@
|
||||
use cmp::{Eq, Ord};
|
||||
|
||||
#[cfg(notest)]
|
||||
impl<T:Eq> Eq for ~const T {
|
||||
impl<T:Eq> Eq for ~T {
|
||||
#[inline(always)]
|
||||
pure fn eq(&self, other: &~const T) -> bool { *(*self) == *(*other) }
|
||||
pure fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) }
|
||||
#[inline(always)]
|
||||
pure fn ne(&self, other: &~const T) -> bool { *(*self) != *(*other) }
|
||||
pure fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) }
|
||||
}
|
||||
|
||||
#[cfg(notest)]
|
||||
impl<T:Ord> Ord for ~const T {
|
||||
impl<T:Ord> Ord for ~T {
|
||||
#[inline(always)]
|
||||
pure fn lt(&self, other: &~const T) -> bool { *(*self) < *(*other) }
|
||||
pure fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) }
|
||||
#[inline(always)]
|
||||
pure fn le(&self, other: &~const T) -> bool { *(*self) <= *(*other) }
|
||||
pure fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) }
|
||||
#[inline(always)]
|
||||
pure fn ge(&self, other: &~const T) -> bool { *(*self) >= *(*other) }
|
||||
pure fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) }
|
||||
#[inline(always)]
|
||||
pure fn gt(&self, other: &~const T) -> bool { *(*self) > *(*other) }
|
||||
pure fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ use sync;
|
||||
use sync::{Mutex, mutex_with_condvars, RWlock, rwlock_with_condvars};
|
||||
|
||||
use core::cast;
|
||||
use core::cell::Cell;
|
||||
use core::pipes;
|
||||
use core::prelude::*;
|
||||
use core::private::{SharedMutableState, shared_mutable_state};
|
||||
@ -532,17 +533,17 @@ mod tests {
|
||||
let arc = ~MutexARC(false);
|
||||
let arc2 = ~arc.clone();
|
||||
let (p,c) = comm::oneshot();
|
||||
let (c,p) = (~mut Some(c), ~mut Some(p));
|
||||
let (c,p) = (Cell(c), Cell(p));
|
||||
do task::spawn || {
|
||||
// wait until parent gets in
|
||||
comm::recv_one(option::swap_unwrap(p));
|
||||
comm::recv_one(p.take());
|
||||
do arc2.access_cond |state, cond| {
|
||||
*state = true;
|
||||
cond.signal();
|
||||
}
|
||||
}
|
||||
do arc.access_cond |state, cond| {
|
||||
comm::send_one(option::swap_unwrap(c), ());
|
||||
comm::send_one(c.take(), ());
|
||||
assert !*state;
|
||||
while !*state {
|
||||
cond.wait();
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
use core::cast::copy_lifetime;
|
||||
use core::cast;
|
||||
use core::cell::Cell;
|
||||
use core::either::Either;
|
||||
use core::option;
|
||||
use core::comm::{oneshot, ChanOne, PortOne, send_one, recv_one};
|
||||
@ -103,11 +104,9 @@ pub fn from_port<A:Owned>(port: PortOne<A>) ->
|
||||
* waiting for the result to be received on the port.
|
||||
*/
|
||||
|
||||
let port = ~mut Some(port);
|
||||
let port = Cell(port);
|
||||
do from_fn || {
|
||||
let mut port_ = None;
|
||||
port_ <-> *port;
|
||||
let port = option::unwrap(port_);
|
||||
let port = port.take();
|
||||
match recv(port) {
|
||||
oneshot::send(data) => data
|
||||
}
|
||||
@ -136,9 +135,9 @@ pub fn spawn<A:Owned>(blk: fn~() -> A) -> Future<A> {
|
||||
|
||||
let (chan, port) = oneshot::init();
|
||||
|
||||
let chan = ~mut Some(chan);
|
||||
let chan = Cell(chan);
|
||||
do task::spawn || {
|
||||
let chan = option::swap_unwrap(&mut *chan);
|
||||
let chan = chan.take();
|
||||
send_one(chan, blk());
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
* in std.
|
||||
*/
|
||||
|
||||
use core::cell::Cell;
|
||||
use core::option;
|
||||
use core::pipes;
|
||||
use core::prelude::*;
|
||||
@ -799,9 +800,9 @@ mod tests {
|
||||
let s = ~semaphore(1);
|
||||
let s2 = ~s.clone();
|
||||
let (p,c) = comm::stream();
|
||||
let child_data = ~mut Some((s2, c));
|
||||
let child_data = Cell((s2, c));
|
||||
do s.access {
|
||||
let (s2,c) = option::swap_unwrap(child_data);
|
||||
let (s2, c) = child_data.take();
|
||||
do task::spawn || {
|
||||
c.send(());
|
||||
do s2.access { }
|
||||
@ -976,13 +977,13 @@ mod tests {
|
||||
let mut sibling_convos = ~[];
|
||||
for 2.times {
|
||||
let (p,c) = comm::stream();
|
||||
let c = ~mut Some(c);
|
||||
let c = Cell(c);
|
||||
sibling_convos.push(p);
|
||||
let mi = ~m2.clone();
|
||||
// spawn sibling task
|
||||
do task::spawn || { // linked
|
||||
do task::spawn { // linked
|
||||
do mi.lock_cond |cond| {
|
||||
let c = option::swap_unwrap(c);
|
||||
let c = c.take();
|
||||
c.send(()); // tell sibling to go ahead
|
||||
let _z = SendOnFailure(c);
|
||||
cond.wait(); // block forever
|
||||
|
@ -15,6 +15,7 @@ use sha1;
|
||||
use serialize::{Encoder, Encodable, Decoder, Decodable};
|
||||
use sort;
|
||||
|
||||
use core::cell::Cell;
|
||||
use core::cmp;
|
||||
use core::either::{Either, Left, Right};
|
||||
use core::io;
|
||||
@ -339,11 +340,11 @@ impl TPrep for @Mut<Prep> {
|
||||
let mut blk = None;
|
||||
blk <-> bo;
|
||||
let blk = blk.unwrap();
|
||||
let chan = ~mut Some(chan);
|
||||
let chan = Cell(chan);
|
||||
do task::spawn || {
|
||||
let exe = Exec{discovered_inputs: LinearMap::new(),
|
||||
discovered_outputs: LinearMap::new()};
|
||||
let chan = option::swap_unwrap(&mut *chan);
|
||||
let chan = chan.take();
|
||||
let v = blk(&exe);
|
||||
send_one(chan, (exe, v));
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ pub impl Parser {
|
||||
"write `+` between trait bounds"
|
||||
),
|
||||
ObsoleteMutOwnedPointer => (
|
||||
"mutable owned pointer",
|
||||
"const or mutable owned pointer",
|
||||
"mutability inherits through `~` pointers; place the `~` box
|
||||
in a mutable location, like a mutable local variable or an \
|
||||
`@mut` box"
|
||||
|
@ -678,7 +678,7 @@ pub impl Parser {
|
||||
// reflected in the AST type.
|
||||
let mt = self.parse_mt();
|
||||
|
||||
if mt.mutbl == m_mutbl && sigil == OwnedSigil {
|
||||
if mt.mutbl != m_imm && sigil == OwnedSigil {
|
||||
self.obsolete(*self.last_span, ObsoleteMutOwnedPointer);
|
||||
}
|
||||
|
||||
@ -1574,6 +1574,10 @@ pub impl Parser {
|
||||
token::TILDE => {
|
||||
self.bump();
|
||||
let m = self.parse_mutability();
|
||||
if m != m_imm {
|
||||
self.obsolete(*self.last_span, ObsoleteMutOwnedPointer);
|
||||
}
|
||||
|
||||
let e = self.parse_prefix_expr();
|
||||
hi = e.span.hi;
|
||||
// HACK: turn ~[...] into a ~-evec
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
fn f(&&v: ~const int) {
|
||||
*v = 1 //~ ERROR assigning to dereference of const ~ pointer
|
||||
}
|
||||
|
||||
let v = ~0;
|
||||
|
||||
f(v);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user