diff options
Diffstat (limited to 'src/docs/read_zero_byte_vec.txt')
| -rw-r--r-- | src/docs/read_zero_byte_vec.txt | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/src/docs/read_zero_byte_vec.txt b/src/docs/read_zero_byte_vec.txt deleted file mode 100644 index cef5604e01c..00000000000 --- a/src/docs/read_zero_byte_vec.txt +++ /dev/null @@ -1,30 +0,0 @@ -### What it does -This lint catches reads into a zero-length `Vec`. -Especially in the case of a call to `with_capacity`, this lint warns that read -gets the number of bytes from the `Vec`'s length, not its capacity. - -### Why is this bad? -Reading zero bytes is almost certainly not the intended behavior. - -### Known problems -In theory, a very unusual read implementation could assign some semantic meaning -to zero-byte reads. But it seems exceptionally unlikely that code intending to do -a zero-byte read would allocate a `Vec` for it. - -### Example -``` -use std::io; -fn foo<F: io::Read>(mut f: F) { - let mut data = Vec::with_capacity(100); - f.read(&mut data).unwrap(); -} -``` -Use instead: -``` -use std::io; -fn foo<F: io::Read>(mut f: F) { - let mut data = Vec::with_capacity(100); - data.resize(100, 0); - f.read(&mut data).unwrap(); -} -``` \ No newline at end of file |
