I try to detect if a revision control tool is used for my application by inspecting the presence of a hidden directory name. However, I would also like to inspect if the user is not reading or writing in that hidden revision control directory itself, as this will be dangerous.
This is part of the standard library, and isn't entirely backwards compatible, which makes it difficult to change. Deprecation or a breaking change would cause code churn, and Rust prefers to avoid that.
From memory management perspective it may be doable to return a reference to the popped part, because lifetimes can keep it alive and prevent getting overwritten, despite being past the end of buffer of the PathBuf. I'm not sure how Miri would like that tho.