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