Skip to content

Commit

Permalink
test -- update tests with new error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 11, 2014
1 parent 1bd7b18 commit 3805c54
Show file tree
Hide file tree
Showing 49 changed files with 92 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/test/compile-fail/arc-rw-read-mode-shouldnt-escape.rs
Expand Up @@ -15,7 +15,7 @@ fn main() {
let mut y = None;
x.write_downgrade(|write_mode| {
y = Some(x.downgrade(write_mode));
//~^ ERROR cannot infer an appropriate lifetime
//~^ ERROR cannot infer
});
y.unwrap();
// Adding this line causes a method unification failure instead
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/borrowck-assign-comp-idx.rs
Expand Up @@ -32,9 +32,9 @@ fn b() {

let mut p = ~[1];

borrow(p, || {
p[0] = 5; //~ ERROR cannot assign to
});
borrow(
p,
|| p[0] = 5); //~ ERROR cannot borrow `p` as mutable
}

fn c() {
Expand Down
19 changes: 10 additions & 9 deletions src/test/compile-fail/borrowck-autoref-3261.rs
Expand Up @@ -21,13 +21,14 @@ impl X {

fn main() {
let mut x = X(Right(main));
(&mut x).with(|opt| {
match opt {
&Right(ref f) => {
x = X(Left((0,0))); //~ ERROR cannot assign to `x`
(*f)()
},
_ => fail!()
}
})
(&mut x).with(
|opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
match opt {
&Right(ref f) => {
x = X(Left((0,0)));
(*f)()
},
_ => fail!()
}
})
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-borrow-mut-object-twice.rs
Expand Up @@ -18,7 +18,7 @@ trait Foo {

fn test(x: &mut Foo) {
let _y = x.f1();
x.f2(); //~ ERROR cannot borrow `*x` because it is already borrowed as mutable
x.f2(); //~ ERROR cannot borrow `*x` as mutable
}

fn main() {}
7 changes: 4 additions & 3 deletions src/test/compile-fail/borrowck-insert-during-each.rs
Expand Up @@ -23,9 +23,10 @@ impl Foo {
}

fn bar(f: &mut Foo) {
f.foo(|a| {
f.n.insert(*a); //~ ERROR cannot borrow
})
f.foo(
|a| { //~ ERROR closure requires unique access to `f`
f.n.insert(*a);
})
}

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-loan-blocks-move-cc.rs
Expand Up @@ -21,7 +21,9 @@ fn box_imm() {
info!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
}

fn box_imm_explicit() {
let v = ~3;
let _w = &v;
task::spawn(proc() {
Expand Down
11 changes: 6 additions & 5 deletions src/test/compile-fail/borrowck-loan-blocks-mut-uniq.rs
Expand Up @@ -14,11 +14,12 @@ fn borrow(v: &int, f: |x: &int|) {

fn box_imm() {
let mut v = ~3;
borrow(v, |w| {
v = ~4; //~ ERROR cannot assign to `v` because it is borrowed
assert_eq!(*v, 3);
assert_eq!(*w, 4);
})
borrow(v,
|w| { //~ ERROR cannot borrow `v` as mutable
v = ~4;
assert_eq!(*v, 3);
assert_eq!(*w, 4);
})
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/borrowck-loan-rcvr.rs
Expand Up @@ -32,8 +32,8 @@ fn a() {
p.impurem();

// But in this case we do not honor the loan:
p.blockm(|| {
p.x = 10; //~ ERROR cannot assign
p.blockm(|| { //~ ERROR cannot borrow `p` as mutable
p.x = 10;
})
}

Expand Down
8 changes: 5 additions & 3 deletions src/test/compile-fail/borrowck-loan-vec-content.rs
Expand Up @@ -23,9 +23,11 @@ fn has_mut_vec_and_does_not_try_to_change_it() {

fn has_mut_vec_but_tries_to_change_it() {
let mut v = ~[1, 2, 3];
takes_imm_elt(&v[0], || {
v[1] = 4; //~ ERROR cannot assign
})
takes_imm_elt(
&v[0],
|| { //~ ERROR cannot borrow `v` as mutable
v[1] = 4;
})
}

fn main() {
Expand Down
6 changes: 2 additions & 4 deletions src/test/compile-fail/borrowck-move-by-capture.rs
Expand Up @@ -9,10 +9,8 @@
// except according to those terms.

pub fn main() {
// FIXME(#2202) - Due to the way that borrowck treats closures,
// you get two error reports here.
let bar = ~3;
let _g = || { //~ ERROR capture of moved value
let _h: proc() -> int = proc() *bar; //~ ERROR capture of moved value
let _g = || {
let _h: proc() -> int = proc() *bar; //~ ERROR cannot move out of captured outer variable
};
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-object-lifetime.rs
Expand Up @@ -17,7 +17,7 @@ fn borrowed_receiver<'a>(x: &'a Foo) -> &'a () {
}

fn owned_receiver(x: ~Foo) -> &() {
x.borrowed() //~ ERROR borrowed value does not live long enough
x.borrowed() //~ ERROR `*x` does not live long enough
}

fn mut_owned_receiver(mut x: ~Foo) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/borrowck-vec-pattern-move-tail.rs
Expand Up @@ -14,6 +14,6 @@ fn main() {
[1, 2, ..tail] => tail,
_ => unreachable!()
};
a[0] = 0; //~ ERROR cannot assign to `a[]` because it is borrowed
a[0] = 0; //~ ERROR cannot assign to `a[..]` because it is borrowed
t[0];
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/borrowck-vec-pattern-nesting.rs
Expand Up @@ -12,7 +12,7 @@ fn a() {
let mut vec = ~[~1, ~2, ~3];
match vec {
[~ref _a] => {
vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed
vec[0] = ~4; //~ ERROR cannot assign
}
_ => fail!("foo")
}
Expand All @@ -22,7 +22,7 @@ fn b() {
let mut vec = ~[~1, ~2, ~3];
match vec {
[.._b] => {
vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed
vec[0] = ~4; //~ ERROR cannot assign
}
}
}
Expand Down
Expand Up @@ -11,7 +11,7 @@
fn a() -> &int {
let vec = ~[1, 2, 3, 4];
let tail = match vec {
[_a, ..tail] => &tail[0], //~ ERROR borrowed value does not live long enough
[_a, ..tail] => &tail[0], //~ ERROR `vec[..]` does not live long enough
_ => fail!("foo")
};
tail
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-3154.rs
Expand Up @@ -13,7 +13,7 @@ struct thing<'a, Q> {
}

fn thing<Q>(x: &Q) -> thing<Q> {
thing{ x: x } //~ ERROR cannot infer an appropriate lifetime
thing{ x: x } //~ ERROR cannot infer
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-4335.rs
Expand Up @@ -11,7 +11,7 @@
fn id<T>(t: T) -> T { t }

fn f<'r, T>(v: &'r T) -> 'r || -> T {
id(|| *v) //~ ERROR cannot infer an appropriate lifetime
id(|| *v) //~ ERROR cannot infer
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/kindck-owned-trait-contains.rs
Expand Up @@ -24,7 +24,7 @@ fn main() {

let y = {
let tmp0 = 3;
let tmp1 = &tmp0; //~ ERROR borrowed value does not live long enough
let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough
repeater(tmp1)
};
assert!(3 == *(y.get()));
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/moves-based-on-type-access-to-field.rs
Expand Up @@ -17,13 +17,13 @@ fn touch<A>(_a: &A) {}

fn f10() {
let x = Foo { f: ~"hi", y: 3 };
consume(x.f); //~ NOTE `x.f` moved here
consume(x.f);
touch(&x.y); //~ ERROR use of partially moved value: `x`
}

fn f20() {
let x = ~[~"hi"];
consume(x[0]); //~ NOTE `(*x)[]` moved here
consume(x[0]);
touch(&x[0]); //~ ERROR use of partially moved value: `x`
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mut-cant-alias.rs
Expand Up @@ -14,5 +14,5 @@ fn main() {
let m = RefCell::new(0);
let mut b = m.borrow_mut();
let b1 = b.get();
let b2 = b.get(); //~ ERROR cannot borrow `b` because it is already borrowed as mutable
let b2 = b.get(); //~ ERROR cannot borrow
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/mut-ptr-cant-outlive-ref.rs
Expand Up @@ -15,6 +15,6 @@ fn main() {
let p;
{
let b = m.borrow();
p = b.get(); //~ ERROR borrowed value does not live long enough
p = b.get(); //~ ERROR `b` does not live long enough
}
}
6 changes: 3 additions & 3 deletions src/test/compile-fail/regionck-closure-lifetimes.rs
Expand Up @@ -18,7 +18,7 @@ fn env<'a>(_: &'a uint, blk: |p: 'a |||) {

let mut state = 0;
let statep = &mut state;
blk(|| *statep = 1); //~ ERROR cannot infer an appropriate lifetime
blk(|| *statep = 1); //~ ERROR cannot infer
}

fn no_env_no_for<'a>(_: &'a uint, blk: |p: 'a |||) {
Expand All @@ -40,7 +40,7 @@ fn repeating_loop() {
let state = 0;

loop {
closure = || state; //~ ERROR cannot infer an appropriate lifetime
closure = || state; //~ ERROR cannot infer
break;
}

Expand All @@ -56,7 +56,7 @@ fn repeating_while() {
let state = 0;

while true {
closure = || state; //~ ERROR cannot infer an appropriate lifetime
closure = || state; //~ ERROR cannot infer
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-addr-of-arg.rs
Expand Up @@ -12,15 +12,15 @@
// bounded by the current function call.

fn foo(a: int) {
let _p: &'static int = &a; //~ ERROR borrowed value does not live long enough
let _p: &'static int = &a; //~ ERROR `a` does not live long enough
}

fn bar(a: int) {
let _q: &int = &a;
}

fn zed<'a>(a: int) -> &'a int {
&a //~ ERROR borrowed value does not live long enough
&a //~ ERROR `a` does not live long enough
}

fn main() {
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/regions-addr-of-self.rs
Expand Up @@ -14,8 +14,7 @@ struct dog {

impl dog {
pub fn chase_cat(&mut self) {
let p: &'static mut uint = &mut self.cats_chased;
//~^ ERROR cannot infer an appropriate lifetime
let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer
*p += 1u;
}

Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/regions-addr-of-upvar-self.rs
Expand Up @@ -17,8 +17,7 @@ struct dog {
impl dog {
pub fn chase_cat(&mut self) {
let _f = || {
let p: &'static mut uint = &mut self.food;
//~^ ERROR cannot infer an appropriate lifetime
let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer
*p = 3u;
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-bounds.rs
Expand Up @@ -17,12 +17,12 @@ struct a_class<'a> { x:&'a int }

fn a_fn1<'a,'b>(e: an_enum<'a>) -> an_enum<'b> {
return e; //~ ERROR mismatched types: expected `an_enum<'b>` but found `an_enum<'a>`
//~^ ERROR cannot infer an appropriate lifetime
//~^ ERROR cannot infer
}

fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> {
return e; //~ ERROR mismatched types: expected `a_class<'b>` but found `a_class<'a>`
//~^ ERROR cannot infer an appropriate lifetime
//~^ ERROR cannot infer
}

fn main() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/regions-creating-enums3.rs
Expand Up @@ -14,7 +14,7 @@ enum ast<'a> {
}

fn mk_add_bad1<'a,'b>(x: &'a ast<'a>, y: &'b ast<'b>) -> ast<'a> {
add(x, y) //~ ERROR cannot infer an appropriate lifetime
add(x, y) //~ ERROR cannot infer
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/regions-creating-enums4.rs
Expand Up @@ -14,7 +14,7 @@ enum ast<'a> {
}

fn mk_add_bad2<'a>(x: &'a ast<'a>, y: &'a ast<'a>, z: &ast) -> ast {
add(x, y) //~ ERROR cannot infer an appropriate lifetime
add(x, y) //~ ERROR cannot infer
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/regions-escape-loop-via-variable.rs
Expand Up @@ -18,6 +18,6 @@ fn main() {

loop {
let x = 1 + *p;
p = &x; //~ ERROR borrowed value does not live long enough
p = &x; //~ ERROR `x` does not live long enough
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/regions-escape-loop-via-vec.rs
Expand Up @@ -14,7 +14,7 @@ fn broken() {
let mut _y = ~[&mut x];
while x < 10 {
let mut z = x;
_y.push(&mut z); //~ ERROR borrowed value does not live long enough
_y.push(&mut z); //~ ERROR `z` does not live long enough
x += 1; //~ ERROR cannot assign
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-free-region-ordering-callee.rs
Expand Up @@ -20,13 +20,13 @@ fn ordering1<'a, 'b>(x: &'a &'b uint) -> &'a uint {

fn ordering2<'a, 'b>(x: &'a &'b uint, y: &'a uint) -> &'b uint {
// However, it is not safe to assume that 'b <= 'a
&*y //~ ERROR cannot infer an appropriate lifetime
&*y //~ ERROR cannot infer
}

fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint {
// Do not infer an ordering from the return value.
let z: &'b uint = &*x;
//~^ ERROR cannot infer an appropriate lifetime
//~^ ERROR cannot infer
fail!();
}

Expand Down
Expand Up @@ -18,7 +18,7 @@ fn call1<'a>(x: &'a uint) {
let y: uint = 3;
let z: &'a & uint = &(&y);
//~^ ERROR borrowed value does not live long enough
//~^^ ERROR borrowed value does not live long enough
//~^^ ERROR `y` does not live long enough
}

fn main() {}
Expand Up @@ -24,7 +24,7 @@ impl<'b, T> Node<'b, T> {
fn get<'a>(&'a self) -> &'b T {
match self.next {
Some(ref next) => next.get(),
None => &self.val //~ ERROR cannot infer an appropriate lifetime
None => &self.val //~ ERROR cannot infer
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/regions-freevar.rs
Expand Up @@ -12,8 +12,7 @@ fn wants_static_fn(_x: 'static ||) {}

fn main() {
let i = 3;
wants_static_fn(|| {
//~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
wants_static_fn(|| { //~ ERROR cannot infer
info!("i={}", i);
})
}

0 comments on commit 3805c54

Please sign in to comment.