Check for conflicting accesses in assert_is_system
#8154
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
The function
assert_is_system
is used in documentation tests to ensure that example code actually produces valid systems. Currently,assert_is_system
just checks that each function parameter implementsSystemParam
. To further check the validity of the system, we should initialize the passed system so that it will be checked for conflicting accesses. Not only does this enforce the validity of our examples, but it provides a convenient way to demonstrate conflicting accesses via ashould_panic
example, which is nicely rendered by rustdoc:Solution
Initialize the system with an empty world to trigger its internal access conflict checks.
Changelog
The function
bevy::ecs::system::assert_is_system
now panics when passed a system with conflicting world accesses, as doesassert_is_read_only_system
.Migration Guide
The functions
assert_is_system
andassert_is_read_only_system
(inbevy_ecs::system
) now panic if the passed system has invalid world accesses. Any tests that called this function on a system with invalid accesses will now fail. Either fix the system's conflicting accesses, or specify that the test is meant to fail:#[test]
), add the#[should_panic]
attribute to the function.should_panic
to the start of the code block:```should_panic