]> git.lizzy.rs Git - rust.git/blob - src/docs/path_buf_push_overwrite.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / path_buf_push_overwrite.txt
1 ### What it does
2 * Checks for [push](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.push)
3 calls on `PathBuf` that can cause overwrites.
4
5 ### Why is this bad?
6 Calling `push` with a root path at the start can overwrite the
7 previous defined path.
8
9 ### Example
10 ```
11 use std::path::PathBuf;
12
13 let mut x = PathBuf::from("/foo");
14 x.push("/bar");
15 assert_eq!(x, PathBuf::from("/bar"));
16 ```
17 Could be written:
18
19 ```
20 use std::path::PathBuf;
21
22 let mut x = PathBuf::from("/foo");
23 x.push("bar");
24 assert_eq!(x, PathBuf::from("/foo/bar"));
25 ```