librustc: Remove ~EXPR, ~TYPE, and ~PAT from the language, except

for `~str`/`~[]`.

Note that `~self` still remains, since I forgot to add support for
`Box<self>` before the snapshot.

How to update your code:

* Instead of `~EXPR`, you should write `box EXPR`.

* Instead of `~TYPE`, you should write `Box<Type>`.

* Instead of `~PATTERN`, you should write `box PATTERN`.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-05-05 18:56:44 -07:00
parent 24f6f26e63
commit 090040bf40
495 changed files with 2252 additions and 1897 deletions

View file

@ -11,10 +11,11 @@
#![crate_id="a"]
#![crate_type = "lib"]
pub trait i<T> { }
pub fn f<T>() -> ~i<T> {
pub fn f<T>() -> Box<i<T>> {
impl<T> i<T> for () { }
~() as ~i<T>
box() () as Box<i<T>>
}

View file

@ -59,7 +59,7 @@ pub mod testtypes {
// Skipping ty_box
// Tests ty_uniq (of u8)
pub type FooUniq = ~u8;
pub type FooUniq = Box<u8>;
// As with ty_str, what type should be used for ty_vec?

View file

@ -29,7 +29,7 @@ impl Drop for Foo {
#[macro_registrar]
pub fn registrar(_: |Name, SyntaxExtension|) {
local_data_key!(foo: ~Any:Send);
local_data::set(foo, ~Foo { foo: 10 } as ~Any:Send);
local_data_key!(foo: Box<Any:Send>);
local_data::set(foo, box Foo { foo: 10 } as Box<Any:Send>);
}

View file

@ -27,7 +27,7 @@ macro_rules! unexported_macro (() => (3))
#[macro_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
register(token::intern("make_a_1"),
NormalTT(~BasicMacroExpander {
NormalTT(box BasicMacroExpander {
expander: expand_make_a_1,
span: None,
},
@ -35,7 +35,8 @@ pub fn macro_registrar(register: |Name, SyntaxExtension|) {
register(token::intern("into_foo"), ItemModifier(expand_into_foo));
}
fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> ~MacResult {
fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<MacResult> {
if !tts.is_empty() {
cx.span_fatal(sp, "make_a_1 takes no arguments");
}

View file

@ -25,14 +25,15 @@ use syntax::parse::token;
#[macro_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
register(token::intern("foo"),
NormalTT(~BasicMacroExpander {
NormalTT(box BasicMacroExpander {
expander: expand_foo,
span: None,
},
None));
}
fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> ~MacResult {
fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
-> Box<MacResult> {
let answer = other::the_answer();
MacExpr::new(quote_expr!(cx, $answer))
}

View file

@ -147,9 +147,9 @@ fn main() {
let rdr = if os::getenv("RUST_BENCH").is_some() {
let foo = include_bin!("shootout-k-nucleotide.data");
~MemReader::new(Vec::from_slice(foo)) as ~Reader
box MemReader::new(Vec::from_slice(foo)) as Box<Reader>
} else {
~stdio::stdin() as ~Reader
box stdio::stdin() as Box<Reader>
};
let mut rdr = BufferedReader::new(rdr);

View file

@ -91,16 +91,16 @@ impl TableCallback for PrintCallback {
struct Entry {
code: Code,
count: uint,
next: Option<~Entry>,
next: Option<Box<Entry>>,
}
struct Table {
count: uint,
items: Vec<Option<~Entry>> }
items: Vec<Option<Box<Entry>>> }
struct Items<'a> {
cur: Option<&'a Entry>,
items: slice::Items<'a, Option<~Entry>>,
items: slice::Items<'a, Option<Box<Entry>>>,
}
impl Table {
@ -114,7 +114,7 @@ impl Table {
fn search_remainder<C:TableCallback>(item: &mut Entry, key: Code, c: C) {
match item.next {
None => {
let mut entry = ~Entry {
let mut entry = box Entry {
code: key,
count: 0,
next: None,
@ -138,7 +138,7 @@ impl Table {
{
if self.items.get(index as uint).is_none() {
let mut entry = ~Entry {
let mut entry = box Entry {
code: key,
count: 0,
next: None,

View file

@ -34,9 +34,9 @@ fn count_matches(seq: &str, variant: &Regex) -> int {
fn main() {
let mut rdr = if std::os::getenv("RUST_BENCH").is_some() {
let fd = io::File::open(&Path::new("shootout-k-nucleotide.data"));
~io::BufferedReader::new(fd) as ~io::Reader
box io::BufferedReader::new(fd) as Box<io::Reader>
} else {
~io::stdin() as ~io::Reader
box io::stdin() as Box<io::Reader>
};
let mut seq = StrBuf::from_str(rdr.read_to_str().unwrap());
let ilen = seq.len();

View file

@ -15,8 +15,8 @@
use std::io;
use std::io::stdio::StdReader;
use std::io::BufferedReader;
use std::os;
use std::num::Bitwise;
use std::os;
// Computes a single solution to a given 9x9 sudoku
//
@ -132,7 +132,7 @@ impl Sudoku {
fn next_color(&mut self, row: u8, col: u8, start_color: u8) -> bool {
if start_color < 10u8 {
// colors not yet used
let mut avail = ~Colors::new(start_color);
let mut avail = box Colors::new(start_color);
// drop colors already in use in neighbourhood
self.drop_colors(avail, row, col);

View file

@ -24,7 +24,7 @@ enum List<T> {
}
enum UniqueList {
ULNil, ULCons(~UniqueList)
ULNil, ULCons(Box<UniqueList>)
}
fn main() {
@ -53,8 +53,8 @@ type nillist = List<()>;
struct State {
managed: @nillist,
unique: ~nillist,
tuple: (@nillist, ~nillist),
unique: Box<nillist>,
tuple: (@nillist, Box<nillist>),
vec: Vec<@nillist>,
res: r
}
@ -85,8 +85,8 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
None => {
State {
managed: @Nil,
unique: ~Nil,
tuple: (@Nil, ~Nil),
unique: box Nil,
tuple: (@Nil, box Nil),
vec: vec!(@Nil),
res: r(@Nil)
}
@ -94,9 +94,9 @@ fn recurse_or_fail(depth: int, st: Option<State>) {
Some(st) => {
State {
managed: @Cons((), st.managed),
unique: ~Cons((), @*st.unique),
unique: box Cons((), @*st.unique),
tuple: (@Cons((), st.tuple.ref0().clone()),
~Cons((), @*st.tuple.ref1().clone())),
box Cons((), @*st.tuple.ref1().clone())),
vec: st.vec.clone().append(&[@Cons((), *st.vec.last().unwrap())]),
res: r(@Cons((), st.res._l))
}

View file

@ -11,8 +11,9 @@
// Test that we detect nested calls that could free pointers evaluated
// for earlier arguments.
fn rewrite(v: &mut ~uint) -> uint {
*v = ~22;
fn rewrite(v: &mut Box<uint>) -> uint {
*v = box 22;
**v
}
@ -21,7 +22,7 @@ fn add(v: &uint, w: uint) -> uint {
}
fn implicit() {
let mut a = ~1;
let mut a = box 1;
// Note the danger here:
//
@ -34,7 +35,7 @@ fn implicit() {
}
fn explicit() {
let mut a = ~1;
let mut a = box 1;
add(
&*a,
rewrite(&mut a)); //~ ERROR cannot borrow

View file

@ -11,17 +11,18 @@
// Test that we detect nested calls that could free pointers evaluated
// for earlier arguments.
fn rewrite(v: &mut ~uint) -> uint {
*v = ~22;
fn rewrite(v: &mut Box<uint>) -> uint {
*v = box 22;
**v
}
fn add(v: &uint, w: ~uint) -> uint {
fn add(v: &uint, w: Box<uint>) -> uint {
*v + *w
}
fn implicit() {
let mut a = ~1;
let mut a = box 1;
// Note the danger here:
//
@ -34,7 +35,7 @@ fn implicit() {
}
fn explicit() {
let mut a = ~1;
let mut a = box 1;
add(
&*a,
a); //~ ERROR cannot move

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo {
bar1: Bar,
bar2: Bar
@ -18,7 +19,7 @@ struct Bar {
int2: int,
}
fn make_foo() -> ~Foo { fail!() }
fn make_foo() -> Box<Foo> { fail!() }
fn borrow_same_field_twice_mut_mut() {
let mut foo = make_foo();

View file

@ -78,7 +78,7 @@ fn deref_extend_mut_field2<'a>(x: &'a mut Own<Point>) -> &'a mut int {
}
fn deref_extend_mut_field3<'a>(x: &'a mut Own<Point>) {
// Hmm, this is unfortunate, because with ~ it would work,
// Hmm, this is unfortunate, because with box it would work,
// but it's presently the expected outcome. See `deref_extend_mut_field4`
// for the workaround.

View file

@ -15,9 +15,9 @@ use collections::HashMap;
fn main() {
let mut buggy_map: HashMap<uint, &uint> = HashMap::new();
buggy_map.insert(42, &*~1); //~ ERROR borrowed value does not live long enough
buggy_map.insert(42, &*box 1); //~ ERROR borrowed value does not live long enough
// but it is ok if we use a temporary
let tmp = ~2;
let tmp = box 2;
buggy_map.insert(43, &*tmp);
}

View file

@ -11,6 +11,7 @@
// Tests that two closures cannot simultaneously have mutable
// and immutable access to the variable. Issue #6801.
fn get(x: &int) -> int {
*x
}
@ -50,27 +51,27 @@ fn e() {
}
fn f() {
let mut x = ~3;
let mut x = box 3;
let c1 = || get(&*x);
*x = 5; //~ ERROR cannot assign
}
fn g() {
struct Foo {
f: ~int
f: Box<int>
}
let mut x = ~Foo { f: ~3 };
let mut x = box Foo { f: box 3 };
let c1 = || get(&*x.f);
*x.f = 5; //~ ERROR cannot assign to `*x.f`
}
fn h() {
struct Foo {
f: ~int
f: Box<int>
}
let mut x = ~Foo { f: ~3 };
let mut x = box Foo { f: box 3 };
let c1 = || get(&*x.f);
let c2 = || *x.f = 5; //~ ERROR cannot borrow `x` as mutable
}

View file

@ -12,6 +12,7 @@
// access to the variable, whether that mutable access be used
// for direct assignment or for taking mutable ref. Issue #6801.
fn a() {
let mut x = 3;
let c1 = || x = 4;
@ -43,10 +44,10 @@ fn d() {
fn g() {
struct Foo {
f: ~int
f: Box<int>
}
let mut x = ~Foo { f: ~3 };
let mut x = box Foo { f: box 3 };
let c1 = || set(&mut *x.f);
let c2 = || set(&mut *x.f);
//~^ ERROR cannot borrow `x` as mutable more than once

View file

@ -12,6 +12,7 @@
// cannot also be supplied a borrowed version of that
// variable's contents. Issue #11192.
struct Foo {
x: int
}
@ -23,9 +24,9 @@ impl Drop for Foo {
}
fn main() {
let mut ptr = ~Foo { x: 0 };
let mut ptr = box Foo { x: 0 };
let test = |foo: &Foo| {
ptr = ~Foo { x: ptr.x + 1 };
ptr = box Foo { x: ptr.x + 1 };
};
test(ptr); //~ ERROR cannot borrow `*ptr`
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
let x = Some(~1);
let x = Some(box 1);
match x {
Some(ref _y) => {
let _a = x; //~ ERROR cannot move

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
let x = Some(~1);
let x = Some(box 1);
match x {
Some(ref y) => {
let _b = *y; //~ ERROR cannot move out

View file

@ -14,21 +14,22 @@
// either genuine or would require more advanced changes. The latter
// cases are noted.
fn borrow(_v: &int) {}
fn borrow_mut(_v: &mut int) {}
fn cond() -> bool { fail!() }
fn for_func(_f: || -> bool) { fail!() }
fn produce<T>() -> T { fail!(); }
fn inc(v: &mut ~int) {
*v = ~(**v + 1);
fn inc(v: &mut Box<int>) {
*v = box() (**v + 1);
}
fn pre_freeze_cond() {
// In this instance, the freeze is conditional and starts before
// the mut borrow.
let mut v = ~3;
let mut v = box 3;
let _w;
if cond() {
_w = &v;
@ -40,7 +41,7 @@ fn pre_freeze_else() {
// In this instance, the freeze and mut borrow are on separate sides
// of the if.
let mut v = ~3;
let mut v = box 3;
let _w;
if cond() {
_w = &v;

View file

@ -14,19 +14,20 @@
// either genuine or would require more advanced changes. The latter
// cases are noted.
fn borrow(_v: &int) {}
fn borrow_mut(_v: &mut int) {}
fn cond() -> bool { fail!() }
fn produce<T>() -> T { fail!(); }
fn inc(v: &mut ~int) {
*v = ~(**v + 1);
fn inc(v: &mut Box<int>) {
*v = box() (**v + 1);
}
fn loop_overarching_alias_mut() {
// In this instance, the borrow encompasses the entire loop.
let mut v = ~3;
let mut v = box 3;
let mut x = &mut v;
**x += 1;
loop {
@ -37,19 +38,19 @@ fn loop_overarching_alias_mut() {
fn block_overarching_alias_mut() {
// In this instance, the borrow encompasses the entire closure call.
let mut v = ~3;
let mut v = box 3;
let mut x = &mut v;
for _ in range(0, 3) {
borrow(v); //~ ERROR cannot borrow
}
*x = ~5;
*x = box 5;
}
fn loop_aliased_mut() {
// In this instance, the borrow is carried through the loop.
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let mut _x = &w;
loop {
borrow_mut(v); //~ ERROR cannot borrow
@ -60,8 +61,8 @@ fn loop_aliased_mut() {
fn while_aliased_mut() {
// In this instance, the borrow is carried through the loop.
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let mut _x = &w;
while cond() {
borrow_mut(v); //~ ERROR cannot borrow
@ -73,8 +74,8 @@ fn while_aliased_mut() {
fn loop_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let mut _x = &w;
loop {
borrow_mut(v);
@ -87,8 +88,8 @@ fn loop_aliased_mut_break() {
fn while_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let mut _x = &w;
while cond() {
borrow_mut(v);
@ -99,8 +100,8 @@ fn while_aliased_mut_break() {
}
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let mut x = &mut w;
while cond {
**x += 1;

View file

@ -37,24 +37,24 @@ fn guard() {
// Here the guard performs a borrow. This borrow "infects" all
// subsequent arms (but not the prior ones).
let mut a = ~3;
let mut b = ~4;
let mut a = box 3;
let mut b = box 4;
let mut w = &*a;
match 22 {
_ if cond() => {
b = ~5;
b = box 5;
}
_ if link(&*b, &mut w) => {
b = ~6; //~ ERROR cannot assign
b = box 6; //~ ERROR cannot assign
}
_ => {
b = ~7; //~ ERROR cannot assign
b = box 7; //~ ERROR cannot assign
}
}
b = ~8; //~ ERROR cannot assign
b = box 8; //~ ERROR cannot assign
}
fn main() {}

View file

@ -14,20 +14,21 @@
// either genuine or would require more advanced changes. The latter
// cases are noted.
fn borrow(_v: &int) {}
fn borrow_mut(_v: &mut int) {}
fn cond() -> bool { fail!() }
fn for_func(_f: || -> bool) { fail!() }
fn produce<T>() -> T { fail!(); }
fn inc(v: &mut ~int) {
*v = ~(**v + 1);
fn inc(v: &mut Box<int>) {
*v = box() (**v + 1);
}
fn pre_freeze() {
// In this instance, the freeze starts before the mut borrow.
let mut v = ~3;
let mut v = box 3;
let _w = &v;
borrow_mut(v); //~ ERROR cannot borrow
}
@ -35,7 +36,7 @@ fn pre_freeze() {
fn post_freeze() {
// In this instance, the const alias starts after the borrow.
let mut v = ~3;
let mut v = box 3;
borrow_mut(v);
let _w = &v;
}

View file

@ -15,7 +15,7 @@ fn borrow(v: &int, f: |x: &int|) {
}
fn box_imm() {
let v = ~3;
let v = box 3;
let _w = &v;
task::spawn(proc() {
println!("v={}", *v);
@ -24,7 +24,7 @@ fn box_imm() {
}
fn box_imm_explicit() {
let v = ~3;
let v = box 3;
let _w = &v;
task::spawn(proc() {
println!("v={}", *v);

View file

@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn take(_v: ~int) {
fn take(_v: Box<int>) {
}
fn box_imm() {
let v = ~3;
let v = box 3;
let _w = &v;
take(v); //~ ERROR cannot move out of `v` because it is borrowed
}

View file

@ -13,10 +13,10 @@ fn borrow(v: &int, f: |x: &int|) {
}
fn box_imm() {
let mut v = ~3;
let mut v = box 3;
borrow(v,
|w| { //~ ERROR cannot borrow `v` as mutable
v = ~4;
v = box 4;
assert_eq!(*v, 3);
assert_eq!(*w, 4);
})

View file

@ -8,18 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct foo(~uint);
struct foo(Box<uint>);
impl Add<foo, foo> for foo {
fn add(&self, f: &foo) -> foo {
let foo(~i) = *self;
let foo(~j) = *f;
foo(~(i + j))
let foo(box i) = *self;
let foo(box j) = *f;
foo(box() (i + j))
}
}
fn main() {
let x = foo(~3);
let x = foo(box 3);
let _y = x + {x}; // the `{x}` forces a move to occur
//~^ ERROR cannot move out of `x`
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
pub fn main() {
let bar = ~3;
let bar = box 3;
let _g = || {
let _h: proc() -> int = proc() *bar; //~ ERROR cannot move out of captured outer variable
};

View file

@ -8,14 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo {
Foo1(~u32, ~u32),
Foo2(~u32),
Foo1(Box<u32>, Box<u32>),
Foo2(Box<u32>),
Foo3,
}
fn blah() {
let f = &Foo1(~1u32, ~2u32);
let f = &Foo1(box 1u32, box 2u32);
match *f { //~ ERROR cannot move out of
Foo1(num1, //~ NOTE attempting to move value to here
num2) => (), //~ NOTE and here
@ -24,7 +25,10 @@ fn blah() {
}
}
struct S {f:~str, g:~str}
struct S {
f: ~str,
g: ~str
}
impl Drop for S {
fn drop(&mut self) { println!("{}", self.f); }
}
@ -40,13 +44,13 @@ fn move_in_match() {
// from issue-8064
struct A {
a: ~int
a: Box<int>,
}
fn free<T>(_: T) {}
fn blah2() {
let a = &A { a: ~1 };
let a = &A { a: box 1 };
match a.a { //~ ERROR cannot move out of
n => { //~ NOTE attempting to move value to here
free(n)

View file

@ -12,7 +12,7 @@
// borrowed path.
fn main() {
let a = ~~2;
let a = box box 2;
let b = &a;
let z = *a; //~ ERROR: cannot move out of `*a` because it is borrowed

View file

@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(x: *~int) -> ~int {
fn foo(x: *Box<int>) -> Box<int> {
let y = *x; //~ ERROR dereference of unsafe pointer requires unsafe function or block
return y;
}

View file

@ -13,7 +13,7 @@ fn call_f(f: proc() -> int) -> int {
}
fn main() {
let t = ~3;
let t = box 3;
call_f(proc() { *t + 1 });
call_f(proc() { *t + 1 }); //~ ERROR capture of moved value

View file

@ -11,19 +11,15 @@
// Tests that the borrow checker checks all components of a path when moving
// out.
#![no_std]
#[lang="sized"]
pub trait Sized {}
struct S {
x : ~int
x : Box<int>
}
fn f<T>(_: T) {}
fn main() {
let a : S = S { x : ~1 };
let a : S = S { x : box 1 };
let pb = &a;
let S { x: ax } = a; //~ ERROR cannot move out
f(pb);

View file

@ -8,8 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct node_ {
a: ~cycle
a: Box<cycle>
}
enum cycle {
@ -17,7 +18,7 @@ enum cycle {
empty
}
fn main() {
let mut x = ~node(node_ {a: ~empty});
let mut x = box node(node_ {a: box empty});
// Create a cycle!
match *x {
node(ref mut y) => {

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
fn borrowed<'a>(&'a self) -> &'a ();
}
@ -16,16 +17,16 @@ fn borrowed_receiver<'a>(x: &'a Foo) -> &'a () {
x.borrowed()
}
fn owned_receiver(x: ~Foo) -> &() {
fn owned_receiver(x: Box<Foo>) -> &() {
x.borrowed() //~ ERROR `*x` does not live long enough
}
fn mut_owned_receiver(mut x: ~Foo) {
fn mut_owned_receiver(mut x: Box<Foo>) {
let _y = x.borrowed();
let _z = &mut x; //~ ERROR cannot borrow
}
fn imm_owned_receiver(mut x: ~Foo) {
fn imm_owned_receiver(mut x: Box<Foo>) {
let _y = x.borrowed();
let _z = &x;
}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
fn borrowed(&self);
fn borrowed_mut(&mut self);
@ -23,12 +24,12 @@ fn borrowed_mut_receiver(x: &mut Foo) {
x.borrowed_mut();
}
fn owned_receiver(x: ~Foo) {
fn owned_receiver(x: Box<Foo>) {
x.borrowed();
x.borrowed_mut(); //~ ERROR cannot borrow
}
fn mut_owned_receiver(mut x: ~Foo) {
fn mut_owned_receiver(mut x: Box<Foo>) {
x.borrowed();
x.borrowed_mut();
}

View file

@ -14,6 +14,7 @@
#![feature(managed_boxes)]
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
@ -21,16 +22,16 @@ fn borrow(x: &int, f: |x: &int|) {
assert_eq!(before, after);
}
struct F { f: ~int }
struct F { f: Box<int> }
pub fn main() {
let mut x = @F {f: ~3};
let mut x = @F {f: box 3};
borrow(x.f, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
//~^ NOTE borrow occurs due to use of `x` in closure
x = @F {f: ~4};
x = @F {f: box 4};
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);

View file

@ -14,6 +14,7 @@
#![feature(managed_boxes)]
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
@ -21,16 +22,16 @@ fn borrow(x: &int, f: |x: &int|) {
assert_eq!(before, after);
}
struct F { f: ~int }
struct F { f: Box<int> }
pub fn main() {
let mut x = ~@F{f: ~3};
let mut x = box @F{f: box 3};
borrow(x.f, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
//~^ NOTE borrow occurs due to use of `x` in closure
*x = @F{f: ~4};
*x = @F{f: box 4};
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);

View file

@ -14,6 +14,7 @@
#![feature(managed_boxes)]
fn borrow(x: &int, f: |x: &int|) {
let before = *x;
f(x);
@ -21,16 +22,16 @@ fn borrow(x: &int, f: |x: &int|) {
assert_eq!(before, after);
}
struct F { f: ~int }
struct F { f: Box<int> }
pub fn main() {
let mut x = @F {f: ~3};
let mut x = @F {f: box 3};
borrow((*x).f, |b_x| {
//~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
assert_eq!(*b_x, 3);
assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
//~^ NOTE borrow occurs due to use of `x` in closure
x = @F {f: ~4};
x = @F {f: box 4};
println!("&*b_x = {:p}", &(*b_x));
assert_eq!(*b_x, 3);

View file

@ -13,10 +13,12 @@
// NoCopy
use NP = std::kinds::marker::NoCopy;
struct S { a: int, np: NP }
impl Drop for S { fn drop(&mut self) { } }
struct T { a: int, mv: ~int }
struct T { a: int, mv: Box<int> }
impl Drop for T { fn drop(&mut self) { } }
fn f(s0:S) {

View file

@ -8,13 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(x: ~int) -> int {
fn foo(x: Box<int>) -> int {
let y = &*x;
free(x); //~ ERROR cannot move out of `x` because it is borrowed
*y
}
fn free(_x: ~int) {
fn free(_x: Box<int>) {
}
fn main() {

View file

@ -8,49 +8,50 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn borrow(_v: &int) {}
fn local() {
let mut v = ~3;
let mut v = box 3;
borrow(v);
}
fn local_rec() {
struct F { f: ~int }
let mut v = F {f: ~3};
struct F { f: Box<int> }
let mut v = F {f: box 3};
borrow(v.f);
}
fn local_recs() {
struct F { f: G }
struct G { g: H }
struct H { h: ~int }
let mut v = F {f: G {g: H {h: ~3}}};
struct H { h: Box<int> }
let mut v = F {f: G {g: H {h: box 3}}};
borrow(v.f.g.h);
}
fn aliased_imm() {
let mut v = ~3;
let mut v = box 3;
let _w = &v;
borrow(v);
}
fn aliased_mut() {
let mut v = ~3;
let mut v = box 3;
let _w = &mut v;
borrow(v); //~ ERROR cannot borrow `*v`
}
fn aliased_other() {
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let _x = &mut w;
borrow(v);
}
fn aliased_other_reassign() {
let mut v = ~3;
let mut w = ~4;
let mut v = box 3;
let mut w = box 4;
let mut _x = &mut w;
_x = &mut v;
borrow(v); //~ ERROR cannot borrow `*v`

View file

@ -8,28 +8,29 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn a() {
let mut vec = [~1, ~2, ~3];
let mut vec = [box 1, box 2, box 3];
match vec {
[~ref _a, _, _] => {
vec[0] = ~4; //~ ERROR cannot assign
[box ref _a, _, _] => {
vec[0] = box 4; //~ ERROR cannot assign
}
}
}
fn b() {
let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec.as_mut_slice();
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<int>] = vec.as_mut_slice();
match vec {
[.._b] => {
vec[0] = ~4; //~ ERROR cannot assign
vec[0] = box 4; //~ ERROR cannot assign
}
}
}
fn c() {
let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec.as_mut_slice();
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<int>] = vec.as_mut_slice();
match vec {
[_a, //~ ERROR cannot move out
.._b] => { //~^ NOTE attempting to move value to here
@ -46,8 +47,8 @@ fn c() {
}
fn d() {
let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec.as_mut_slice();
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<int>] = vec.as_mut_slice();
match vec {
[.._a, //~ ERROR cannot move out
_b] => {} //~ NOTE attempting to move value to here
@ -57,8 +58,8 @@ fn d() {
}
fn e() {
let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec.as_mut_slice();
let mut vec = vec!(box 1, box 2, box 3);
let vec: &mut [Box<int>] = vec.as_mut_slice();
match vec {
[_a, _b, _c] => {} //~ ERROR cannot move out
//~^ NOTE attempting to move value to here

View file

@ -94,7 +94,7 @@ static STATIC10: UnsafeStruct = UnsafeStruct;
struct MyOwned;
static STATIC11: ~MyOwned = ~MyOwned;
static STATIC11: Box<MyOwned> = box MyOwned;
//~^ ERROR static items are not allowed to have owned pointers
// The following examples test that mutable structs are just forbidden
@ -109,11 +109,12 @@ static mut STATIC13: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(
static mut STATIC14: SafeStruct = SafeStruct{field1: Variant1, field2: Variant4("str".to_owned())};
//~^ ERROR mutable static items are not allowed to have destructors
static STATIC15: &'static [~MyOwned] = &'static [~MyOwned, ~MyOwned];
static STATIC15: &'static [Box<MyOwned>] = &'static [box MyOwned, box MyOwned];
//~^ ERROR static items are not allowed to have owned pointers
//~^^ ERROR static items are not allowed to have owned pointers
static STATIC16: (&'static ~MyOwned, &'static ~MyOwned) = (&'static ~MyOwned, &'static ~MyOwned);
static STATIC16: (&'static Box<MyOwned>, &'static Box<MyOwned>) =
(&'static box MyOwned, &'static box MyOwned);
//~^ ERROR static items are not allowed to have owned pointers
//~^^ ERROR static items are not allowed to have owned pointers
@ -123,10 +124,10 @@ static mut STATIC17: SafeEnum = Variant1;
static STATIC18: @SafeStruct = @SafeStruct{field1: Variant1, field2: Variant2(0)};
//~^ ERROR static items are not allowed to have managed pointers
static STATIC19: ~int = box 3;
static STATIC19: Box<int> = box 3;
//~^ ERROR static items are not allowed to have owned pointers
pub fn main() {
let y = { static x: ~int = ~3; x };
let y = { static x: Box<int> = box 3; x };
//~^ ERROR static items are not allowed to have owned pointers
}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait noisy {
fn speak(&self);
}
@ -57,6 +58,6 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
}
fn main() {
let nyan: ~noisy = ~cat(0, 2, "nyan".to_owned()) as ~noisy;
let nyan: Box<noisy> = box cat(0, 2, "nyan".to_owned()) as Box<noisy>;
nyan.eat(); //~ ERROR does not implement any method in scope named `eat`
}

View file

@ -17,7 +17,7 @@ fn has_uniq(x: ~str) {
}
fn has_slice(x: &str) {
wants_uniq(x); //~ ERROR mismatched types: expected `~str` but found `&str` (expected ~-ptr but f
wants_uniq(x); //~ ERROR mismatched types: expected `~str` but found `&str` (expected box but f
wants_slice(x);
}

View file

@ -8,12 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f(y: ~int) {
fn f(y: Box<int>) {
*y = 5; //~ ERROR cannot assign
}
fn g() {
let _frob: |~int| = |q| { *q = 2; }; //~ ERROR cannot assign
let _frob: |Box<int>| = |q| { *q = 2; }; //~ ERROR cannot assign
}

View file

@ -23,7 +23,7 @@ impl Deref<Foo> for Foo {
pub fn main() {
let mut x;
loop {
x = ~x;
x = box x;
x.foo;
x.bar();
}

View file

@ -11,7 +11,8 @@
// Test struct inheritance.
#![feature(struct_inherit)]
struct S6 : ~S2; //~ ERROR not a struct
struct S6 : int; //~ ERROR super-struct could not be resolved
pub fn main() {
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
let x = ~1;
let x = box 1;
let f: proc() = proc() {
let _a = x;
drop(x);

View file

@ -19,10 +19,10 @@ impl Drop for Foo {
}
fn main() {
let mut ptr = ~Foo { x: 0 };
let mut ptr = box Foo { x: 0 };
let test = |foo: &Foo| {
println!("access {}", foo.x);
ptr = ~Foo { x: ptr.x + 1 };
ptr = box Foo { x: ptr.x + 1 };
println!("access {}", foo.x);
};
test(ptr);

View file

@ -13,6 +13,6 @@ struct Test<'s> {
}
fn main() {
let test = ~Test { func: proc() {} };
let test = box Test { func: proc() {} };
//~^ ERROR: expected `||` but found `proc()`
}

View file

@ -10,7 +10,7 @@
fn main() {
let r = {
let x = ~42;
let x = box 42;
let f = proc() &x; //~ ERROR: `x` does not live long enough
f()
};

View file

@ -11,7 +11,9 @@
// test that autoderef of a type like this does not
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
struct t(~t); //~ ERROR this type cannot be instantiated
struct t(Box<t>); //~ ERROR this type cannot be instantiated
trait to_str_2 {
fn my_to_str() -> ~str;

View file

@ -8,12 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct HTMLImageData {
image: Option<~str>
}
struct ElementData {
kind: ~ElementKind
kind: Box<ElementKind>
}
enum ElementKind {
@ -25,17 +26,17 @@ enum NodeKind {
}
struct NodeData {
kind: ~NodeKind
kind: Box<NodeKind>,
}
fn main() {
let mut id = HTMLImageData { image: None };
let ed = ElementData { kind: ~HTMLImageElement(id) };
let n = NodeData {kind : ~Element(ed)};
let ed = ElementData { kind: box HTMLImageElement(id) };
let n = NodeData {kind : box Element(ed)};
// n.b. span could be better
match n.kind {
~Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns
~HTMLImageElement(ref d) if d.image.is_some() => { true }
box Element(ed) => match ed.kind { //~ ERROR non-exhaustive patterns
box HTMLImageElement(ref d) if d.image.is_some() => { true }
},
_ => fail!("WAT") //~ ERROR unreachable pattern
};

View file

@ -26,12 +26,12 @@ fn main() {
let my_struct = my_mod::MyStruct();
let _woohoo = (&my_struct).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
let _woohoo = (~my_struct).priv_field;
let _woohoo = (box my_struct).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
let _woohoo = (@my_struct).priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private
(&my_struct).happyfun(); //~ ERROR method `happyfun` is private
(~my_struct).happyfun(); //~ ERROR method `happyfun` is private
(box my_struct).happyfun(); //~ ERROR method `happyfun` is private
(@my_struct).happyfun(); //~ ERROR method `happyfun` is private
let nope = my_struct.priv_field;
//~^ ERROR field `priv_field` of struct `my_mod::MyStruct` is private

View file

@ -8,15 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait MyTrait { }
pub enum TraitWrapper {
A(~MyTrait),
A(Box<MyTrait>),
}
fn get_tw_map<'lt>(tw: &'lt TraitWrapper) -> &'lt MyTrait {
match *tw {
A(~ref map) => map, //~ ERROR found a `~`-box pattern
A(box ref map) => map, //~ ERROR found a box pattern
}
}

View file

@ -23,8 +23,8 @@ fn main() {
}
match (true, false) {
~(true, false) => ()
//~^ ERROR mismatched types: expected `(bool,bool)` but found a `~`-box pattern
box (true, false) => ()
//~^ ERROR mismatched types: expected `(bool,bool)` but found a box pattern
}
match (true, false) {

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo {
foo: int,
}
@ -17,8 +18,8 @@ struct Bar {
}
impl Bar {
fn make_foo (&self, i: int) -> ~Foo {
return ~Foo { nonexistent: self, foo: i }; //~ ERROR: no field named
fn make_foo (&self, i: int) -> Box<Foo> {
return box Foo { nonexistent: self, foo: i }; //~ ERROR: no field named
}
}

View file

@ -12,7 +12,8 @@
// transferring ownership of the owned box before invoking the stack
// closure results in a crash.
fn twice(x: ~uint) -> uint {
fn twice(x: Box<uint>) -> uint {
*x * 2
}
@ -21,7 +22,7 @@ fn invoke(f: || -> uint) {
}
fn main() {
let x : ~uint = ~9;
let x : Box<uint> = box 9;
let sq : || -> uint = || { *x * *x };
twice(x); //~ ERROR: cannot move out of

View file

@ -8,35 +8,30 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;
trait Foo
{
trait Foo {
fn set(&mut self, v: Rc<RefCell<A>>);
}
struct B
{
struct B {
v: Option<Rc<RefCell<A>>>
}
impl Foo for B
{
impl Foo for B {
fn set(&mut self, v: Rc<RefCell<A>>)
{
self.v = Some(v);
}
}
struct A
{
v: ~Foo:Send,
struct A {
v: Box<Foo:Send>,
}
fn main()
{
let a = A {v: ~B{v: None} as ~Foo:Send};
fn main() {
let a = A {v: box B{v: None} as Box<Foo:Send>};
//~^ ERROR cannot pack type `~B`, which does not fulfill `Send`
let v = Rc::new(RefCell::new(a));
let w = v.clone();

View file

@ -11,7 +11,8 @@
// Verify the compiler fails with an error on infinite function
// recursions.
struct Data(~Option<Data>);
struct Data(Box<Option<Data>>);
fn generic<T>( _ : Vec<(Data,T)> ) {
//~^ ERROR reached the recursion limit during monomorphization

View file

@ -23,7 +23,7 @@ struct MyStruct {
}
struct MyNoncopyStruct {
x: ~int,
x: Box<int>,
}
fn test<'a,T,U:Copy>(_: &'a int) {
@ -38,10 +38,10 @@ fn test<'a,T,U:Copy>(_: &'a int) {
assert_copy::<&'a mut int>(); //~ ERROR does not fulfill
// ~ pointers are not ok
assert_copy::<~int>(); //~ ERROR does not fulfill
assert_copy::<Box<int>>(); //~ ERROR does not fulfill
assert_copy::<~str>(); //~ ERROR does not fulfill
assert_copy::<Vec<int> >(); //~ ERROR does not fulfill
assert_copy::<~&'a mut int>(); //~ ERROR does not fulfill
assert_copy::<Box<&'a mut int>>(); //~ ERROR does not fulfill
// borrowed object types are generally ok
assert_copy::<&'a Dummy>();
@ -49,8 +49,8 @@ fn test<'a,T,U:Copy>(_: &'a int) {
assert_copy::<&'static Dummy:Copy>();
// owned object types are not ok
assert_copy::<~Dummy>(); //~ ERROR does not fulfill
assert_copy::<~Dummy:Copy>(); //~ ERROR does not fulfill
assert_copy::<Box<Dummy>>(); //~ ERROR does not fulfill
assert_copy::<Box<Dummy:Copy>>(); //~ ERROR does not fulfill
// mutable object types are not ok
assert_copy::<&'a mut Dummy:Copy>(); //~ ERROR does not fulfill

View file

@ -8,14 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Repeat<A> { fn get(&self) -> A; }
impl<A:Clone> Repeat<A> for A {
fn get(&self) -> A { self.clone() }
}
fn repeater<A:Clone>(v: A) -> ~Repeat<A>: {
~v as ~Repeat<A>: // No
fn repeater<A:Clone>(v: A) -> Box<Repeat<A>:> {
box v as Box<Repeat<A>:> // No
}
fn main() {

View file

@ -28,28 +28,28 @@ fn test<'a,T,U:Send>(_: &'a int) {
assert_send::<&'a str>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a [int]>(); //~ ERROR does not fulfill `Send`
// ~ pointers are ok
assert_send::<~int>();
// boxes are ok
assert_send::<Box<int>>();
assert_send::<~str>();
assert_send::<Vec<int> >();
// but not if they own a bad thing
assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send`
assert_send::<Box<&'a int>>(); //~ ERROR does not fulfill `Send`
// careful with object types, who knows what they close over...
assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a Dummy:Send>(); //~ ERROR does not fulfill `Send`
assert_send::<~Dummy:>(); //~ ERROR does not fulfill `Send`
assert_send::<Box<Dummy:>>(); //~ ERROR does not fulfill `Send`
// ...unless they are properly bounded
assert_send::<&'static Dummy:Send>();
assert_send::<~Dummy:Send>();
assert_send::<Box<Dummy:Send>>();
// but closure and object types can have lifetime bounds which make
// them not ok (FIXME #5121)
// assert_send::<proc:'a()>(); // ERROR does not fulfill `Send`
// assert_send::<~Dummy:'a>(); // ERROR does not fulfill `Send`
// assert_send::<Box<Dummy:'a>>(); // ERROR does not fulfill `Send`
// unsafe ptrs are ok unless they point at unsendable things
assert_send::<*int>();

View file

@ -14,6 +14,6 @@ fn f(_: &int) {}
fn g(_: &mut int) {}
fn main() {
f(~1); //~ ERROR unnecessary allocation, use & instead
g(~1); //~ ERROR unnecessary allocation, use &mut instead
f(box 1); //~ ERROR unnecessary allocation, use & instead
g(box 1); //~ ERROR unnecessary allocation, use &mut instead
}

View file

@ -36,7 +36,7 @@ pub static used_static2: int = used_static;
static USED_STATIC: int = 0;
static STATIC_USED_IN_ENUM_DISCRIMINANT: uint = 10;
pub type typ = ~UsedStruct4;
pub type typ = *UsedStruct4;
pub struct PubStruct();
struct PrivStruct; //~ ERROR: code is never used
struct UsedStruct1 { x: int }
@ -57,7 +57,7 @@ pub struct PubStruct2 {
}
pub enum pub_enum { foo1, bar1 }
pub enum pub_enum2 { a(~StructUsedInEnum) }
pub enum pub_enum2 { a(*StructUsedInEnum) }
pub enum pub_enum3 { Foo = STATIC_USED_IN_ENUM_DISCRIMINANT }
enum priv_enum { foo2, bar2 } //~ ERROR: code is never used
enum used_enum { foo3, bar3 }

View file

@ -13,19 +13,20 @@
#![allow(dead_code)]
#![allow(deprecated_owned_vector)]
struct Foo {
x: @int //~ ERROR type uses managed
}
struct Bar { x: ~int } //~ ERROR type uses owned
struct Bar { x: Box<int> } //~ ERROR type uses owned
fn main() {
let _x : Bar = Bar {x : ~10}; //~ ERROR type uses owned
let _x : Bar = Bar {x : box 10}; //~ ERROR type uses owned
@2; //~ ERROR type uses managed
~2; //~ ERROR type uses owned
fn g(_: ~Clone) {} //~ ERROR type uses owned
box 2; //~ ERROR type uses owned
fn g(_: Box<Clone>) {} //~ ERROR type uses owned
"".to_owned(); //~ ERROR type uses owned
proc() {}; //~ ERROR type uses owned
}

View file

@ -10,11 +10,12 @@
#![forbid(owned_heap_memory)]
struct Foo {
x: ~int //~ ERROR type uses owned
x: Box<int> //~ ERROR type uses owned
}
fn main() {
let _x : Foo = Foo {x : ~10};
let _x : Foo = Foo {x : box 10};
//~^ ERROR type uses owned
}

View file

@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn take(_x: ~int) {}
fn take(_x: Box<int>) {}
fn main() {
let x: ~int = ~25;
let x: Box<int> = box 25;
loop {
take(x); //~ ERROR use of moved value: `x`
}

View file

@ -8,9 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let y: ~int = ~42;
let mut x: ~int;
let y: Box<int> = box 42;
let mut x: Box<int>;
loop {
println!("{:?}", y);
loop {

View file

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let y: ~int = ~42;
let mut x: ~int;
fn main() {
let y: Box<int> = box 42;
let mut x: Box<int>;
loop {
println!("{:?}", y); //~ ERROR use of moved value: `y`
while true { while true { while true { x = y; x.clone(); } } }

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
let x = ~5;
let x = box 5;
let y = x;
println!("{:?}", *x); //~ ERROR use of moved value: `x`
y.clone();

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn send<T:Send>(ch: _chan<T>, data: T) {
println!("{:?}", ch);
println!("{:?}", data);
@ -18,7 +19,7 @@ struct _chan<T>(int);
// Tests that "log(debug, message);" is flagged as using
// message after the send deinitializes it
fn test00_start(ch: _chan<~int>, message: ~int, _count: ~int) {
fn test00_start(ch: _chan<Box<int>>, message: Box<int>, _count: Box<int>) {
send(ch, message);
println!("{:?}", message); //~ ERROR use of moved value: `message`
}

View file

@ -15,9 +15,9 @@ use collections::HashMap;
// Test that trait types printed in error msgs include the type arguments.
fn main() {
let x: ~HashMap<~str, ~str> = ~HashMap::new();
let x: ~Map<~str, ~str> = x;
let y: ~Map<uint, ~str> = ~x;
let x: Box<HashMap<~str, ~str>> = box HashMap::new();
let x: Box<Map<~str, ~str>> = x;
let y: Box<Map<uint, ~str>> = box x;
//~^ ERROR failed to find an implementation of trait std::container::Map<uint,~str>
// for ~std::container::Map<~str,~str>:Send
}

View file

@ -8,13 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S {
x: ~E
x: Box<E>
}
enum E {
Foo(~S),
Bar(~int),
Foo(Box<S>),
Bar(Box<int>),
Baz
}
@ -23,13 +24,13 @@ fn f(s: &S, g: |&S|) {
}
fn main() {
let s = S { x: ~Bar(~42) };
let s = S { x: box Bar(box 42) };
loop {
f(&s, |hellothere| {
match hellothere.x { //~ ERROR cannot move out
~Foo(_) => {}
~Bar(x) => println!("{}", x.to_str()), //~ NOTE attempting to move value to here
~Baz => {}
box Foo(_) => {}
box Bar(x) => println!("{}", x.to_str()), //~ NOTE attempting to move value to here
box Baz => {}
}
})
}

View file

@ -12,9 +12,10 @@
// temporary kinds wound up being stored in a cache and used later.
// See middle::ty::type_contents() for more information.
struct List { key: int, next: Option<~List> }
fn foo(node: ~List) -> int {
struct List { key: int, next: Option<Box<List>> }
fn foo(node: Box<List>) -> int {
let r = match node.next {
Some(right) => consume(right),
None => 0
@ -22,7 +23,7 @@ fn foo(node: ~List) -> int {
consume(node) + r //~ ERROR use of partially moved value: `node`
}
fn consume(v: ~List) -> int {
fn consume(v: Box<List>) -> int {
v.key
}

View file

@ -10,9 +10,9 @@
use std::uint;
fn test(_x: ~uint) {}
fn test(_x: Box<uint>) {}
fn main() {
let i = ~3;
let i = box 3;
let _f = || test(i); //~ ERROR cannot move out
}

View file

@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn dup(x: ~int) -> ~(~int,~int) { ~(x, x) } //~ ERROR use of moved value
fn dup(x: Box<int>) -> Box<(Box<int>,Box<int>)> { box() (x, x) } //~ ERROR use of moved value
fn main() {
dup(~3);
dup(box 3);
}

View file

@ -8,18 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type Noncopyable = proc();
struct Foo {
copied: int,
moved: ~int,
moved: Box<int>,
noncopyable: Noncopyable
}
fn test0(f: Foo, g: Noncopyable, h: Noncopyable) {
// just copy implicitly copyable fields from `f`, no moves:
let _b = Foo {moved: ~1, noncopyable: g, ..f};
let _c = Foo {moved: ~2, noncopyable: h, ..f};
let _b = Foo {moved: box 1, noncopyable: g, ..f};
let _c = Foo {moved: box 2, noncopyable: h, ..f};
}
fn test1(f: Foo, g: Noncopyable, h: Noncopyable) {
@ -30,7 +31,7 @@ fn test1(f: Foo, g: Noncopyable, h: Noncopyable) {
fn test2(f: Foo, g: Noncopyable) {
// move non-copyable field
let _b = Foo {copied: 22, moved: ~23, ..f};
let _b = Foo {copied: 22, moved: box 23, ..f};
let _c = Foo {noncopyable: g, ..f}; //~ ERROR use of partially moved value: `f`
}

View file

@ -14,11 +14,11 @@
// Tests that the new `box` syntax works with unique pointers and GC pointers.
use std::gc::Gc;
use std::owned::HEAP;
use std::owned::{Box, HEAP};
pub fn main() {
let x: Gc<int> = box(HEAP) 2; //~ ERROR mismatched types
let y: Gc<int> = box(HEAP)(1 + 2); //~ ERROR mismatched types
let z: ~int = box(GC)(4 + 5); //~ ERROR mismatched types
let z: Box<int> = box(GC)(4 + 5); //~ ERROR mismatched types
}

View file

@ -8,10 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that an object type `~Foo` is not considered to implement the
// Test that an object type `Box<Foo>` is not considered to implement the
// trait `Foo`. Issue #5087.
trait Foo {}
fn take_foo<F:Foo>(f: F) {}
fn take_object(f: ~Foo) { take_foo(f); } //~ ERROR failed to find an implementation of trait
fn take_object(f: Box<Foo>) { take_foo(f); } //~ ERROR failed to find an implementation of trait
fn main() {}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
fn borrowed(&self);
fn borrowed_mut(&mut self);
@ -27,7 +28,7 @@ fn borrowed_mut_receiver(x: &mut Foo) {
x.owned(); //~ ERROR does not implement any method
}
fn owned_receiver(x: ~Foo) {
fn owned_receiver(x: Box<Foo>) {
x.borrowed();
x.borrowed_mut(); // See [1]
x.managed(); //~ ERROR does not implement any method

View file

@ -8,22 +8,23 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait A<T> {}
struct B<'a, T>(&'a A<T>);
trait X {}
impl<'a, T> X for B<'a, T> {}
fn f<'a, T, U>(v: ~A<T>) -> ~X: {
~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `T`
fn f<'a, T, U>(v: Box<A<T>>) -> Box<X:> {
box B(v) as Box<X:> //~ ERROR value may contain references; add `'static` bound to `T`
}
fn g<'a, T, U>(v: ~A<U>) -> ~X: {
~B(v) as ~X: //~ ERROR value may contain references; add `'static` bound to `U`
fn g<'a, T, U>(v: Box<A<U>>) -> Box<X:> {
box B(v) as Box<X:> //~ ERROR value may contain references; add `'static` bound to `U`
}
fn h<'a, T: 'static>(v: ~A<T>) -> ~X: {
~B(v) as ~X: // ok
fn h<'a, T: 'static>(v: Box<A<T>>) -> Box<X:> {
box B(v) as Box<X:> // ok
}
fn main() {}

View file

@ -39,7 +39,7 @@ fn main() {
let i = @Cell::new(0);
{
// Can't do this copy
let x = ~~~A {y: r(i)};
let x = box box box A {y: r(i)};
let _z = x.clone(); //~ ERROR failed to find an implementation
println!("{:?}", x);
}

View file

@ -15,6 +15,7 @@
#![allow(dead_code)]
#![allow(unused_imports)]
// public type, private value
pub mod foo1 {
pub trait Bar {
@ -42,7 +43,7 @@ pub mod foo2 {
fn test_glob2() {
use foo2::*;
let _x: ~Bar; //~ ERROR use of undeclared type name `Bar`
let _x: Box<Bar>; //~ ERROR use of undeclared type name `Bar`
}
// neither public
@ -58,7 +59,7 @@ fn test_glob3() {
use foo3::*;
Bar(); //~ ERROR unresolved name `Bar`.
let _x: ~Bar; //~ ERROR use of undeclared type name `Bar`
let _x: Box<Bar>; //~ ERROR use of undeclared type name `Bar`
}
fn main() {

View file

@ -15,6 +15,7 @@
#![allow(dead_code)]
#![allow(unused_imports)]
// public type, private value
pub mod foo1 {
pub trait Bar {
@ -49,13 +50,13 @@ pub mod foo2 {
fn test_single2() {
use foo2::Bar; //~ ERROR `Bar` is private
let _x : ~Bar;
let _x : Box<Bar>;
}
fn test_list2() {
use foo2::{Bar,Baz}; //~ ERROR `Bar` is private
let _x: ~Bar;
let _x: Box<Bar>;
}
// neither public
@ -76,14 +77,14 @@ fn test_single3() {
use foo3::Bar; //~ ERROR `Bar` is private
Bar();
let _x: ~Bar;
let _x: Box<Bar>;
}
fn test_list3() {
use foo3::{Bar,Baz}; //~ ERROR `Bar` is private
Bar();
let _x: ~Bar;
let _x: Box<Bar>;
}
fn main() {

View file

@ -8,9 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo { }
fn foo<'a>(x: ~Foo:'a) { //~ ERROR only the 'static lifetime is accepted here
fn foo<'a>(x: Box<Foo:'a>) { //~ ERROR only the 'static lifetime is accepted here
}
fn bar<'a, T:'a>() { //~ ERROR only the 'static lifetime is accepted here

View file

@ -8,14 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn arg_item(~ref x: ~int) -> &'static int {
fn arg_item(box ref x: Box<int>) -> &'static int {
x //~^ ERROR borrowed value does not live long enough
}
fn with<R>(f: |~int| -> R) -> R { f(~3) }
fn with<R>(f: |Box<int>| -> R) -> R { f(box 3) }
fn arg_closure() -> &'static int {
with(|~ref x| x) //~ ERROR borrowed value does not live long enough
with(|box ref x| x) //~ ERROR borrowed value does not live long enough
}
fn main() {}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct ctxt { v: uint }
trait get_ctxt {
@ -27,12 +28,12 @@ impl<'a> get_ctxt for has_ctxt<'a> {
}
fn get_v(gc: ~get_ctxt) -> uint {
fn get_v(gc: Box<get_ctxt>) -> uint {
gc.get_ctxt().v
}
fn main() {
let ctxt = ctxt { v: 22u };
let hc = has_ctxt { c: &ctxt };
assert_eq!(get_v(~hc as ~get_ctxt), 22u);
assert_eq!(get_v(box hc as Box<get_ctxt>), 22u);
}

View file

@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type closure = ~lt/fn(); //~ ERROR expected `;` but found `/`
type closure = Box<lt/fn()>; //~ ERROR expected `,` but found `/`

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn f() {
let a_box = ~mut 42;
let a_box = box mut 42;
//~^ ERROR found `mut` in ident position
//~^^ ERROR expected `;` but found `42`
}

View file

@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type mut_box = ~mut int;
type mut_box = Box<mut int>;
//~^ ERROR found `mut` in ident position
//~^^ ERROR expected `;` but found `int`
//~^^ ERROR expected `,` but found `int`

View file

@ -1,16 +0,0 @@
// Copyright 2013-2014 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.
struct S;
impl S {
fn f(~mut self) {} //~ ERROR found `self` in ident position
//~^ ERROR expected `:` but found `)`
}

View file

@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait add {
fn plus(&self, x: Self) -> Self;
}
fn do_add(x: ~add, y: ~add) -> ~add {
fn do_add(x: Box<add>, y: Box<add>) -> Box<add> {
x.plus(y) //~ ERROR cannot call a method whose type contains a self-type through an object
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
static mut a: ~int = ~3; //~ ERROR: mutable static items are not allowed to have owned pointers
static mut a: Box<int> = box 3;
//~^ ERROR mutable static items are not allowed to have owned pointers
fn main() {}

View file

@ -8,9 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct BuildData {
foo: int,
bar: ~int
bar: Box<int>,
}
fn main() {

View file

@ -8,17 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
}
fn a(_x: ~Foo:Send) {
fn a(_x: Box<Foo:Send>) {
}
fn c(x: ~Foo:Share+Send) {
fn c(x: Box<Foo:Share+Send>) {
a(x);
}
fn d(x: ~Foo:) {
fn d(x: Box<Foo:>) {
a(x); //~ ERROR found no bounds
}

View file

@ -8,8 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Foo;
fn foo(_x: ~Foo:Send) { } //~ ERROR kind bounds can only be used on trait types
fn foo(_x: Box<Foo:Send>) { } //~ ERROR kind bounds can only be used on trait types
fn main() { }

Some files were not shown because too many files have changed in this diff Show more