]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![warn(clippy::verbose_file_reads)] |
2 | use std::env::temp_dir; | |
3 | use std::fs::File; | |
4 | use std::io::Read; | |
5 | ||
6 | struct Struct; | |
7 | // To make sure we only warn on File::{read_to_end, read_to_string} calls | |
8 | impl Struct { | |
9 | pub fn read_to_end(&self) {} | |
10 | ||
11 | pub fn read_to_string(&self) {} | |
12 | } | |
13 | ||
14 | fn main() -> std::io::Result<()> { | |
15 | let path = "foo.txt"; | |
16 | // Lint shouldn't catch this | |
17 | let s = Struct; | |
18 | s.read_to_end(); | |
19 | s.read_to_string(); | |
20 | // Should catch this | |
f2b60f7d | 21 | let mut f = File::open(path)?; |
f20569fa XL |
22 | let mut buffer = Vec::new(); |
23 | f.read_to_end(&mut buffer)?; | |
24 | // ...and this | |
25 | let mut string_buffer = String::new(); | |
26 | f.read_to_string(&mut string_buffer)?; | |
27 | Ok(()) | |
28 | } |