Skip to content

zst_query should not warn against Has<T> #279

@BD103

Description

@BD103

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

No one assigned

    Labels

    A-LinterRelated to the linter and custom lintsC-BugA bug in the programD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixes

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions