diff options
| author | bors <bors@rust-lang.org> | 2023-11-14 15:55:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-14 15:55:00 +0000 |
| commit | 0c42e451d643d54347aa47d7bc6c731896fe5fde (patch) | |
| tree | cb668925f1e91c87c7671fe9d94efb0c194472cf /clippy_lints/src/lib.rs | |
| parent | ca8f33e19b7a64d2817e8e8f9c4ef382af46b254 (diff) | |
| parent | f8ea496495d2766536d7f0fe11c03d609e8ed837 (diff) | |
Auto merge of #11791 - Jacherr:iter_over_hash_type, r=Jarcho
Implement new lint `iter_over_hash_type` Implements and fixes https://github.com/rust-lang/rust-clippy/issues/11788 This PR adds a new *restriction* lint `iter_over_hash_type` which prevents `Hash`-types (that is, `HashSet` and `HashMap`) from being used as the iterator in `for` loops. The justification for this is because in `Hash`-based types, the ordering of items is not guaranteed and may vary between executions of the same program on the same hardware. In addition, it reduces readability due to the unclear iteration order. The implementation of this lint also ensures the following: - Calls to `HashMap::keys`, `HashMap::values`, and `HashSet::iter` are also denied when used in `for` loops, - When this expression is used in procedural macros, it is not linted/denied. changelog: add new `iter_over_hash_type` lint to prevent unordered iterations through hashed data structures
Diffstat (limited to 'clippy_lints/src/lib.rs')
| -rw-r--r-- | clippy_lints/src/lib.rs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 463f880aa8a..c462c933082 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -164,6 +164,7 @@ mod item_name_repetitions; mod items_after_statements; mod items_after_test_module; mod iter_not_returning_iterator; +mod iter_over_hash_type; mod iter_without_into_iter; mod large_const_arrays; mod large_enum_variant; @@ -1064,6 +1065,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { }); store.register_late_pass(move |_| Box::new(manual_hash_one::ManualHashOne::new(msrv()))); store.register_late_pass(|_| Box::new(iter_without_into_iter::IterWithoutIntoIter)); + store.register_late_pass(|_| Box::new(iter_over_hash_type::IterOverHashType)); // add lints here, do not remove this comment, it's used in `new_lint` } |
