title: Cannot move out of captured outer variable in an `Fn` closure
body: <p>I'm trying to figure out how to send a function through a channel, and how to avoid extra cloning in order to execute the function at the other end. If I remove the extra cloning operation inside the closure, I get the following error: </p>
  
  <pre><code>error: cannot move out of captured outer variable in an 'Fn' closure
  </code></pre>
  
  <p>Ignoring the fact that this code does absolutely nothing, and makes use of a global mutable static <code>Sender&lt;T&gt;</code>, it represents what I'm trying to achieve while giving the proper compiler errors. This code is <strong>not meant to be ran</strong>, just compiled.</p>
  
  <pre><code>use std::ops::DerefMut;
  use std::sync::{Arc, Mutex};
  use std::collections::LinkedList;
  use std::sync::mpsc::{Sender, Receiver};
  
  type SafeList = Arc&lt;Mutex&lt;LinkedList&lt;u8&gt;&gt;&gt;;
  type SendableFn = Arc&lt;Mutex&lt;(Fn() + Send + Sync + 'static)&gt;&gt;;
  static mut tx: *mut Sender&lt;SendableFn&gt; = 0 as *mut Sender&lt;SendableFn&gt;;
  
  fn main() {
      let list: SafeList = Arc::new(Mutex::new(LinkedList::new()));
      loop {
          let t_list = list.clone();
          run(move || {
              foo(t_list.clone());
          });
      }
  }
  
  fn run&lt;T: Fn() + Send + Sync + 'static&gt;(task: T) {
      unsafe {
          let _ = (*tx).send(Arc::new(Mutex::new(task)));
      }
  }
  
  #[allow(dead_code)]
  fn execute(rx: Receiver&lt;SendableFn&gt;) {
      for t in rx.iter() {
          let mut guard = t.lock().unwrap();
          let task = guard.deref_mut();
          task();
      }
  }
  
  #[allow(unused_variables)]
  fn foo(list: SafeList) { }
  </code></pre>
  
  <p>Is there a better method to getting around that error and/or another way I should be sending functions through channels?</p>