]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/borrowck-overloaded-call.rs
Imported Upstream version 1.0.0-alpha.2
[rustc.git] / src / test / compile-fail / borrowck-overloaded-call.rs
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.
4 //
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.
10
11 #![feature(unboxed_closures)]
12
13 use std::ops::{Fn, FnMut, FnOnce};
14
15 struct SFn {
16 x: isize,
17 y: isize,
18 }
19
20 impl Fn<(isize,)> for SFn {
21 type Output = isize;
22
23 extern "rust-call" fn call(&self, (z,): (isize,)) -> isize {
24 self.x * self.y * z
25 }
26 }
27
28 struct SFnMut {
29 x: isize,
30 y: isize,
31 }
32
33 impl FnMut<(isize,)> for SFnMut {
34 type Output = isize;
35
36 extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
37 self.x * self.y * z
38 }
39 }
40
41 struct SFnOnce {
42 x: String,
43 }
44
45 impl FnOnce<(String,)> for SFnOnce {
46 type Output = usize;
47
48 extern "rust-call" fn call_once(self, (z,): (String,)) -> usize {
49 self.x.len() + z.len()
50 }
51 }
52
53 fn f() {
54 let mut s = SFn {
55 x: 1,
56 y: 2,
57 };
58 let sp = &mut s;
59 s(3); //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
60 //~^ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable
61 }
62
63 fn g() {
64 let s = SFnMut {
65 x: 1,
66 y: 2,
67 };
68 s(3); //~ ERROR cannot borrow immutable local variable `s` as mutable
69 }
70
71 fn h() {
72 let s = SFnOnce {
73 x: "hello".to_string(),
74 };
75 s(" world".to_string());
76 s(" world".to_string()); //~ ERROR use of moved value: `s`
77 }
78
79 fn main() {}
80