new tests for new fn arg passing code

This commit is contained in:
Ralf Jung 2018-08-27 17:08:42 +02:00
parent 904923fa7a
commit e239fcffc1
5 changed files with 27 additions and 4 deletions

View file

@ -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
}

View file

@ -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
}

View 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
}

View 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
}

View file

@ -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();
}