Repository: bevyengine/bevy
File: crates/bevy_ecs/src/system/builder.rs (Rust)

Code before:
            BuilderSystemInner::Initialized { system, .. } => system.apply_deferred(world),
            BuilderSystemInner::Uninitialized { .. } => {}
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    fn queue_deferred(&mut self, world: DeferredWorld) {
        match &mut self.inner {
            BuilderSystemInner::Initialized { system, .. } => system.queue_deferred(world),
            BuilderSystemInner::Uninitialized { .. } => {}
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    unsafe fn validate_param_unsafe(
        &mut self,
        world: UnsafeWorldCell,
    ) -> Result<(), SystemParamValidationError> {
        match &mut self.inner {
            // SAFETY: requirements upheld by the caller.
            BuilderSystemInner::Initialized { system, .. } => unsafe {
                system.validate_param_unsafe(world)
            },
            BuilderSystemInner::Uninitialized { .. } => Ok(()),
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    fn initialize(&mut self, world: &mut World) -> FilteredAccessSet {
        let inner = mem::replace(&mut self.inner, BuilderSystemInner::Invalid);
        match inner {
            BuilderSystemInner::Initialized { mut system } => {
                let access = system.initialize(world);
                self.inner = BuilderSystemInner::Initialized { system };
                access
            }
            BuilderSystemInner::Uninitialized { builder, func, .. } => {
                let mut system = builder.build_state(world).build_any_system(func);
                let access = system.initialize(world);
                self.inner = BuilderSystemInner::Initialized { system };
                access
            }
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    fn check_change_tick(&mut self, check: CheckChangeTicks) {

Review comment (suggestion):
I think would expect this to be a panic similar to `run_unsafe()` because an uninitialized system cannot have its parameters validated IIUC. Is there a reason why this is `Ok(())` here instead? Just trying to learn more :) 

Code after:
        input: super::SystemIn<'_, Self>,
        world: UnsafeWorldCell,
    ) -> Result<Self::Out, RunSystemError> {
        match &mut self.inner {
            // SAFETY: requirements upheld by the caller.
            BuilderSystemInner::Initialized { system, .. } => unsafe {
                system.run_unsafe(input, world)
            },
            BuilderSystemInner::Uninitialized { .. } => panic!(
                "BuilderSystem {} was not initialized before calling run_unsafe.",
                self.name()
            ),
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[cfg(feature = "hotpatching")]
    #[inline]
    fn refresh_hotpatch(&mut self) {
        match &mut self.inner {
            BuilderSystemInner::Initialized { system, .. } => system.refresh_hotpatch(),
            BuilderSystemInner::Uninitialized { .. } => {}
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    fn apply_deferred(&mut self, world: &mut World) {
        match &mut self.inner {
            BuilderSystemInner::Initialized { system, .. } => system.apply_deferred(world),
            BuilderSystemInner::Uninitialized { .. } => {}
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    fn queue_deferred(&mut self, world: DeferredWorld) {
        match &mut self.inner {
            BuilderSystemInner::Initialized { system, .. } => system.queue_deferred(world),
            BuilderSystemInner::Uninitialized { .. } => {}
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]
    unsafe fn validate_param_unsafe(
        &mut self,
        world: UnsafeWorldCell,
    ) -> Result<(), SystemParamValidationError> {
        match &mut self.inner {
            // SAFETY: requirements upheld by the caller.