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 { read_to_end(&self)9 pub fn read_to_end(&self) {} 10 read_to_string(&self)11 pub fn read_to_string(&self) {} 12 } 13 main() -> std::io::Result<()>14fn 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 21 let mut f = File::open(path)?; 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 } 29