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
This commit is contained in:
atwam 2024-01-11 12:49:49 +00:00
parent 84588a8815
commit 515fe65ba8
No known key found for this signature in database
5 changed files with 44 additions and 12 deletions

View file

@ -26,16 +26,23 @@ fn main() {
.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).write(true).open("dump.json").unwrap();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("dump.json")
.unwrap();
}

View file

@ -26,16 +26,23 @@ fn main() {
.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).write(true).open("dump.json").unwrap();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("dump.json")
.unwrap();
}

View file

@ -29,5 +29,6 @@ fn main() {
let mut options = std::fs::OpenOptions::new();
options.read(true);
options.read(false);
//~^ ERROR: the method `read` is called more than once
//#~^ ERROR: the method `read` is called more than once
options.open("foo.txt");
}

View file

@ -4,9 +4,9 @@ error: file opened with `create`, but `truncate` behavior not defined
LL | OpenOptions::new().create(true).open("foo.txt");
| ^^^^^^^^^^^^- help: add: `.truncate(true)`
|
= help: if you intend to overwrite an existing file entirely, call `.truncate(true)`. if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`
= help: if you intend to overwrite an existing file entirely, call `.truncate(true)`. if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`. Alternatively, use `.append` to append to the file instead of overwriting it.
= note: `-D clippy::suspicious-open-options` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::suspicious_open_options)]`
error: aborting due to previous error
error: aborting due to 1 previous error