Skip to content

custom_test_frameworks doesn't work with plain functions #65210

Open
@exFalso

Description

@exFalso

The following code:

#![feature(custom_test_frameworks)]
#![test_runner(my_test_runner)]

fn my_test_runner(tests: &[&fn() -> ()]) {
    for test in tests {
        test();
    }
}

#[test_case]
fn test_1() {}

#[test_case]
fn test_2() {}

results in

11 | fn test_1() {}
   | ^^^^^^^^^^^^^^ expected fn pointer, found fn item
   |
   = note: expected type `&fn()`
              found type `&fn() {test_1}`

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:

fn my_test_runner(tests: &[fn() -> ()]) {
fn my_test_runner<F: Fn() -> ()>(tests: &[F]) {
fn my_test_runner<F: Fn() -> ()>(tests: &[&F]) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.F-custom_test_frameworks`#![feature(custom_test_frameworks)]`requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions