2014-10-28 11:24:25 +00:00
|
|
|
// Checks that the Fn trait hierarchy rules do not permit
|
|
|
|
// Fn to be used where FnMut is implemented.
|
|
|
|
|
2016-11-10 17:08:21 +00:00
|
|
|
#![feature(fn_traits, unboxed_closures)]
|
2014-06-02 01:41:46 +00:00
|
|
|
|
2014-10-28 11:24:25 +00:00
|
|
|
use std::ops::{Fn,FnMut,FnOnce};
|
2014-06-02 01:41:46 +00:00
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
2015-01-12 15:27:25 +00:00
|
|
|
impl FnMut<(isize,)> for S {
|
2015-01-08 10:54:35 +00:00
|
|
|
extern "rust-call" fn call_mut(&mut self, (x,): (isize,)) -> isize {
|
2014-06-02 01:41:46 +00:00
|
|
|
x * x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:08:33 +00:00
|
|
|
impl FnOnce<(isize,)> for S {
|
|
|
|
type Output = isize;
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(mut self, args: (isize,)) -> isize { self.call_mut(args) }
|
|
|
|
}
|
|
|
|
|
2015-01-08 10:54:35 +00:00
|
|
|
fn call_it<F:Fn(isize)->isize>(f: &F, x: isize) -> isize {
|
2014-10-28 11:24:25 +00:00
|
|
|
f.call((x,))
|
2014-06-02 01:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-01-12 15:27:25 +00:00
|
|
|
let x = call_it(&S, 22);
|
2016-03-29 17:12:31 +00:00
|
|
|
//~^ ERROR E0277
|
2014-06-02 01:41:46 +00:00
|
|
|
}
|