]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/borrowck/borrow-immutable-upvar-mutation.rs
1 #![feature(unboxed_closures)]
3 // Tests that we can't assign to or mutably borrow upvars from `Fn`
4 // closures (issue #17780)
6 fn set(x
: &mut usize) {
10 fn to_fn
<A
, F
: Fn
<A
>>(f
: F
) -> F
{
13 fn to_fn_mut
<A
, F
: FnMut
<A
>>(f
: F
) -> F
{
21 let _f
= to_fn(|| x
= 42); //~ ERROR cannot assign
24 let _g
= to_fn(|| set(&mut y
)); //~ ERROR cannot borrow
27 let _h
= to_fn_mut(|| {
29 to_fn(|| z
= 42); //~ ERROR cannot assign
36 let _f
= to_fn(move || x
= 42); //~ ERROR cannot assign
39 let _g
= to_fn(move || set(&mut y
)); //~ ERROR cannot borrow
42 let _h
= to_fn_mut(move || {
44 to_fn(move || z
= 42);
45 //~^ ERROR cannot assign
50 fn foo() -> Box
<dyn Fn() -> usize> {
53 x
+= 1; //~ ERROR cannot assign