1 // Tests correct kind-checking of the reason stack closures without the :Copy
2 // bound must be noncopyable. For details see
3 // https://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/
6 // This struct is needed to create the
7 // otherwise infinite type of a fn that
8 // accepts itself as argument:
9 c: Box<dyn FnMut(&mut R, bool) + 'a>
12 fn innocent_looking_victim() {
13 let mut x = Some("hello".to_string());
14 conspirator(|f, writer| {
21 //~^ ERROR: cannot borrow `*f` as mutable more than once at a time
24 None => panic!("oops"),
30 fn conspirator<F>(mut f: F) where F: FnMut(&mut R, bool) {
31 let mut r = R {c: Box::new(f)};
32 f(&mut r, false) //~ ERROR borrow of moved value
35 fn main() { innocent_looking_victim() }