I stumbled on this standard library code:
impl ops::Deref for PathBuf {
type Target = Path;
#[inline]
fn deref(&self) -> &Path {
Path::new(&self.inner)
}
}
How can this work? This seems to be creating a temporary on the stack and then returns a reference to it. Isn't that an obvious lifetime violation?