Can You Create a Function, that Returns its own Function Pointer?

126 points Xelaxander

I know this is completely useless, but I'm curious. We want to construct a function, that take zero arguments and returns it's own function pointer. At runtime, this should absolutely be no issue, but we probably can't compile it within the type system.

So far I have failed miserably due to having to type return values explicitly. This leads to an infinitely recursive type:

fn retself<F: Fn() -> F>() -> impl Fn() -> F {
    retself::<F>
}

​