mirror of
https://github.com/bevyengine/bevy
synced 2024-12-21 18:43:07 +00:00
4f212a5b0c
# Objective The latest `clippy` release has a much more aggressive application of the [`explicit_iter_loop`](https://rust-lang.github.io/rust-clippy/master/index.html#/explicit_into_iter_loop?groups=pedantic) pedantic lint. As a result, clippy now suggests the following: ```diff -for event in events.iter() { +for event in &mut events { ``` I'm generally in favor of this lint. Using `for mut item in &mut query` is also recommended over `for mut item in query.iter_mut()` for good reasons IMO. But, it is my personal belief that `&mut events` is much less clear than `events.iter()`. Why? The reason is that the events from `EventReader` **are not mutable**, they are immutable references to each event in the event reader. `&mut events` suggests we are getting mutable access to events — similarly to `&mut query` — which is not the case. Using `&mut events` is therefore misleading. `IntoIterator` requires a mutable `EventReader` because it updates the internal `last_event_count`, not because it let you mutate it. So clippy's suggested improvement is a downgrade. ## Solution Do not implement `IntoIterator` for `&mut events`. Without the impl, clippy won't suggest its "fix". This also prevents generally people from using `&mut events` for iterating `EventReader`s, which makes the ecosystem every-so-slightly better. --- ## Changelog - Removed `IntoIterator` impl for `&mut EventReader` ## Migration Guide - `&mut EventReader` does not implement `IntoIterator` anymore. replace `for foo in &mut events` by `for foo in events.iter()` |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_dynamic_plugin | ||
bevy_ecs | ||
bevy_ecs_compile_fail_tests | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_macros_compile_fail_tests | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_reflect_compile_fail_tests | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |