Skip to content

Commit 39d71e2

Browse files
committed
Use a function instead of a closure for the add_system_to_stage error path
1 parent b1ed28e commit 39d71e2

File tree

1 file changed

+13
-6
lines changed
  • crates/bevy_ecs/src/schedule

1 file changed

+13
-6
lines changed

crates/bevy_ecs/src/schedule/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub use system_container::*;
2020
pub use system_descriptor::*;
2121
pub use system_set::*;
2222

23+
use std::fmt::Debug;
24+
2325
use crate::{
2426
system::{IntoSystem, System},
2527
world::World,
@@ -144,14 +146,19 @@ impl Schedule {
144146
stage_label: impl StageLabel,
145147
system: impl Into<SystemDescriptor>,
146148
) -> &mut Self {
149+
// Use a function instead of a closure to ensure that it is codegend inside bevy_ecs instead
150+
// of the game. Closures inherit generic parameters from their enclosing function.
151+
#[cold]
152+
fn stage_not_found(stage_label: &dyn Debug) -> ! {
153+
panic!(
154+
"Stage '{:?}' does not exist or is not a SystemStage",
155+
stage_label
156+
)
157+
}
158+
147159
let stage = self
148160
.get_stage_mut::<SystemStage>(&stage_label)
149-
.unwrap_or_else(move || {
150-
panic!(
151-
"Stage '{:?}' does not exist or is not a SystemStage",
152-
stage_label
153-
)
154-
});
161+
.unwrap_or_else(move || stage_not_found(&stage_label));
155162
stage.add_system(system);
156163
self
157164
}

0 commit comments

Comments
 (0)