File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -4,21 +4,33 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
4
4
5
5
declare_clippy_lint ! {
6
6
/// ### 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.
7
10
///
8
11
/// ### 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.
9
18
///
10
19
/// ### Example
11
20
/// ```rust
12
- /// // example code where clippy issues a warning
21
+ /// let mut data = Vec::with_capacity(len);
22
+ /// r.read_exact(&mut data)?;
13
23
/// ```
14
24
/// Use instead:
15
25
/// ```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)?;
17
29
/// ```
18
30
#[ clippy:: version = "1.63.0" ]
19
31
pub READ_ZERO_BYTE_VEC ,
20
32
correctness,
21
- "default lint description "
33
+ "checks for reads into a zero-length `Vec` "
22
34
}
23
35
declare_lint_pass ! ( ReadZeroByteVec => [ READ_ZERO_BYTE_VEC ] ) ;
24
36
You can’t perform that action at this time.
0 commit comments