RS.CLIPPY.PATHBUF_INIT_THEN_PUSH

`push` immediately after `PathBuf` creation

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: pathbuf_init_then_push. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for calls to push immediately after creating a new PathBuf.

Why is this bad?

Multiple .join() calls are usually easier to read than multiple .push calls across multiple statements. It might also be possible to use PathBuf::from instead.

Known problems

.join() introduces an implicit clone(). PathBuf::from can alternatively be used when the PathBuf is newly constructed. This will avoid the implicit clone.

Example

let mut path_buf = PathBuf::new();
path_buf.push("foo");

Use instead:

let path_buf = PathBuf::from("foo");
// or
let path_buf = PathBuf::new().join("foo");