2017-11-22 11:15:56 -06:00
|
|
|
// revisions: ast mir
|
|
|
|
//[mir]compile-flags: -Z borrowck=mir
|
|
|
|
|
2015-01-24 16:25:07 -06:00
|
|
|
// Test that a by-ref `FnMut` closure gets an error when it tries to
|
|
|
|
// mutate a value.
|
|
|
|
|
|
|
|
fn call<F>(f: F) where F : Fn() {
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 02:42:26 -06:00
|
|
|
let mut counter = 0;
|
2015-01-24 16:25:07 -06:00
|
|
|
call(|| {
|
|
|
|
counter += 1;
|
2017-11-22 11:15:56 -06:00
|
|
|
//[ast]~^ ERROR cannot assign to data in a captured outer variable in an `Fn` closure
|
2018-06-12 12:12:19 -05:00
|
|
|
//[mir]~^^ ERROR cannot assign to `counter`
|
2015-01-24 16:25:07 -06:00
|
|
|
});
|
|
|
|
}
|