mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-03 18:09:42 +00:00
6c201db005
Checks for the suspicious use of OpenOptions::create() without an explicit OpenOptions::truncate(). create() alone will either create a new file or open an existing file. If the file already exists, it will be overwritten when written to, but the file will not be truncated by default. If less data is written to the file than it already contains, the remainder of the file will remain unchanged, and the end of the file will contain old data. In most cases, one should either use `create_new` to ensure the file is created from scratch, or ensure `truncate` is called so that the truncation behaviour is explicit. `truncate(true)` will ensure the file is entirely overwritten with new data, whereas `truncate(false)` will explicitely keep the default behavior. ```rust use std::fs::OpenOptions; OpenOptions::new().create(true).truncate(true); ```
23 lines
861 B
Text
23 lines
861 B
Text
error: used `seek` to go to the start of the stream
|
|
--> $DIR/seek_to_start_instead_of_rewind.rs:52:7
|
|
|
|
|
LL | t.seek(SeekFrom::Start(0));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
|
|
|
|
|
= note: `-D clippy::seek-to-start-instead-of-rewind` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::seek_to_start_instead_of_rewind)]`
|
|
|
|
error: used `seek` to go to the start of the stream
|
|
--> $DIR/seek_to_start_instead_of_rewind.rs:57:7
|
|
|
|
|
LL | t.seek(SeekFrom::Start(0));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
|
|
|
|
error: used `seek` to go to the start of the stream
|
|
--> $DIR/seek_to_start_instead_of_rewind.rs:136:7
|
|
|
|
|
LL | f.seek(SeekFrom::Start(0));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `rewind()`
|
|
|
|
error: aborting due to 3 previous errors
|
|
|