Skip to content

Instantly share code, notes, and snippets.

@LunNova
Created September 13, 2025 14:54
Show Gist options
  • Save LunNova/95f98ceb2a0ee4b5b24b0054cafff51d to your computer and use it in GitHub Desktop.
Save LunNova/95f98ceb2a0ee4b5b24b0054cafff51d to your computer and use it in GitHub Desktop.
trait TypeFn {type Output<A>;}
struct Fix<F: TypeFn>(<F as TypeFn>::Output<Fix<F>>);
struct FnRes;
impl TypeFn for FnRes { type Output<A> = fn() -> A;}
fn return_me() -> Fix<FnRes> {
Fix(return_me as fn() -> Fix<FnRes>)
}
fn name_of<T>(a: T) -> &'static str {
core::any::type_name::<T>()
}
// Program returned: 0
// [/app/example.rs:17:5] name_of(return_me()) = "example::Fix<example::FnRes>"
// [/app/example.rs:18:5] name_of(return_me().0()) = "example::Fix<example::FnRes>"
// [/app/example.rs:19:5] return_me().0 = 0x0000559a4d157e50
// [/app/example.rs:19:5] return_me().0().0 = 0x0000559a4d157e50
// [/app/example.rs:19:5] return_me().0().0().0 = 0x0000559a4d157e50
fn main() {
dbg!(name_of(return_me()));
dbg!(name_of(return_me().0()));
dbg!(return_me().0,
return_me().0().0,
return_me().0().0().0,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment