From dfdd6bf0ec98dc0ae78dfa2e5d953116d2d596f7 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 28 Dec 2022 23:24:09 -0500 Subject: [PATCH] implement unconditionally read-only params --- crates/bevy_ecs/macros/src/lib.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index 8dbadc4393069..5006196d0bb3d 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -518,7 +518,21 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream { {} } } - ParamAccess::ReadOnly => todo!(), + ParamAccess::ReadOnly => { + quote! { + fn __assert_field_is_read_only_system_param() {} + fn __assert_each_field_is_read_only_system_param #impl_generics () #where_clause { + #( + __assert_field_is_read_only_system_param::<#field_types>(); + )* + } + + // SAFETY: The above code will cause a compile error if each field does not implement `ReadOnlySystemParam`. + // Since each field is `ReadOnlySystemParam`, this can only read from the `World` + unsafe impl #impl_generics #path::system::ReadOnlySystemParam for #struct_name #ty_generics #where_clause + {} + } + } ParamAccess::Mutable => quote! {}, };