1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![feature(fn_traits, unboxed_closures)]
13 use std::ops::{Fn, FnMut, FnOnce};
20 impl Fn<(isize,)> for SFn {
21 extern "rust-call" fn call(&self, (z,): (isize,)) -> isize {
26 impl FnMut<(isize,)> for SFn {
27 extern "rust-call" fn call_mut(&mut self, args: (isize,)) -> isize { self.call(args) }
30 impl FnOnce<(isize,)> for SFn {
32 extern "rust-call" fn call_once(self, args: (isize,)) -> isize { self.call(args) }
40 impl FnMut<(isize,)> for SFnMut {
41 extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
46 impl FnOnce<(isize,)> for SFnMut {
48 extern "rust-call" fn call_once(mut self, args: (isize,)) -> isize { self.call_mut(args) }
55 impl FnOnce<(String,)> for SFnOnce {
58 extern "rust-call" fn call_once(self, (z,): (String,)) -> usize {
59 self.x.len() + z.len()
69 s(3); //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
77 s(3); //~ ERROR cannot borrow immutable local variable `s` as mutable
82 x: "hello".to_string(),
84 s(" world".to_string());
85 s(" world".to_string()); //~ ERROR use of moved value: `s`
90 fn use_mut<T>(_: &mut T) { }