Skip to content

Commit 79c684d

Browse files
committed
Auto merge of rust-lang#10692 - y21:missing-asserts, r=Alexendoo
new lint: `missing_asserts_for_indexing` Fixes rust-lang#8296 This lint looks for repeated slice indexing and suggests adding an `assert!` beforehand that helps LLVM elide bounds checks. The lint documentation has an example. I'm not really sure what category this should be in. It seems like a nice lint for the `perf` category but I suspect this has a pretty high FP rate, so it might have to be a pedantic lint or something. I'm also not sure about the name. If someone knows a better name for this lint, I'd be fine with changing it. changelog: new lint [`missing_asserts_for_indexing`]
2 parents 77e395e + 790922c commit 79c684d

9 files changed

+1101
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5132,6 +5132,7 @@ Released 2018-09-13
51325132
[`misnamed_getters`]: https://rust-lang.github.io/rust-clippy/master/index.html#misnamed_getters
51335133
[`misrefactored_assign_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#misrefactored_assign_op
51345134
[`missing_assert_message`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_assert_message
5135+
[`missing_asserts_for_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_asserts_for_indexing
51355136
[`missing_const_for_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
51365137
[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
51375138
[`missing_enforced_import_renames`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames

clippy_lints/src/declared_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
457457
crate::misc_early::ZERO_PREFIXED_LITERAL_INFO,
458458
crate::mismatching_type_param_order::MISMATCHING_TYPE_PARAM_ORDER_INFO,
459459
crate::missing_assert_message::MISSING_ASSERT_MESSAGE_INFO,
460+
crate::missing_asserts_for_indexing::MISSING_ASSERTS_FOR_INDEXING_INFO,
460461
crate::missing_const_for_fn::MISSING_CONST_FOR_FN_INFO,
461462
crate::missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS_INFO,
462463
crate::missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAMES_INFO,

clippy_lints/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ mod misc;
210210
mod misc_early;
211211
mod mismatching_type_param_order;
212212
mod missing_assert_message;
213+
mod missing_asserts_for_indexing;
213214
mod missing_const_for_fn;
214215
mod missing_doc;
215216
mod missing_enforced_import_rename;
@@ -1100,6 +1101,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11001101
store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns));
11011102
store.register_late_pass(|_| Box::<reserve_after_initialization::ReserveAfterInitialization>::default());
11021103
store.register_late_pass(|_| Box::new(implied_bounds_in_impls::ImpliedBoundsInImpls));
1104+
store.register_late_pass(|_| Box::new(missing_asserts_for_indexing::MissingAssertsForIndexing));
11031105
// add lints here, do not remove this comment, it's used in `new_lint`
11041106
}
11051107

0 commit comments

Comments
 (0)