std::mem::transmute::<fn(), fn(i32)>(f)
};
- g(42) //~ ERROR constant evaluation error
- //~^ NOTE tried to call a function with sig fn() through a function pointer of type fn(i32)
+ g(42) //~ ERROR tried to call a function with incorrect number of arguments
}
std::mem::transmute::<fn((i32,i32)), fn(i32)>(f)
};
- g(42) //~ ERROR constant evaluation error
- //~^ NOTE tried to call a function with sig fn((i32, i32)) through a function pointer of type fn(i32)
+ g(42) //~ ERROR tried to call a function with argument of type (i32, i32) passing data of type i32
}
--- /dev/null
+fn main() {
+ fn f(_ : (i32,i32)) {}
+
+ let g = unsafe {
+ std::mem::transmute::<fn((i32,i32)), fn()>(f)
+ };
+
+ g() //~ ERROR tried to call a function with incorrect number of arguments
+}
+
--- /dev/null
+fn main() {
+ fn f(_ : *const [i32]) {}
+
+ let g = unsafe {
+ std::mem::transmute::<fn(*const [i32]), fn(*const i32)>(f)
+ };
+
+ g(&42 as *const i32) //~ ERROR tried to call a function with argument of type *const [i32] passing data of type *const i32
+}
#[allow(const_err)]
static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) };
+// use to first make the closure FnOnce() before making it fn()
+fn magic<F: FnOnce()>(f: F) -> F { f }
+
fn main() {
FOO();
BAR(44, 45);
unsafe { bar(46, 47) };
let boo: &Fn(i32, i32) = &BAR;
boo(48, 49);
+
+ let f = magic(||{}) as fn();
+ f();
}