Add ui test for write_and_append
lint
This commit is contained in:
parent
19f5b85330
commit
5accd517ee
41
tests/ui/ineffective_open_options.fixed
Normal file
41
tests/ui/ineffective_open_options.fixed
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#![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)
|
||||||
|
.write(true)
|
||||||
|
.append(false)
|
||||||
|
.open("dump.json")
|
||||||
|
.unwrap();
|
||||||
|
let file = OpenOptions::new()
|
||||||
|
.create(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).write(true).open("dump.json").unwrap();
|
||||||
|
}
|
41
tests/ui/ineffective_open_options.rs
Normal file
41
tests/ui/ineffective_open_options.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#![warn(clippy::ineffective_open_options)]
|
||||||
|
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let file = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true) //~ ERROR: unnecessary use of `.write(true)`
|
||||||
|
.append(true)
|
||||||
|
.open("dump.json")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let file = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.write(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)
|
||||||
|
.write(true)
|
||||||
|
.append(false)
|
||||||
|
.open("dump.json")
|
||||||
|
.unwrap();
|
||||||
|
let file = OpenOptions::new()
|
||||||
|
.create(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).write(true).open("dump.json").unwrap();
|
||||||
|
}
|
17
tests/ui/ineffective_open_options.stderr
Normal file
17
tests/ui/ineffective_open_options.stderr
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
error: unnecessary use of `.write(true)` because there is `.append(true)`
|
||||||
|
--> $DIR/ineffective_open_options.rs:8:9
|
||||||
|
|
|
||||||
|
LL | .write(true)
|
||||||
|
| ^^^^^^^^^^^^ help: remove `.write(true)`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::ineffective-open-options` implied by `-D warnings`
|
||||||
|
= help: to override `-D warnings` add `#[allow(clippy::ineffective_open_options)]`
|
||||||
|
|
||||||
|
error: unnecessary use of `.write(true)` because there is `.append(true)`
|
||||||
|
--> $DIR/ineffective_open_options.rs:16:9
|
||||||
|
|
|
||||||
|
LL | .write(true)
|
||||||
|
| ^^^^^^^^^^^^ help: remove `.write(true)`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user