You can do that with Python (sometimes) because many libraries have type hints today, so even if you don't use types yourself, the type checker can infer them in your code and help you out.
The same way Rust checks for object lifespans with the borrow checker, which is distinct from the compiler and type system.
The same way valgrind for C can check for use after free.
The same way errorprone can look for null checks in Java.
This is a well tested and proven technique. Static code analysis is a staple of the industry, when it comes to automated code analysis.
All of the examples you gave are from static languages, where the information is known at compile time (except for valgrind, which requires a runtime). The parent to my original post was claiming that you can have the same tooling for Ruby.
Also, you're wrong about Rust. Lifetimes are part of the type system.