Skip to content

Commit ec7b349

Browse files
alice-i-cecilebushrat011899ThemayuBD103
authored
Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662)
# Objective - #13414 did not have the intended effect. - #13404 is still blocked ## Solution - Re-adds #13347. Co-authored-by: Zachary Harrold <[email protected]> Co-authored-by: Jamie Ridding <[email protected]> Co-authored-by: BD103 <[email protected]>
1 parent 37cc8ea commit ec7b349

File tree

30 files changed

+129
-12
lines changed

30 files changed

+129
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/bevyengine/bevy"
1212
documentation = "https://docs.rs/bevy"
13-
rust-version = "1.77.0"
13+
rust-version = "1.78.0"
1414

1515
[workspace]
1616
exclude = [

crates/bevy_app/src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use std::any::Any;
5454
/// }
5555
/// }
5656
/// # fn damp_flickering() {}
57-
/// ````
57+
/// ```
5858
pub trait Plugin: Downcast + Any + Send + Sync {
5959
/// Configures the [`App`] to which this plugin is added.
6060
fn build(&self, app: &mut App);

crates/bevy_asset/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ impl Plugin for AssetPlugin {
227227
}
228228
}
229229

230+
#[diagnostic::on_unimplemented(
231+
message = "`{Self}` is not an `Asset`",
232+
label = "invalid `Asset`",
233+
note = "consider annotating `{Self}` with `#[derive(Asset)]`"
234+
)]
230235
pub trait Asset: VisitAssetDependencies + TypePath + Send + Sync + 'static {}
231236

232237
pub trait VisitAssetDependencies {

crates/bevy_ecs/src/bundle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ use std::ptr::NonNull;
141141
// bundle, in the _exact_ order that [`DynamicBundle::get_components`] is called.
142142
// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by
143143
// [`Bundle::component_ids`].
144+
#[diagnostic::on_unimplemented(
145+
message = "`{Self}` is not a `Bundle`",
146+
label = "invalid `Bundle`",
147+
note = "consider annotating `{Self}` with `#[derive(Component)]` or `#[derive(Bundle)]`"
148+
)]
144149
pub unsafe trait Bundle: DynamicBundle + Send + Sync + 'static {
145150
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
146151
#[doc(hidden)]

crates/bevy_ecs/src/component.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ use std::{
151151
///
152152
/// [`SyncCell`]: bevy_utils::synccell::SyncCell
153153
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
154+
#[diagnostic::on_unimplemented(
155+
message = "`{Self}` is not a `Component`",
156+
label = "invalid `Component`",
157+
note = "consider annotating `{Self}` with `#[derive(Component)]`"
158+
)]
154159
pub trait Component: Send + Sync + 'static {
155160
/// A constant indicating the storage type used for this component.
156161
const STORAGE_TYPE: StorageType;

crates/bevy_ecs/src/entity/map_entities.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use super::EntityHashMap;
3737
/// }
3838
/// }
3939
/// ```
40-
///
4140
pub trait MapEntities {
4241
/// Updates all [`Entity`] references stored inside using `entity_mapper`.
4342
///

crates/bevy_ecs/src/event.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ use std::{
2828
/// You can conveniently access events using the [`EventReader`] and [`EventWriter`] system parameter.
2929
///
3030
/// Events must be thread-safe.
31+
#[diagnostic::on_unimplemented(
32+
message = "`{Self}` is not an `Event`",
33+
label = "invalid `Event`",
34+
note = "consider annotating `{Self}` with `#[derive(Event]`"
35+
)]
3136
pub trait Event: Send + Sync + 'static {}
3237

3338
/// An `EventId` uniquely identifies an event stored in a specific [`World`].

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ use std::{cell::UnsafeCell, marker::PhantomData};
268268
///
269269
/// [`Query`]: crate::system::Query
270270
/// [`ReadOnly`]: Self::ReadOnly
271+
#[diagnostic::on_unimplemented(
272+
message = "`{Self}` is not valid to request as data in a `Query`",
273+
label = "invalid `Query` data"
274+
)]
271275
pub unsafe trait QueryData: WorldQuery {
272276
/// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.
273277
type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;

crates/bevy_ecs/src/query/filter.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ use std::{cell::UnsafeCell, marker::PhantomData};
7070
/// [`matches_component_set`]: Self::matches_component_set
7171
/// [`Query`]: crate::system::Query
7272
/// [`State`]: Self::State
73-
73+
#[diagnostic::on_unimplemented(
74+
message = "`{Self}` is not a valid `Query` filter",
75+
label = "invalid `Query` filter",
76+
note = "a `QueryFilter` typically uses a combination of `With<T>` and `Without<T>` statements"
77+
)]
7478
pub trait QueryFilter: WorldQuery {
7579
/// Returns true if (and only if) this Filter relies strictly on archetypes to limit which
7680
/// components are accessed by the Query.
@@ -942,6 +946,11 @@ impl<T: Component> QueryFilter for Changed<T> {
942946
///
943947
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
944948
/// they do not implement [`ArchetypeFilter`].
949+
#[diagnostic::on_unimplemented(
950+
message = "`{Self}` is not a valid `Query` filter based on archetype information",
951+
label = "invalid `Query` filter",
952+
note = "an `ArchetypeFilter` typically uses a combination of `With<T>` and `Without<T>` statements"
953+
)]
945954
pub trait ArchetypeFilter: QueryFilter {}
946955

947956
impl<T: Component> ArchetypeFilter for With<T> {}

crates/bevy_ecs/src/schedule/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ impl<T> NodeConfigs<T> {
288288
/// )
289289
/// );
290290
/// ```
291+
#[diagnostic::on_unimplemented(
292+
message = "`{Self}` does not describe a valid system configuration",
293+
label = "invalid system configuration"
294+
)]
291295
pub trait IntoSystemConfigs<Marker>
292296
where
293297
Self: Sized,
@@ -562,6 +566,10 @@ impl SystemSetConfig {
562566
pub type SystemSetConfigs = NodeConfigs<InternedSystemSet>;
563567

564568
/// Types that can convert into a [`SystemSetConfigs`].
569+
#[diagnostic::on_unimplemented(
570+
message = "`{Self}` does not describe a valid system set configuration",
571+
label = "invalid system set configuration"
572+
)]
565573
pub trait IntoSystemSetConfigs
566574
where
567575
Self: Sized,

0 commit comments

Comments
 (0)