RS.CLIPPY.JOIN_ABSOLUTE_PATHS

Calls to `Path::join` which will overwrite the original path

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

What it does

Checks for calls to Path::join that start with a path separator (\\\\ or /).

Why is this bad?

If the argument to Path::join starts with a separator, it will overwrite the original path. If this is intentional, prefer using Path::new instead.

Note the behavior is platform dependent. A leading \\\\ will be accepted on unix systems as part of the file name

See Path::join

Example

let path = Path::new("/bin");
let joined_path = path.join("/sh");
assert_eq!(joined_path, PathBuf::from("/sh"));

Use instead;

let path = Path::new("/bin");

// If this was unintentional, remove the leading separator
let joined_path = path.join("sh");
assert_eq!(joined_path, PathBuf::from("/bin/sh"));

// If this was intentional, create a new path instead
let new = Path::new("/sh");
assert_eq!(new, PathBuf::from("/sh"));