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
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() {
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!()
+ }
+ })
}
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() {}
}
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() {
info!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
+}
+fn box_imm_explicit() {
let v = ~3;
let _w = &v;
task::spawn(proc() {
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() {
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;
})
}
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() {
// 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
};
}
}
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) {
[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];
}
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")
}
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
}
}
}
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
}
fn thing<Q>(x: &Q) -> thing<Q> {
- thing{ x: x } //~ ERROR cannot infer an appropriate lifetime
+ thing{ x: x } //~ ERROR cannot infer
}
fn main() {
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() {
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()));
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`
}
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
}
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
}
}
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 |||) {
let state = 0;
loop {
- closure = || state; //~ ERROR cannot infer an appropriate lifetime
+ closure = || state; //~ ERROR cannot infer
break;
}
let state = 0;
while true {
- closure = || state; //~ ERROR cannot infer an appropriate lifetime
+ closure = || state; //~ ERROR cannot infer
break;
}
// 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) {
}
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() {
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;
}
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;
};
}
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() { }
}
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() {
}
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() {
loop {
let x = 1 + *p;
- p = &x; //~ ERROR borrowed value does not live long enough
+ p = &x; //~ ERROR `x` does not live long enough
}
}
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
}
}
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!();
}
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() {}
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
}
}
}
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);
})
}
impl<'a> Flag<'a> {
pub fn set_desc(self, s: &str) -> Flag<'a> {
- Flag { //~ ERROR cannot infer an appropriate lifetime
+ Flag { //~ ERROR cannot infer
name: self.name,
desc: s,
max_count: self.max_count,
fn take1(p: parameterized1) -> parameterized1 { p }
//~^ ERROR mismatched types
-//~^^ ERROR cannot infer an appropriate lifetime
+//~^^ ERROR cannot infer
fn take3(p: not_parameterized1) -> not_parameterized1 { p }
fn take4(p: not_parameterized2) -> not_parameterized2 { p }
fn manip<'a>(x: &'a int) -> int {
let z = with(|y| { select(x, y) });
- //~^ ERROR cannot infer an appropriate lifetime
+ //~^ ERROR cannot infer
*z
}
}
fn take_direct(p: direct) -> direct { p } //~ ERROR mismatched types
-//~^ ERROR cannot infer an appropriate lifetime
+//~^ ERROR cannot infer
fn take_indirect1(p: indirect1) -> indirect1 { p }
fn take_indirect2(p: indirect2) -> indirect2 { p } //~ ERROR mismatched types
-//~^ ERROR cannot infer an appropriate lifetime
+//~^ ERROR cannot infer
fn main() {}
fn set_f_bad(&self, b: @b) {
self.f = b; //~ ERROR mismatched types: expected `@@&'a int` but found `@@&int`
- //~^ ERROR cannot infer an appropriate lifetime
+ //~^ ERROR cannot infer
}
}
fn nested() {
let y = 3;
- ignore(|z| {
- if false { &y } else { z } //~ ERROR borrowed value does not live long enough
- });
+ ignore(
+ |z| { //~ ERROR `y` does not live long enough
+ if false { &y } else { z }
+ });
}
fn main() {}
fn nested<'x>(x: &'x int) {
let y = 3;
- let mut ay = &y; //~ ERROR cannot infer an appropriate lifetime
+ let mut ay = &y; //~ ERROR cannot infer
ignore::< <'z>|&'z int|>(|z| {
ay = x;
ignore::< <'z>|&'z int| -> &'z int>(|z| {
if false { return x; } //~ ERROR mismatched types
- //~^ ERROR cannot infer an appropriate lifetime
+ //~^ ERROR cannot infer
if false { return ay; }
return z;
});
fn return_it<'a>() -> &'a int {
with(|o| o) //~ ERROR mismatched types
//~^ ERROR lifetime of return value does not outlive the function call
- //~^^ ERROR cannot infer an appropriate lifetime
+ //~^^ ERROR cannot infer
}
fn main() {
fn return_it() -> &int {
with(|o| o) //~ ERROR mismatched types
//~^ ERROR lifetime of return value does not outlive the function call
- //~^^ ERROR cannot infer an appropriate lifetime
+ //~^^ ERROR cannot infer
}
fn main() {
fn main() {
let cl_box = {
let mut i = 3;
- box_it(|| i += 1) //~ ERROR cannot infer an appropriate lifetime
+ box_it(|| i += 1) //~ ERROR cannot infer
};
(cl_box.cl)();
}
}
fn make_gc2<'a,'b>(foo: Foo<'a>) -> @get_ctxt<'b> {
- return @foo as @get_ctxt; //~ ERROR cannot infer an appropriate lifetime
+ return @foo as @get_ctxt; //~ ERROR cannot infer
}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// error-pattern: cannot infer an appropriate lifetime
+// error-pattern: cannot infer
extern mod sync;
use sync::RWLock;
fn main() {
fn main() {
let person = ~"Fred";
- let person: &str = person; //~ ERROR borrowed value does not live long enough
+ let person: &str = person; //~ ERROR `person[..]` does not live long enough
let s: ~Trait<&'static str> = ~Struct { person: person };
}
let mut xs = ~[1, 2, 3, 4];
for x in xs.mut_iter() {
- xs.push(1) //~ ERROR cannot borrow `xs` because it is already borrowed as mutable
+ xs.push(1) //~ ERROR cannot borrow `xs`
}
}
pub fn main() {
let mut e = Refs{refs: ~[], n: 0};
let _f: || = || error!("{}", e.n);
- e.refs.push(1);
+ let x: &[int] = e.refs;
+ assert_eq!(x.len(), 0);
}
pub fn main() {
let mut i = 3;
- let cl_box = box_it(|| i += 1);
assert_eq!(i, 3);
- (cl_box.cl)();
+ {
+ let cl = || i += 1;
+ let cl_box = box_it(cl);
+ (cl_box.cl)();
+ }
assert_eq!(i, 4);
}