From 8b1f69a485d394f4439336f958451054c0e89184 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 1 Dec 2018 16:20:58 -0800 Subject: [PATCH] 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. --- clippy_lints/src/lib.rs | 3 +-- clippy_lints/src/slow_vector_initialization.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1b970b2f3769..c2e625f3d52a 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -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, diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 7bf0fea42776..2964bb6fac7d 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -55,7 +55,7 @@ declare_clippy_lint! { /// ``` declare_clippy_lint! { pub UNSAFE_VECTOR_INITIALIZATION, - correctness, + restriction, "unsafe vector initialization" }