Skip to content

Commit c36c6d8

Browse files
committed
add description
1 parent 81d384b commit c36c6d8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

clippy_lints/src/read_zero_byte_vec.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,33 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
44

55
declare_clippy_lint! {
66
/// ### What it does
7+
/// This lint catches reads into a zero-length `Vec`.
8+
/// Especially in the case of a call to `with_capacity`, this lint warns that read
9+
/// gets the number of bytes from the `Vec`'s length, not its capacity.
710
///
811
/// ### Why is this bad?
12+
/// Reading zero bytes is almost certainly not the intended behavior.
13+
///
14+
/// ### Known problems
15+
/// In theory, a very unusual read implementation could assign some semantic meaning
16+
/// to zero-byte reads. But it seems exceptionally unlikely that code intending to do
17+
/// a zero-byte read would allocate a `Vec` for it.
918
///
1019
/// ### Example
1120
/// ```rust
12-
/// // example code where clippy issues a warning
21+
/// let mut data = Vec::with_capacity(len);
22+
/// r.read_exact(&mut data)?;
1323
/// ```
1424
/// Use instead:
1525
/// ```rust
16-
/// // example code which does not raise clippy warning
26+
/// let mut data = Vec::with_capacity(len);
27+
/// data.resize(len, 0);
28+
/// r.read_exact(&mut data)?;
1729
/// ```
1830
#[clippy::version = "1.63.0"]
1931
pub READ_ZERO_BYTE_VEC,
2032
correctness,
21-
"default lint description"
33+
"checks for reads into a zero-length `Vec`"
2234
}
2335
declare_lint_pass!(ReadZeroByteVec => [READ_ZERO_BYTE_VEC]);
2436

0 commit comments

Comments
 (0)