diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 7f05afd221..75480468b0 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -20,6 +20,8 @@ pub use system_container::*; pub use system_descriptor::*; pub use system_set::*; +use std::fmt::Debug; + use crate::{ system::{IntoSystem, System}, world::World, @@ -144,14 +146,19 @@ impl Schedule { stage_label: impl StageLabel, system: impl Into, ) -> &mut Self { + // Use a function instead of a closure to ensure that it is codegend inside bevy_ecs instead + // of the game. Closures inherit generic parameters from their enclosing function. + #[cold] + fn stage_not_found(stage_label: &dyn Debug) -> ! { + panic!( + "Stage '{:?}' does not exist or is not a SystemStage", + stage_label + ) + } + let stage = self .get_stage_mut::(&stage_label) - .unwrap_or_else(move || { - panic!( - "Stage '{:?}' does not exist or is not a SystemStage", - stage_label - ) - }); + .unwrap_or_else(move || stage_not_found(&stage_label)); stage.add_system(system); self }