TheBevyFlock / bevy_cli

A Bevy CLI tool and linter.
https://thebevyflock.github.io/bevy_cli/
Apache License 2.0
48 stars 7 forks source link

Lint for component aliasing rules (add `With`/`Without` bounds) #122

Open Rigidity opened 2 months ago

Rigidity commented 2 months ago

I believe there should be a lint to catch the scenario of having two or more queries which violate Rust's aliasing rules for components. I'd name it something like query_conflict and make it deny by default.

For example: query_1: Query<&mut A, With<B>>, query_2: Query<&mut A, With<C>>

Would give an error something like:

error: overlapping queries `query_1` and `query_2` both mutably borrow component `A`

help:

consider adding an explicit bound on `query_1`:
    query_1: Query<&mut A, (With<B>, Without<C>)>

or an explicit bound on `query_2`:
    query_2: Query<&mut A, (With<C>, Without<B>)>

to prevent accessing the same components in conflicting queries
janhohenheim commented 1 month ago

Isn't this already handled by Bevy natively via a runtime error?

BD103 commented 1 month ago

Isn't this already handled by Bevy natively via a runtime error?

I believe it is, which is why I've personally marked it as low priority. The reason you'd want a lint as well is for the Rust-Analyzer warning during development and the nice suggestion.

This is a nice to have feature, but probably shouldn't be worked on when more useful lints also need to be implemented. (Though I wouldn't object to someone else writing this lint in their own time! I'd still review it 😄)

janhohenheim commented 1 month ago

RA highlighting is a good point I haven't considered :)