]> git.lizzy.rs Git - rust.git/blob - tests/ui/verbose_file_reads.rs
add lint on File::read_to_string and File::read_to_end
[rust.git] / tests / ui / verbose_file_reads.rs
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 mut path = temp_dir();
16     path.push("test.txt");
17     let file = File::create(&path)?;
18     // Lint shouldn't catch this
19     let s = Struct;
20     s.read_to_end();
21     s.read_to_string();
22     // Should catch this
23     let mut f = File::open(&path)?;
24     let mut buffer = Vec::new();
25     f.read_to_end(&mut buffer)?;
26     // ...and this
27     let mut string_buffer = String::new();
28     f.read_to_string(&mut string_buffer)?;
29     Ok(())
30 }