I just wrote buggy code like this:
let path = TempDir::new("dir").path().join("file");
The problem is that Drop for TempDir runs on this line and deletes it immediately. This is obviously not the intended usage of TempDir. Could Rust warn against it?
There’s a similar bug with:
let _ = lock.lock();
if the programmer isn’t aware that _ is not just a wildcard variable name, but an immediate drop that makes the lock ineffective.
I suspect both of these cases could be improved by adding an annotation similar to #[must_use], but where “use” requires giving the value a non-temporary scope.