2014-06-01 20:41:46 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-10-28 06:24:25 -05:00
|
|
|
// Checks that the Fn trait hierarchy rules permit
|
|
|
|
// FnMut or FnOnce to be used where FnMut is implemented.
|
|
|
|
|
2014-11-15 15:04:04 -06:00
|
|
|
#![feature(unboxed_closures)]
|
2014-11-15 18:10:22 -06:00
|
|
|
#![feature(unboxed_closures)]
|
2014-06-01 20:41:46 -05:00
|
|
|
|
2014-10-28 06:24:25 -05:00
|
|
|
use std::ops::{FnMut,FnOnce};
|
2014-06-01 20:41:46 -05:00
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
|
|
|
impl FnMut<(int,),int> for S {
|
2014-05-29 00:26:56 -05:00
|
|
|
extern "rust-call" fn call_mut(&mut self, (x,): (int,)) -> int {
|
2014-06-01 20:41:46 -05:00
|
|
|
x * x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 06:24:25 -05:00
|
|
|
fn call_it_mut<F:FnMut(int)->int>(f: &mut F, x: int) -> int {
|
2015-01-05 13:07:10 -06:00
|
|
|
f(x)
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
|
|
|
|
2014-10-28 06:24:25 -05:00
|
|
|
fn call_it_once<F:FnOnce(int)->int>(f: F, x: int) -> int {
|
2015-01-05 13:07:10 -06:00
|
|
|
f(x)
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-10-28 06:24:25 -05:00
|
|
|
let y = call_it_mut(&mut S, 22);
|
|
|
|
let z = call_it_once(S, 22);
|
|
|
|
assert_eq!(y, z);
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
|
|
|
|