Skip to content

Commit

Permalink
Diagnostics for label traits (#17441)
Browse files Browse the repository at this point in the history
# 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`
```
  • Loading branch information
SpecificProtagonist authored Jan 20, 2025
1 parent ebbd961 commit a7051a4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ use std::{

bevy_ecs::define_label!(
/// A strongly-typed class of labels used to identify an [`App`].
#[diagnostic::on_unimplemented(
note = "consider annotating `{Self}` with `#[derive(AppLabel)]`"
)]
AppLabel,
APP_LABEL_INTERNER
);
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/schedule/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ use crate::{

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

define_label!(
/// Types that identify logical groups of systems.
#[diagnostic::on_unimplemented(
note = "consider annotating `{Self}` with `#[derive(SystemSet)]`"
)]
SystemSet,
SYSTEM_SET_INTERNER,
extra_methods: {
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_render/src/render_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use super::{EdgeExistence, InternedRenderLabel, IntoRenderNodeArray};
pub use bevy_render_macros::RenderSubGraph;

define_label!(
#[diagnostic::on_unimplemented(
note = "consider annotating `{Self}` with `#[derive(RenderSubGraph)]`"
)]
/// A strongly-typed class of labels used to identify a [`SubGraph`] in a render graph.
RenderSubGraph,
RENDER_SUB_GRAPH_INTERNER
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_render/src/render_graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub use bevy_render_macros::RenderLabel;
use super::{InternedRenderSubGraph, RenderSubGraph};

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

0 comments on commit a7051a4

Please sign in to comment.