forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make derived SystemParam readonly if possible (bevyengine#4650)
Required for bevyengine#4402. # Objective - derived `SystemParam` implementations were never `ReadOnlySystemParamFetch` - We want them to be, e.g. for `EventReader` ## Solution - If possible, 'forward' the impl of `ReadOnlySystemParamFetch`.
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
crates/bevy_ecs_compile_fail_tests/tests/ui/system_param_derive_readonly.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use bevy_ecs::prelude::*; | ||
use bevy_ecs::system::{ReadOnlySystemParamFetch, SystemParam, SystemState}; | ||
|
||
#[derive(Component)] | ||
struct Foo; | ||
|
||
#[derive(SystemParam)] | ||
struct Mutable<'w, 's> { | ||
a: Query<'w, 's, &'static mut Foo>, | ||
} | ||
|
||
fn main() { | ||
// Ideally we'd use: | ||
// let mut world = World::default(); | ||
// let state = SystemState::<Mutable>::new(&mut world); | ||
// state.get(&world); | ||
// But that makes the test show absolute paths | ||
assert_readonly::<Mutable>(); | ||
} | ||
|
||
fn assert_readonly<P: SystemParam>() | ||
where | ||
<P as SystemParam>::Fetch: ReadOnlySystemParamFetch, | ||
{ | ||
} |
25 changes: 25 additions & 0 deletions
25
crates/bevy_ecs_compile_fail_tests/tests/ui/system_param_derive_readonly.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
warning: unused import: `SystemState` | ||
--> tests/ui/system_param_derive_readonly.rs:2:63 | ||
| | ||
2 | use bevy_ecs::system::{ReadOnlySystemParamFetch, SystemParam, SystemState}; | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unused_imports)]` on by default | ||
|
||
error[E0277]: the trait bound `for<'x> WriteFetch<'x, Foo>: ReadOnlyFetch` is not satisfied | ||
--> tests/ui/system_param_derive_readonly.rs:18:5 | ||
| | ||
18 | assert_readonly::<Mutable>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'x> ReadOnlyFetch` is not implemented for `WriteFetch<'x, Foo>` | ||
| | ||
= note: required because of the requirements on the impl of `ReadOnlySystemParamFetch` for `QueryState<&'static mut Foo>` | ||
= note: 2 redundant requirements hidden | ||
= note: required because of the requirements on the impl of `ReadOnlySystemParamFetch` for `_::FetchState<(QueryState<&'static mut Foo>,)>` | ||
note: required by a bound in `assert_readonly` | ||
--> tests/ui/system_param_derive_readonly.rs:23:32 | ||
| | ||
21 | fn assert_readonly<P: SystemParam>() | ||
| --------------- required by a bound in this | ||
22 | where | ||
23 | <P as SystemParam>::Fetch: ReadOnlySystemParamFetch, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `assert_readonly` |