New lint: unbuffered_bytes
This commit is contained in:
parent
32aef114c6
commit
8b6de49ef7
9 changed files with 143 additions and 6 deletions
37
tests/ui/unbuffered_bytes.rs
Normal file
37
tests/ui/unbuffered_bytes.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#![warn(clippy::unbuffered_bytes)]
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Cursor, Read, Stdin, stdin};
|
||||
use std::net::TcpStream;
|
||||
|
||||
fn main() {
|
||||
// File is not buffered, should complain
|
||||
let file = File::open("./bytes.txt").unwrap();
|
||||
file.bytes();
|
||||
|
||||
// TcpStream is not buffered, should complain
|
||||
let tcp_stream: TcpStream = TcpStream::connect("127.0.0.1:80").unwrap();
|
||||
tcp_stream.bytes();
|
||||
|
||||
// BufReader<File> is buffered, should not complain
|
||||
let file = BufReader::new(File::open("./bytes.txt").unwrap());
|
||||
file.bytes();
|
||||
|
||||
// Cursor is buffered, should not complain
|
||||
let cursor = Cursor::new(Vec::new());
|
||||
cursor.bytes();
|
||||
|
||||
// Stdio would acquire the lock for every byte, should complain
|
||||
let s: Stdin = stdin();
|
||||
s.bytes();
|
||||
|
||||
// But when locking stdin, this is fine so should not complain
|
||||
let s: Stdin = stdin();
|
||||
let s = s.lock();
|
||||
s.bytes();
|
||||
}
|
||||
|
||||
fn use_read<R: Read>(r: R) {
|
||||
// Callers of `use_read` may choose a `R` that is not buffered
|
||||
r.bytes();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue