Cast as fn pointer to fix build error

Fixes a build error with the latest nightly. See: https://github.com/rust-lang/rust/issues/20178