From e5ba91983924d4f3956a8c3ac4eebe3efc1d6976 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 13 Apr 2021 19:21:17 +0200 Subject: [PATCH] Use a function instead of a closure for the add_system_to_stage error path --- crates/bevy_ecs/src/schedule/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 7f05afd22171d8..75480468b0bfa3 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 }