rust-clippy/tests/ui/ineffective_open_options.fixed
atwam 515fe65ba8
Fix conflicts
- New ineffective_open_options had to be fixed.
- Now not raising an issue on missing `truncate` when `append(true)`
  makes the intent clear.
- Try implementing more advanced tests for non-chained operations. Fail
2024-01-15 17:15:09 +00:00

48 lines
1.2 KiB
Rust

#![warn(clippy::ineffective_open_options)]
use std::fs::OpenOptions;
fn main() {
let file = OpenOptions::new()
.create(true)
//~ ERROR: unnecessary use of `.write(true)`
.append(true)
.open("dump.json")
.unwrap();
let file = OpenOptions::new()
.create(true)
.append(true)
//~ ERROR: unnecessary use of `.write(true)`
.open("dump.json")
.unwrap();
// All the next calls are ok.
let file = OpenOptions::new()
.create(true)
.write(false)
.append(true)
.open("dump.json")
.unwrap();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.append(false)
.open("dump.json")
.unwrap();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(false)
.append(false)
.open("dump.json")
.unwrap();
let file = OpenOptions::new().create(true).append(true).open("dump.json").unwrap();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("dump.json")
.unwrap();
}