Skip to content

Commit 0cd1cda

Browse files
Make Require an unsafe trait
Discourages users from implementing it themselves, since it is purely for documentation purposes. Co-Authored-By: JoshValjosh <[email protected]>
1 parent 0036f81 commit 0cd1cda

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/bevy_ecs/macros/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream {
220220
quote! {
221221
/// If not already present, the required component will be inserted using
222222
#[doc = #insertion_info]
223-
impl #impl_generics #bevy_ecs_path::component::Require<#path> for #struct_name #type_generics #where_clause {}
223+
unsafe impl #impl_generics #bevy_ecs_path::component::Require<#path> for #struct_name #type_generics #where_clause {}
224224
}
225225
});
226226

crates/bevy_ecs/src/component.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,13 @@ pub trait Component: Send + Sync + 'static {
456456
}
457457

458458
/// Indicates this [`Component`] requires another [`Component`] `C`.
459-
pub trait Require<C: Component>: Component {}
459+
/// This trait is similar to [`Eq`] in the sense that it is up to the implementer to ensure `C` is
460+
/// appropriately registered as a required component.
461+
///
462+
/// # Safety
463+
///
464+
/// Implementing this trait must be done in tandem with updating the implementation of [`Component::register_required_components`].
465+
pub unsafe trait Require<C: Component>: Component {}
460466

461467
mod private {
462468
pub trait Seal {}

0 commit comments

Comments
 (0)