]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/verbose_file_reads.rs
Merge commit '8da837185714cefbb261e93e9846afb11c1dc60e' into sync-rustfmt-subtree
[rust.git] / src / tools / clippy / 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 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 }