Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zst_query should not warn against Has<T> #279

Open
BD103 opened this issue Feb 22, 2025 · 0 comments
Open

zst_query should not warn against Has<T> #279

BD103 opened this issue Feb 22, 2025 · 0 comments
Labels
A-Linter Related to the linter and custom lints C-Bug A bug in the program D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes

Comments

@BD103
Copy link
Member

BD103 commented Feb 22, 2025

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.

@BD103 BD103 added A-Linter Related to the linter and custom lints C-Bug A bug in the program D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Related to the linter and custom lints C-Bug A bug in the program D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes
Projects
None yet
Development

No branches or pull requests

1 participant