bevy/crates/bevy_ecs/compile_fail
Chris Russell 6df711ce7f
Fix unsound lifetimes in Query::join and Query::join_filtered (#17972)
# Objective

Fix unsound lifetimes in `Query::join` and `Query::join_filtered`.  

The joined query allowed access from either input query, but it only
took the `'world` lifetime from `self`, not from `other`. This meant
that after the borrow of `other` ended, the joined query would unsoundly
alias `other`.

## Solution

Change the lifetimes on `join` and `join_filtered` to require mutable
borrows of the *same* lifetime for the input queries. This ensures both
input queries are borrowed for the full lifetime of the joined query.

Change `join_inner` to take `other` by value instead of reference so
that the returned query is still usable without needing to borrow from a
local variable.

## Testing

Added a compile-fail test.
2025-03-10 21:30:34 +00:00
..
src Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
tests Fix unsound lifetimes in Query::join and Query::join_filtered (#17972) 2025-03-10 21:30:34 +00:00
.gitignore Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00
Cargo.toml Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
README.md Move compile fail tests (#13196) 2024-05-03 13:35:21 +00:00

Compile fail tests for bevy_ecs

This crate is separate from bevy_ecs and not part of the Bevy workspace in order to not fail crater tests for Bevy. The tests assert on the exact compiler errors and can easily fail for new Rust versions due to updated compiler errors (e.g. changes in spans).

The CI workflow executes these tests on the stable rust toolchain (see tools/ci).

For information on writing tests see compile_fail_utils/README.md.