Update lint description for new() and default()

This commit is contained in:
Yechan Bae 2021-10-12 16:01:58 -04:00
parent 03fed75c89
commit 4ed3a4fe2f

View file

@ -13,14 +13,16 @@ use rustc_span::{sym, Span};
declare_clippy_lint! { declare_clippy_lint! {
/// ### What it does /// ### What it does
/// Checks for `set_len()` call that creates `Vec` with uninitialized elements. /// Checks for `set_len()` call that creates `Vec` with uninitialized elements.
/// This is commonly caused by calling `set_len()` right after after calling /// This is commonly caused by calling `set_len()` right after allocating or
/// `with_capacity()` or `reserve()`. /// reserving a buffer with `new()`, `default()`, `with_capacity()`, or `reserve()`.
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// It creates a `Vec` with uninitialized data, which leads to /// It creates a `Vec` with uninitialized data, which leads to
/// undefined behavior with most safe operations. /// undefined behavior with most safe operations. Notably, uninitialized
/// `Vec<u8>` must not be used with generic `Read`.
/// ///
/// Notably, uninitialized `Vec<u8>` must not be used with generic `Read`. /// Moreover, calling `set_len()` on a `Vec` created with `new()` or `default()`
/// creates out-of-bound values that lead to heap memory corruption when used.
/// ///
/// ### Known Problems /// ### Known Problems
/// This lint only checks directly adjacent statements. /// This lint only checks directly adjacent statements.