new tests for new fn arg passing code
This commit is contained in:
parent
904923fa7a
commit
e239fcffc1
5 changed files with 27 additions and 4 deletions
|
|
@ -5,6 +5,5 @@ fn main() {
|
|||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,5 @@ fn main() {
|
|||
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
|
||||
}
|
||||
|
|
|
|||
10
tests/compile-fail/cast_fn_ptr3.rs
Normal file
10
tests/compile-fail/cast_fn_ptr3.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
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
|
||||
}
|
||||
|
||||
9
tests/compile-fail/cast_fn_ptr4.rs
Normal file
9
tests/compile-fail/cast_fn_ptr4.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ static FOO: fn() = || { assert_ne!(42, 43) };
|
|||
#[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);
|
||||
|
|
@ -11,4 +14,7 @@ fn main() {
|
|||
unsafe { bar(46, 47) };
|
||||
let boo: &Fn(i32, i32) = &BAR;
|
||||
boo(48, 49);
|
||||
|
||||
let f = magic(||{}) as fn();
|
||||
f();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue