You can if you add {.nimcall.} pragma:
cast[(proc(x: int): int {.nimcall.})](p)
I think it doesn't work because, without this pragma, compiler thinks this is a
closure, and closures have a greater size than normal proc pointers, that's the
reason why the casting is not allowed.
[https://nim-lang.org/docs/manual.html#types-procedural-type](https://nim-lang.org/docs/manual.html#types-procedural-type)
To avoid the boilerplate you can define your own proc types:
type MyProc = proc(x: int): int {.nimcall.}
proc myProc(x: int): int = x + 1
let f: MyProc = myProc
let p: pointer = cast[pointer](myProc)
let casted = cast[MyProc](p)