]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cannot-mutate-captured-non-mut-var.rs
Rollup merge of #59072 - RalfJung:miri-alloc-tests, r=kennytm
[rust.git] / src / test / ui / cannot-mutate-captured-non-mut-var.rs
1 // ignore-tidy-linelength
2 // revisions: ast mir
3 //[mir]compile-flags: -Z borrowck=mir
4
5 #![feature(unboxed_closures)]
6
7 use std::io::Read;
8
9 fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
10
11 fn main() {
12     let x = 1;
13     to_fn_once(move|| { x = 2; });
14     //[ast]~^ ERROR: cannot assign to immutable captured outer variable
15     //[mir]~^^ ERROR: cannot assign to `x`, as it is not declared as mutable
16
17     let s = std::io::stdin();
18     to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
19     //[ast]~^ ERROR: cannot borrow immutable captured outer variable
20     //[mir]~^^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
21 }