Skip to content

Commit 4bc4f45

Browse files
committed
turn check into explicit assert fn
1 parent 3d3577b commit 4bc4f45

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use crate::{
66
query::{Access, FilteredAccessSet},
77
schedule::{SystemLabel, SystemLabelId},
88
system::{
9-
check_system_change_tick, MaybeUnsafeCell, ReadOnlySystemParamFetch, System, SystemParam,
10-
SystemParamFetch, SystemParamItem, SystemParamState, WorldAccessLevel,
9+
assert_valid_world_access_level, check_system_change_tick, MaybeUnsafeCell,
10+
ReadOnlySystemParamFetch, System, SystemParam, SystemParamFetch, SystemParamItem,
11+
SystemParamState, WorldAccessLevel,
1112
},
1213
world::{World, WorldId},
1314
};
@@ -140,7 +141,7 @@ pub struct SystemState<Param: SystemParam> {
140141

141142
impl<Param: SystemParam> SystemState<Param> {
142143
pub fn new(world: &mut World) -> Self {
143-
let _ = <Param::Fetch as SystemParamState>::world_access_level();
144+
assert_valid_world_access_level::<Param>();
144145
let mut meta = SystemMeta::new::<Param>();
145146
meta.last_change_tick = world.change_tick().wrapping_sub(MAX_CHANGE_AGE);
146147
let param_state = <Param::Fetch as SystemParamState>::init(world, &mut meta);
@@ -335,7 +336,7 @@ where
335336
{
336337
type System = FunctionSystem<In, Out, Param, Marker, F>;
337338
fn into_system(func: Self) -> Self::System {
338-
let _ = <Param::Fetch as SystemParamState>::world_access_level();
339+
assert_valid_world_access_level::<Param>();
339340
FunctionSystem {
340341
func,
341342
param_state: None,

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ pub enum WorldAccessLevel {
2626
Exclusive,
2727
}
2828

29+
/// Asserts that a given [`SystemParam`] (or tuple) has a valid [`WorldAccessLevel`].
30+
pub fn assert_valid_world_access_level<Params: SystemParam>() {
31+
// this will panic on params/tuples whose fields/members have conflicting access levels
32+
let _ = <Params::Fetch as SystemParamState>::world_access_level();
33+
}
34+
2935
/// A parameter that can be used in a [`System`](super::System).
3036
///
3137
/// # Derive

0 commit comments

Comments
 (0)