-
Notifications
You must be signed in to change notification settings - Fork 33
Labels
A-LinterRelated to the linter and custom lintsRelated to the linter and custom lintsC-BugA bug in the programA bug in the programD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixes
Description
Has<T> is a zero-sized type that should not be made a query filter. This is because <Has<T> as QueryData>::Item is a bool. See the following example:
// `Has<Name>`'s size is 0.
fn my_system(query: Query<Has<Name>>) {
// `has_name` is a boolean.
for has_name in query {
assert!(has_name);
}
}Though Has<T> is a ZST because it just contains a PhantomData<T>, when queried, it returns a boolean. This exposes an underlying flaw in zst_query:
The size of the QueryData should not affect the lint, instead the size of the data fetched by that QueryData is what matters. zst_query should look at QueryData::Item, not QueryData itself.
As an extra bonus, zst_query should consider if the type implements QueryFilter before suggesting it be used as a filter instead!
For now, zst_query should remain in nursery until this is addressed.
Metadata
Metadata
Assignees
Labels
A-LinterRelated to the linter and custom lintsRelated to the linter and custom lintsC-BugA bug in the programA bug in the programD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixes