Skip to content

Commit

Permalink
Use a function instead of a closure for the add_system_to_stage error…
Browse files Browse the repository at this point in the history
… path
  • Loading branch information
bjorn3 committed Apr 13, 2021
1 parent 31f8d87 commit e5ba919
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -144,14 +146,19 @@ impl Schedule {
stage_label: impl StageLabel,
system: impl Into<SystemDescriptor>,
) -> &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::<SystemStage>(&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
}
Expand Down

0 comments on commit e5ba919

Please sign in to comment.