Skip to content

Commit 8b1f69a

Browse files
committed
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.
1 parent c669727 commit 8b1f69a

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
495495
panic_unimplemented::UNIMPLEMENTED,
496496
shadow::SHADOW_REUSE,
497497
shadow::SHADOW_SAME,
498+
slow_vector_initialization::UNSAFE_VECTOR_INITIALIZATION,
498499
strings::STRING_ADD,
499500
write::PRINT_STDOUT,
500501
write::USE_DEBUG,
@@ -727,7 +728,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
727728
returns::UNUSED_UNIT,
728729
serde_api::SERDE_API_MISUSE,
729730
slow_vector_initialization::SLOW_VECTOR_INITIALIZATION,
730-
slow_vector_initialization::UNSAFE_VECTOR_INITIALIZATION,
731731
strings::STRING_LIT_AS_BYTES,
732732
suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
733733
suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
@@ -974,7 +974,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
974974
ranges::ITERATOR_STEP_BY_ZERO,
975975
regex::INVALID_REGEX,
976976
serde_api::SERDE_API_MISUSE,
977-
slow_vector_initialization::UNSAFE_VECTOR_INITIALIZATION,
978977
suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
979978
suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL,
980979
swap::ALMOST_SWAPPED,

clippy_lints/src/slow_vector_initialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare_clippy_lint! {
5555
/// ```
5656
declare_clippy_lint! {
5757
pub UNSAFE_VECTOR_INITIALIZATION,
58-
correctness,
58+
restriction,
5959
"unsafe vector initialization"
6060
}
6161

0 commit comments

Comments
 (0)