Is it theoretically possible to have completely safe JIT compilation in native Rust?
I was playing around with the inkwell crate, which is a really awesome crate that wraps llvm-sys. In the example on the crates.io page I linked above, we see that we can JIT compile a function at runtime that adds three numbers. My understanding is that a lot of the API has to be unsafe since theoretically it can call any undefined function. There is a note at the bottom of said example that explains the example needs two instances of unsafe since 1) we don't know if we're calling the correct function with the correct parameters and 2) we don't know if the function we created does unsafe things.
My question is this: would it be possible for some sort of new interface (potentially a new crate) to exist that strictly only JIT compiles native Rust code (versus any unsafe C function), such that it only generates safe Rust code? An example would be building a Rust function with some builder, checking at runtime if it compiles correctly once we've built it, and thus outputting a completely safe Rust function.
A followup question is this: is it possible to JIT compile a known valid Rust syntax tree (perhaps from syn) that would output a completely safe function?
I have very limited knowledge of LLVM and JIT compilation, so any thoughts would be appreciated!
Edit: I mention unsafe here, what I really mean is engineering it in a way that is not unsound, so writing a sound solution.