Repository: bevyengine/bevy
File: crates/bevy_ecs/src/message/message_reader.rs (Rust)

Code before:
unsafe impl<'w, 's, M: Message> SystemParam for PopulatedMessageReader<'w, 's, M> {
    type State = <MessageReader<'w, 's, M> as SystemParam>::State;
    type Item<'world, 'state> = PopulatedMessageReader<'world, 'state, M>;

    fn init_state(world: &mut crate::prelude::World) -> Self::State {
        MessageReader::<M>::init_state(world)
    }

    fn init_access(
        state: &Self::State,
        system_meta: &mut crate::system::SystemMeta,
        component_access_set: &mut crate::query::FilteredAccessSet,
        world: &mut crate::prelude::World,
    ) {
        MessageReader::<M>::init_access(state, system_meta, component_access_set, world);
    }

    unsafe fn get_param<'world, 'state>(
        state: &'state mut Self::State,
        system_meta: &crate::system::SystemMeta,
        world: crate::world::unsafe_world_cell::UnsafeWorldCell<'world>,
        change_tick: crate::change_detection::Tick,
    ) -> Self::Item<'world, 'state> {
        // SAFETY: requirements are upheld by MessageReader's implementation
        unsafe {
            PopulatedMessageReader::<'world, 'state, M>(MessageReader::<M>::get_param(
                state,
                system_meta,
                world,
                change_tick,
            ))
        }
    }

    unsafe fn validate_param(
        state: &mut Self::State,
        system_meta: &crate::system::SystemMeta,
        world: crate::world::unsafe_world_cell::UnsafeWorldCell,
    ) -> Result<(), SystemParamValidationError> {
        // SAFETY: requirements are upheld by MessageReader's implementation
        unsafe { MessageReader::<M>::validate_param(state, system_meta, world) }?;

        let cursor = state.state.0.get();

        // SAFETY: this access is registered in MessageReader's `init_access`
        let messages = unsafe { world.get_resource::<Messages<M>>() }
            .expect("missing message queue just after system param was validated");

        if cursor.is_empty(messages) {
            Err(SystemParamValidationError::skipped::<Self>(
                "message queue is empty",

Review comment (suggestion):
I bet the compiler can infer these parameters from the return type.

```suggestion
            PopulatedMessageReader(MessageReader::<M>::get_param(
```

Code after:
unsafe impl<'w, 's, M: Message> SystemParam for PopulatedMessageReader<'w, 's, M> {
    type State = <MessageReader<'w, 's, M> as SystemParam>::State;
    type Item<'world, 'state> = PopulatedMessageReader<'world, 'state, M>;

    fn init_state(world: &mut crate::prelude::World) -> Self::State {
        MessageReader::<M>::init_state(world)
    }

    fn init_access(
        state: &Self::State,
        system_meta: &mut crate::system::SystemMeta,
        component_access_set: &mut crate::query::FilteredAccessSet,
        world: &mut crate::prelude::World,
    ) {
        MessageReader::<M>::init_access(state, system_meta, component_access_set, world);
    }

    unsafe fn get_param<'world, 'state>(
        state: &'state mut Self::State,
        system_meta: &crate::system::SystemMeta,
        world: crate::world::unsafe_world_cell::UnsafeWorldCell<'world>,
        change_tick: crate::change_detection::Tick,
    ) -> Self::Item<'world, 'state> {
        // SAFETY: requirements are upheld by MessageReader's implementation
        unsafe {
            PopulatedMessageReader(MessageReader::get_param(
                state,
                system_meta,
                world,
                change_tick,
            ))
        }
    }

    unsafe fn validate_param(
        state: &mut Self::State,
        system_meta: &crate::system::SystemMeta,
        world: crate::world::unsafe_world_cell::UnsafeWorldCell,
    ) -> Result<(), SystemParamValidationError> {
        // SAFETY: requirements are upheld by MessageReader's implementation
        unsafe { MessageReader::<M>::validate_param(state, system_meta, world) }?;

        // SAFETY: requirements are upheld by MessageReader's implementation
        let reader =
            unsafe { MessageReader::get_param(state, system_meta, world, world.change_tick()) };
        if reader.is_empty() {
            Err(SystemParamValidationError::skipped::<Self>(
                "message queue is empty",
            ))
        } else {
            Ok(())