1
Fork 0

replace f.call_mut(a, b, ..) with f(a, b, ..)

This commit is contained in:
Jorge Aparicio 2015-01-05 14:07:10 -05:00
parent c98814b124
commit ec11f66dbf
17 changed files with 28 additions and 28 deletions

View file

@ -29,7 +29,7 @@ fn innocent_looking_victim() {
} else { } else {
match x { match x {
Some(ref msg) => { Some(ref msg) => {
f.c.call_mut((f, true)); (f.c)(f, true);
//~^ ERROR: cannot borrow `*f` as mutable more than once at a time //~^ ERROR: cannot borrow `*f` as mutable more than once at a time
println!("{}", msg); println!("{}", msg);
}, },

View file

@ -14,6 +14,6 @@ use std::ops::FnMut;
pub fn main() { pub fn main() {
let mut f = |&mut: x: int, y: int| -> int { x + y }; let mut f = |&mut: x: int, y: int| -> int { x + y };
let z = f.call_mut((1u, 2)); //~ ERROR type mismatch let z = f(1u, 2); //~ ERROR type mismatch
println!("{}", z); println!("{}", z);
} }

View file

@ -13,7 +13,7 @@
use std::ops::FnMut; use std::ops::FnMut;
fn call_it<F:FnMut<(int,int),int>>(y: int, mut f: F) -> int { fn call_it<F:FnMut<(int,int),int>>(y: int, mut f: F) -> int {
f.call_mut((2, y)) f(2, y)
} }
pub fn main() { pub fn main() {

View file

@ -18,7 +18,7 @@
*/ */
pub fn map(filename: String, mut emit: map_reduce::putter) { pub fn map(filename: String, mut emit: map_reduce::putter) {
emit.call_mut((filename, "1".to_string(),)); emit(filename, "1".to_string());
} }
mod map_reduce { mod map_reduce {

View file

@ -20,8 +20,8 @@ impl<'a, I, O: 'a> Parser<'a, I, O> {
fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> { fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> {
Parser { Parser {
parse: box move |&mut: x: I| { parse: box move |&mut: x: I| {
match (*self.parse).call_mut((x,)) { match (self.parse)(x) {
Ok(r) => (*rhs.parse).call_mut((r,)), Ok(r) => (rhs.parse)(r),
Err(e) => Err(e) Err(e) => Err(e)
} }
} }

View file

@ -27,7 +27,7 @@ fn tester()
}; };
let path = path::Path::new("blah"); let path = path::Path::new("blah");
assert!(loader.call_mut((&path,)).is_ok()); assert!(loader(&path).is_ok());
} }
pub fn main() {} pub fn main() {}

View file

@ -50,7 +50,7 @@ fn main() {
x: 3, x: 3,
y: 3, y: 3,
}; };
let ans = s.call_mut((3,)); let ans = s(3);
assert_eq!(ans, 27); assert_eq!(ans, 27);
let s = S2 { let s = S2 {
@ -64,7 +64,7 @@ fn main() {
x: 3, x: 3,
y: 3, y: 3,
}; };
let ans = s.call_once((3, 1)); let ans = s(3, 1);
assert_eq!(ans, 27); assert_eq!(ans, 27);
} }

View file

@ -42,19 +42,19 @@ struct Goldfyshe {
} }
impl Pet for Catte { impl Pet for Catte {
fn name(&self, mut blk: Box<FnMut(&str)>) { blk.call_mut((self.name.as_slice(),)) } fn name(&self, mut blk: Box<FnMut(&str)>) { blk(self.name.as_slice()) }
fn num_legs(&self) -> uint { 4 } fn num_legs(&self) -> uint { 4 }
fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 } fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 }
} }
impl Pet for Dogge { impl Pet for Dogge {
fn name(&self, mut blk: Box<FnMut(&str)>) { blk.call_mut((self.name.as_slice(),)) } fn name(&self, mut blk: Box<FnMut(&str)>) { blk(self.name.as_slice()) }
fn num_legs(&self) -> uint { 4 } fn num_legs(&self) -> uint { 4 }
fn of_good_pedigree(&self) -> bool { fn of_good_pedigree(&self) -> bool {
self.bark_decibels < 70 || self.tricks_known > 20 self.bark_decibels < 70 || self.tricks_known > 20
} }
} }
impl Pet for Goldfyshe { impl Pet for Goldfyshe {
fn name(&self, mut blk: Box<FnMut(&str)>) { blk.call_mut((self.name.as_slice(),)) } fn name(&self, mut blk: Box<FnMut(&str)>) { blk(self.name.as_slice()) }
fn num_legs(&self) -> uint { 0 } fn num_legs(&self) -> uint { 0 }
fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 } fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 }
} }

