Downgrade unsafe_vector_initialization to restriction

This lint looks for:

    let mut vec = Vec::with_capacity(len);
    vec.set_len(len);

The suggested replacement is `vec![0; len]`.

This is far too opinionated to be a deny-by-default lint because the performance
characteristics of the suggested replacement are totally different.

I am not convinced that this lint has value beyond what deny(unsafe_code) gives
you. Unsafe code is unsafe but please don't deny-by-default lint it if that's
the only reason.
This commit is contained in:
David Tolnay 2018-12-01 16:20:58 -08:00
parent c669727df4
commit 8b1f69a485
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 2 additions and 3 deletions

View file

@ -495,6 +495,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
panic_unimplemented::UNIMPLEMENTED,
shadow::SHADOW_REUSE,
shadow::SHADOW_SAME,
slow_vector_initialization::UNSAFE_VECTOR_INITIALIZATION,
strings::STRING_ADD,
write::PRINT_STDOUT,
write::USE_DEBUG,
@ -727,7 +728,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
returns::UNUSED_UNIT,
serde_api::SERDE_API_MISUSE,
slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
slow_vector_initialization::UNSAFE_VECTOR_INITIALIZATION,
strings::STRING_LIT_AS_BYTES,
suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
@ -974,7 +974,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
ranges::ITERATOR_STEP_BY_ZERO,
regex::INVALID_REGEX,
serde_api::SERDE_API_MISUSE,
slow_vector_initialization::UNSAFE_VECTOR_INITIALIZATION,
suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
swap::ALMOST_SWAPPED,

View file

@ -55,7 +55,7 @@ declare_clippy_lint! {
/// ```
declare_clippy_lint! {
pub UNSAFE_VECTOR_INITIALIZATION,
correctness,
restriction,
"unsafe vector initialization"
}