2013-06-25 11:04:50 -05:00
|
|
|
// Copyright 2013 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.
|
|
|
|
|
2014-06-23 12:01:14 -05:00
|
|
|
fn env<'a>(blk: |p: ||: 'a|) {
|
2013-06-25 11:04:50 -05:00
|
|
|
// Test that the closure here cannot be assigned
|
|
|
|
// the lifetime `'a`, which outlives the current
|
|
|
|
// block.
|
|
|
|
|
2014-06-27 14:30:25 -05:00
|
|
|
let mut state = 0i;
|
2013-06-25 11:04:50 -05:00
|
|
|
let statep = &mut state;
|
2014-06-27 14:30:25 -05:00
|
|
|
blk(|| *statep = 1i); //~ ERROR cannot infer
|
2013-06-25 11:04:50 -05:00
|
|
|
}
|
|
|
|
|
2014-06-23 12:01:14 -05:00
|
|
|
fn no_env_no_for<'a>(blk: |p: |||: 'a) {
|
2013-06-25 11:04:50 -05:00
|
|
|
// Test that a closure with no free variables CAN
|
|
|
|
// outlive the block in which it is created.
|
|
|
|
|
|
|
|
blk(|| ())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn repeating_loop() {
|
|
|
|
// Test that the closure cannot be created within `loop` loop and
|
|
|
|
// called without, even though the state that it closes over is
|
|
|
|
// external to the loop.
|
|
|
|
|
|
|
|
let closure;
|
2014-06-27 14:30:25 -05:00
|
|
|
let state = 0i;
|
2013-06-25 11:04:50 -05:00
|
|
|
|
|
|
|
loop {
|
2014-02-10 06:44:03 -06:00
|
|
|
closure = || state; //~ ERROR cannot infer
|
2013-06-25 11:04:50 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
closure();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn repeating_while() {
|
|
|
|
// Test that the closure cannot be created within `while` loop and
|
|
|
|
// called without, even though the state that it closes over is
|
|
|
|
// external to the loop.
|
|
|
|
|
|
|
|
let closure;
|
2014-06-27 14:30:25 -05:00
|
|
|
let state = 0i;
|
2013-06-25 11:04:50 -05:00
|
|
|
|
|
|
|
while true {
|
2014-02-10 06:44:03 -06:00
|
|
|
closure = || state; //~ ERROR cannot infer
|
2013-06-25 11:04:50 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
closure();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|