View file

@ -19,7 +19,7 @@ use std::ops::FnMut;
pub fn main() { pub fn main() {
let mut adder = make_adder(3); let mut adder = make_adder(3);
let z = adder.call_mut((2,)); let z = adder(2);
println!("{}", z); println!("{}", z);
assert_eq!(z, 5); assert_eq!(z, 5);
} }

View file

@ -18,15 +18,15 @@ use std::ops::{Fn,FnMut,FnOnce};
fn square(x: int) -> int { x * x } fn square(x: int) -> int { x * x }
fn call_it<F:Fn(int)->int>(f: &F, x: int) -> int { fn call_it<F:Fn(int)->int>(f: &F, x: int) -> int {
f.call((x,)) f(x)
} }
fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int { fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int {
f.call_mut((x,)) f(x)
} }
fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int { fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int {
f.call_once((x,)) f(x)
} }
fn main() { fn main() {

View file

@ -25,15 +25,15 @@ impl Fn<(int,),int> for S {
} }
fn call_it<F:Fn(int)->int>(f: &F, x: int) -> int { fn call_it<F:Fn(int)->int>(f: &F, x: int) -> int {
f.call((x,)) f(x)
} }
fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int { fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int {
f.call_mut((x,)) f(x)
} }
fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int { fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int {
f.call_once((x,)) f(x)
} }
fn main() { fn main() {

View file

@ -25,11 +25,11 @@ impl FnMut<(int,),int> for S {
} }
fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int { fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int {
f.call_mut((x,)) f(x)
} }
fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int { fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int {
f.call_once((x,)) f(x)
} }
fn main() { fn main() {

View file

@ -13,7 +13,7 @@
use std::ops::FnMut; use std::ops::FnMut;
fn call_it<F:FnMut<(int,int),int>>(y: int, mut f: F) -> int { fn call_it<F:FnMut<(int,int),int>>(y: int, mut f: F) -> int {
f.call_mut((2, y)) f(2, y)
} }
pub fn main() { pub fn main() {

View file

@ -22,11 +22,11 @@ impl FnMut<(int,),int> for S {
} }
fn call_it<F:FnMut(int)->int>(mut f: F, x: int) -> int { fn call_it<F:FnMut(int)->int>(mut f: F, x: int) -> int {
f.call_mut((x,)) + 3 f(x) + 3
} }
fn call_box(f: &mut FnMut(int) -> int, x: int) -> int { fn call_box(f: &mut FnMut(int) -> int, x: int) -> int {
f.call_mut((x,)) + 3 f(x) + 3
} }
fn main() { fn main() {

View file

@ -17,12 +17,12 @@ fn main() {
task.call((0i, )); task.call((0i, ));
let mut task: Box<FnMut(int) -> int> = box |&mut: x| x; let mut task: Box<FnMut(int) -> int> = box |&mut: x| x;
task.call_mut((0i, )); task(0i);
call(|:x| x, 22); call(|:x| x, 22);
} }
fn call<F:FnOnce(int) -> int>(f: F, x: int) -> int { fn call<F:FnOnce(int) -> int>(f: F, x: int) -> int {
f.call_once((x,)) f(x)
} }

View file

@ -14,6 +14,6 @@ use std::ops::FnMut;
pub fn main() { pub fn main() {
let mut f = |&mut: x: int, y: int| -> int { x + y }; let mut f = |&mut: x: int, y: int| -> int { x + y };
let z = f.call_mut((1, 2)); let z = f(1, 2);
assert_eq!(z, 3); assert_eq!(z, 3);
} }

View file

@ -12,6 +12,6 @@
fn main() { fn main() {
let onetime = |: x| x; let onetime = |: x| x;
onetime.call_once((0i,)); onetime(0i);
} }