Skip to content

Commit 0910e47

Browse files
committed
Remove an outdated workaround for impl Trait (#5659)
# Objective Rust 1.63 resolved [an issue](rust-lang/rust#83701) that prevents you from combining explicit generic arguments with `impl Trait` arguments. Now, we no longer need to use dynamic dispatch to work around this. ## Migration Guide The methods `Schedule::get_stage` and `get_stage_mut` now accept `impl StageLabel` instead of `&dyn StageLabel`. ### Before ```rust let stage = schedule.get_stage_mut::<SystemStage>(&MyLabel)?; ``` ### After ```rust let stage = schedule.get_stage_mut::<SystemStage>(MyLabel)?; ```
1 parent aad2267 commit 0910e47

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

crates/bevy_ecs/src/schedule/mod.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ impl Schedule {
211211
)
212212
}
213213

214+
let label = stage_label.as_label();
214215
let stage = self
215-
.get_stage_mut::<SystemStage>(&stage_label)
216-
.unwrap_or_else(move || stage_not_found(&stage_label.as_label()));
216+
.get_stage_mut::<SystemStage>(label)
217+
.unwrap_or_else(move || stage_not_found(&label));
217218
stage.add_system(system);
218219
self
219220
}
@@ -278,14 +279,12 @@ impl Schedule {
278279
/// Panics if `label` refers to a non-existing stage, or if it's not of type `T`.
279280
pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
280281
&mut self,
281-
label: impl StageLabel,
282+
stage_label: impl StageLabel,
282283
func: F,
283284
) -> &mut Self {
284-
let stage = self.get_stage_mut::<T>(&label).unwrap_or_else(move || {
285-
panic!(
286-
"stage '{:?}' does not exist or is the wrong type",
287-
label.as_label()
288-
)
285+
let label = stage_label.as_label();
286+
let stage = self.get_stage_mut::<T>(label).unwrap_or_else(move || {
287+
panic!("stage '{label:?}' does not exist or is the wrong type",)
289288
});
290289
func(stage);
291290
self
@@ -304,11 +303,12 @@ impl Schedule {
304303
/// # let mut schedule = Schedule::default();
305304
/// # schedule.add_stage("my_stage", SystemStage::parallel());
306305
/// #
307-
/// let stage = schedule.get_stage::<SystemStage>(&"my_stage").unwrap();
306+
/// let stage = schedule.get_stage::<SystemStage>("my_stage").unwrap();
308307
/// ```
309-
pub fn get_stage<T: Stage>(&self, label: &dyn StageLabel) -> Option<&T> {
308+
pub fn get_stage<T: Stage>(&self, stage_label: impl StageLabel) -> Option<&T> {
309+
let label = stage_label.as_label();
310310
self.stages
311-
.get(&label.as_label())
311+
.get(&label)
312312
.and_then(|stage| stage.downcast_ref::<T>())
313313
}
314314

@@ -325,11 +325,12 @@ impl Schedule {
325325
/// # let mut schedule = Schedule::default();
326326
/// # schedule.add_stage("my_stage", SystemStage::parallel());
327327
/// #
328-
/// let stage = schedule.get_stage_mut::<SystemStage>(&"my_stage").unwrap();
328+
/// let stage = schedule.get_stage_mut::<SystemStage>("my_stage").unwrap();
329329
/// ```
330-
pub fn get_stage_mut<T: Stage>(&mut self, label: &dyn StageLabel) -> Option<&mut T> {
330+
pub fn get_stage_mut<T: Stage>(&mut self, stage_label: impl StageLabel) -> Option<&mut T> {
331+
let label = stage_label.as_label();
331332
self.stages
332-
.get_mut(&label.as_label())
333+
.get_mut(&label)
333334
.and_then(|stage| stage.downcast_mut::<T>())
334335
}
335336

crates/bevy_render/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl Plugin for RenderPlugin {
249249
// prepare
250250
let prepare = render_app
251251
.schedule
252-
.get_stage_mut::<SystemStage>(&RenderStage::Prepare)
252+
.get_stage_mut::<SystemStage>(RenderStage::Prepare)
253253
.unwrap();
254254
prepare.run(&mut render_app.world);
255255
}
@@ -262,7 +262,7 @@ impl Plugin for RenderPlugin {
262262
// queue
263263
let queue = render_app
264264
.schedule
265-
.get_stage_mut::<SystemStage>(&RenderStage::Queue)
265+
.get_stage_mut::<SystemStage>(RenderStage::Queue)
266266
.unwrap();
267267
queue.run(&mut render_app.world);
268268
}
@@ -275,7 +275,7 @@ impl Plugin for RenderPlugin {
275275
// phase sort
276276
let phase_sort = render_app
277277
.schedule
278-
.get_stage_mut::<SystemStage>(&RenderStage::PhaseSort)
278+
.get_stage_mut::<SystemStage>(RenderStage::PhaseSort)
279279
.unwrap();
280280
phase_sort.run(&mut render_app.world);
281281
}
@@ -288,7 +288,7 @@ impl Plugin for RenderPlugin {
288288
// render
289289
let render = render_app
290290
.schedule
291-
.get_stage_mut::<SystemStage>(&RenderStage::Render)
291+
.get_stage_mut::<SystemStage>(RenderStage::Render)
292292
.unwrap();
293293
render.run(&mut render_app.world);
294294
}
@@ -301,7 +301,7 @@ impl Plugin for RenderPlugin {
301301
// cleanup
302302
let cleanup = render_app
303303
.schedule
304-
.get_stage_mut::<SystemStage>(&RenderStage::Cleanup)
304+
.get_stage_mut::<SystemStage>(RenderStage::Cleanup)
305305
.unwrap();
306306
cleanup.run(&mut render_app.world);
307307
}
@@ -335,7 +335,7 @@ struct ScratchMainWorld(World);
335335
fn extract(app_world: &mut World, render_app: &mut App) {
336336
let extract = render_app
337337
.schedule
338-
.get_stage_mut::<SystemStage>(&RenderStage::Extract)
338+
.get_stage_mut::<SystemStage>(RenderStage::Extract)
339339
.unwrap();
340340

341341
// temporarily add the app world to the render world as a resource

0 commit comments

Comments
 (0)