Skip to content

Commit a7051a4

Browse files
Diagnostics for label traits (#17441)
# Objective Diagnostics for labels don't suggest how to best implement them. ``` error[E0277]: the trait bound `Label: ScheduleLabel` is not satisfied --> src/main.rs:15:35 | 15 | let mut sched = Schedule::new(Label); | ------------- ^^^^^ the trait `ScheduleLabel` is not implemented for `Label` | | | required by a bound introduced by this call | = help: the trait `ScheduleLabel` is implemented for `Interned<(dyn ScheduleLabel + 'static)>` note: required by a bound in `bevy_ecs::schedule::Schedule::new` --> /home/vj/workspace/rust/bevy/crates/bevy_ecs/src/schedule/schedule.rs:297:28 | 297 | pub fn new(label: impl ScheduleLabel) -> Self { | ^^^^^^^^^^^^^ required by this bound in `Schedule::new` ``` ## Solution `diagnostics::on_unimplemented` and `diagnostics::do_not_recommend` ## Showcase New error message: ``` error[E0277]: the trait bound `Label: ScheduleLabel` is not satisfied --> src/main.rs:15:35 | 15 | let mut sched = Schedule::new(Label); | ------------- ^^^^^ the trait `ScheduleLabel` is not implemented for `Label` | | | required by a bound introduced by this call | = note: consider annotating `Label` with `#[derive(ScheduleLabel)]` note: required by a bound in `bevy_ecs::schedule::Schedule::new` --> /home/vj/workspace/rust/bevy/crates/bevy_ecs/src/schedule/schedule.rs:297:28 | 297 | pub fn new(label: impl ScheduleLabel) -> Self { | ^^^^^^^^^^^^^ required by this bound in `Schedule::new` ```
1 parent ebbd961 commit a7051a4

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

crates/bevy_app/src/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ use std::{
3232

3333
bevy_ecs::define_label!(
3434
/// A strongly-typed class of labels used to identify an [`App`].
35+
#[diagnostic::on_unimplemented(
36+
note = "consider annotating `{Self}` with `#[derive(AppLabel)]`"
37+
)]
3538
AppLabel,
3639
APP_LABEL_INTERNER
3740
);

crates/bevy_ecs/src/schedule/set.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ use crate::{
2020

2121
define_label!(
2222
/// A strongly-typed class of labels used to identify a [`Schedule`](crate::schedule::Schedule).
23+
#[diagnostic::on_unimplemented(
24+
note = "consider annotating `{Self}` with `#[derive(ScheduleLabel)]`"
25+
)]
2326
ScheduleLabel,
2427
SCHEDULE_LABEL_INTERNER
2528
);
2629

2730
define_label!(
2831
/// Types that identify logical groups of systems.
32+
#[diagnostic::on_unimplemented(
33+
note = "consider annotating `{Self}` with `#[derive(SystemSet)]`"
34+
)]
2935
SystemSet,
3036
SYSTEM_SET_INTERNER,
3137
extra_methods: {

crates/bevy_render/src/render_graph/graph.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ use super::{EdgeExistence, InternedRenderLabel, IntoRenderNodeArray};
1414
pub use bevy_render_macros::RenderSubGraph;
1515

1616
define_label!(
17+
#[diagnostic::on_unimplemented(
18+
note = "consider annotating `{Self}` with `#[derive(RenderSubGraph)]`"
19+
)]
1720
/// A strongly-typed class of labels used to identify a [`SubGraph`] in a render graph.
1821
RenderSubGraph,
1922
RENDER_SUB_GRAPH_INTERNER

crates/bevy_render/src/render_graph/node.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub use bevy_render_macros::RenderLabel;
2323
use super::{InternedRenderSubGraph, RenderSubGraph};
2424

2525
define_label!(
26+
#[diagnostic::on_unimplemented(
27+
note = "consider annotating `{Self}` with `#[derive(RenderLabel)]`"
28+
)]
2629
/// A strongly-typed class of labels used to identify a [`Node`] in a render graph.
2730
RenderLabel,
2831
RENDER_LABEL_INTERNER

0 commit comments

Comments
 (0)