RS.CLIPPY.PATH_BUF_PUSH_OVERWRITE
Calling `push` with file system root on `PathBuf` can overwrite it
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: path_buf_push_overwrite. Copyright ©2025 The Rust Team. All rights reserved.
What it does
- Checks for push
calls on
PathBufthat can cause overwrites.
Why is this bad?
Calling push with a root path at the start can overwrite the
previous defined path.
Example
use std::path::PathBuf;
let mut x = PathBuf::from("/foo");
x.push("/bar");
assert_eq!(x, PathBuf::from("/bar"));
Could be written:
use std::path::PathBuf;
let mut x = PathBuf::from("/foo");
x.push("bar");
assert_eq!(x, PathBuf::from("/foo/bar"));