]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/verbose_file_reads.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / verbose_file_reads.rs
CommitLineData
f20569fa
XL
1#![warn(clippy::verbose_file_reads)]
2use std::env::temp_dir;
3use std::fs::File;
4use std::io::Read;
5
6struct Struct;
7// To make sure we only warn on File::{read_to_end, read_to_string} calls
8impl Struct {
9 pub fn read_to_end(&self) {}
10
11 pub fn read_to_string(&self) {}
12}
13
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
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}