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

Add lint: systems with conflicting queries #258

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

Add lint: systems with conflicting queries #258

BD103 opened this issue Feb 3, 2025 · 0 comments
Labels
A-Linter Related to the linter and custom lints C-Feature Make something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help!

Comments

@BD103
Copy link
Member

BD103 commented Feb 3, 2025

Bevy does not let systems break Rust's mutability rules, and will panic if two queries overlap:

// Will panic: an entity could have both `Player` and `Enemy` components.
fn randomize_health(
    player_query: Query<&mut Health, With<Player>>,
    enemy_query: Query<&mut Health, With<Enemy>>,
) {
    // ...
}

Due to limitations in Rust and how Bevy is architected, conflicts are a runtime error and not a compile-time error.

To provide a better development experience, the linter should error against conflicting queries. Query conflicts are computed with the private assert_component_access_compatibility() function, so we may also be able steal permanently borrow some logic from that.

@BD103 BD103 added A-Linter Related to the linter and custom lints C-Feature Make something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help! labels Feb 3, 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-Feature Make something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help!
Projects
Status: Todo
Development

No branches or pull requests

1 participant