Skip to content

Commit 5accd51

Browse files
Add ui test for write_and_append lint
1 parent 19f5b85 commit 5accd51

3 files changed

+99
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![warn(clippy::ineffective_open_options)]
2+
3+
use std::fs::OpenOptions;
4+
5+
fn main() {
6+
let file = OpenOptions::new()
7+
.create(true)
8+
//~ ERROR: unnecessary use of `.write(true)`
9+
.append(true)
10+
.open("dump.json")
11+
.unwrap();
12+
13+
let file = OpenOptions::new()
14+
.create(true)
15+
.append(true)
16+
//~ ERROR: unnecessary use of `.write(true)`
17+
.open("dump.json")
18+
.unwrap();
19+
20+
// All the next calls are ok.
21+
let file = OpenOptions::new()
22+
.create(true)
23+
.write(false)
24+
.append(true)
25+
.open("dump.json")
26+
.unwrap();
27+
let file = OpenOptions::new()
28+
.create(true)
29+
.write(true)
30+
.append(false)
31+
.open("dump.json")
32+
.unwrap();
33+
let file = OpenOptions::new()
34+
.create(true)
35+
.write(false)
36+
.append(false)
37+
.open("dump.json")
38+
.unwrap();
39+
let file = OpenOptions::new().create(true).append(true).open("dump.json").unwrap();
40+
let file = OpenOptions::new().create(true).write(true).open("dump.json").unwrap();
41+
}

tests/ui/ineffective_open_options.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![warn(clippy::ineffective_open_options)]
2+
3+
use std::fs::OpenOptions;
4+
5+
fn main() {
6+
let file = OpenOptions::new()
7+
.create(true)
8+
.write(true) //~ ERROR: unnecessary use of `.write(true)`
9+
.append(true)
10+
.open("dump.json")
11+
.unwrap();
12+
13+
let file = OpenOptions::new()
14+
.create(true)
15+
.append(true)
16+
.write(true) //~ ERROR: unnecessary use of `.write(true)`
17+
.open("dump.json")
18+
.unwrap();
19+
20+
// All the next calls are ok.
21+
let file = OpenOptions::new()
22+
.create(true)
23+
.write(false)
24+
.append(true)
25+
.open("dump.json")
26+
.unwrap();
27+
let file = OpenOptions::new()
28+
.create(true)
29+
.write(true)
30+
.append(false)
31+
.open("dump.json")
32+
.unwrap();
33+
let file = OpenOptions::new()
34+
.create(true)
35+
.write(false)
36+
.append(false)
37+
.open("dump.json")
38+
.unwrap();
39+
let file = OpenOptions::new().create(true).append(true).open("dump.json").unwrap();
40+
let file = OpenOptions::new().create(true).write(true).open("dump.json").unwrap();
41+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: unnecessary use of `.write(true)` because there is `.append(true)`
2+
--> $DIR/ineffective_open_options.rs:8:9
3+
|
4+
LL | .write(true)
5+
| ^^^^^^^^^^^^ help: remove `.write(true)`
6+
|
7+
= note: `-D clippy::ineffective-open-options` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::ineffective_open_options)]`
9+
10+
error: unnecessary use of `.write(true)` because there is `.append(true)`
11+
--> $DIR/ineffective_open_options.rs:16:9
12+
|
13+
LL | .write(true)
14+
| ^^^^^^^^^^^^ help: remove `.write(true)`
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)