Open exFalso opened 5 years ago
If anyone hits this, my current workaround is to use static lambdas, i.e:
#[test_case]
static TEST_1: fn() -> () = || {};
#[test_case]
static TEST_2: fn() -> () = || {};
Note for anyone coming across this issue:
You can use dyn Fn()
instead of &fn() -> ()
, which works:
fn my_test_runner(tests: &[&dyn Fn()]) {
for test in tests {
test();
}
}
The following code:
results in
The workaround mentioned in https://stackoverflow.com/questions/27895946/expected-fn-item-found-a-different-fn-item-when-working-with-function-pointer doesn't work, as these functions are passed in by the compiler, so we cannot do the coercion.
Other variants that don't work: