Expand description
Checks for queries that query the data for a zero-sized type.
§Motivation
Zero-sized types (ZSTs) are types that have no size because they contain no runtime data. Any information they may hold is known at compile-time in the form of constant generics, which do not need to be queried. As such, ZSTs are better used as query filters instead of query data.
§Known Issues
This lint raises false positives on queries like Has<T>
and AnyOf<T>
because they are ZSTs,
even though they still retrieve data from the ECS. Please see #279 for more information.
§Example
// This is a zero-sized type, sometimes known as a "marker component".
#[derive(Component)]
struct Player;
fn move_player(mut query: Query<(&mut Transform, &Player)>) {
for (transform, _) in query.iter_mut() {
// ...
}
}
Use instead:
#[derive(Component)]
struct Player;
fn move_player(mut query: Query<&mut Transform, With<Player>>) {
for transform in query.iter_mut() {
// ...
}
}
Structs§
Statics§
- ZST_
QUERY - Click me for more information.