mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
Add on_unimplemented
Diagnostics to Most Public Traits (#13347)
# Objective - Fixes #12377 ## Solution Added simple `#[diagnostic::on_unimplemented(...)]` attributes to some critical public traits providing a more approachable initial error message. Where appropriate, a `note` is added indicating that a `derive` macro is available. ## Examples <details> <summary>Examples hidden for brevity</summary> Below is a collection of examples showing the new error messages produced by this change. In general, messages will start with a more Bevy-centric error message (e.g., _`MyComponent` is not a `Component`_), and a note directing the user to an available derive macro where appropriate. ### Missing `#[derive(Resource)]` <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; struct MyResource; fn main() { App::new() .insert_resource(MyResource) .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `MyResource` is not a `Resource` --> examples/app/empty.rs:7:26 | 7 | .insert_resource(MyResource) | --------------- ^^^^^^^^^^ invalid `Resource` | | | required by a bound introduced by this call | = help: the trait `Resource` is not implemented for `MyResource` = note: consider annotating `MyResource` with `#[derive(Resource)]` = help: the following other types implement trait `Resource`: AccessibilityRequested ManageAccessibilityUpdates bevy::bevy_a11y::Focus DiagnosticsStore FrameCount bevy::prelude::State<S> SystemInfo bevy::prelude::Axis<T> and 141 others note: required by a bound in `bevy::prelude::App::insert_resource` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_app\src\app.rs:419:31 | 419 | pub fn insert_resource<R: Resource>(&mut self, resource: R) -> &mut Self { | ^^^^^^^^ required by this bound in `App::insert_resource` ``` </details> ### Putting A `QueryData` in a `QueryFilter` Slot <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; #[derive(Component)] struct A; #[derive(Component)] struct B; fn my_system(_query: Query<&A, &B>) {} fn main() { App::new() .add_systems(Update, my_system) .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `&B` is not a valid `Query` filter --> examples/app/empty.rs:9:22 | 9 | fn my_system(_query: Query<&A, &B>) {} | ^^^^^^^^^^^^^ invalid `Query` filter | = help: the trait `QueryFilter` is not implemented for `&B` = help: the following other types implement trait `QueryFilter`: With<T> Without<T> bevy::prelude::Or<()> bevy::prelude::Or<(F0,)> bevy::prelude::Or<(F0, F1)> bevy::prelude::Or<(F0, F1, F2)> bevy::prelude::Or<(F0, F1, F2, F3)> bevy::prelude::Or<(F0, F1, F2, F3, F4)> and 28 others note: required by a bound in `bevy::prelude::Query` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_ecs\src\system\query.rs:349:51 | 349 | pub struct Query<'world, 'state, D: QueryData, F: QueryFilter = ()> { | ^^^^^^^^^^^ required by this bound in `Query` ``` </details> ### Missing `#[derive(Component)]` <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; struct A; fn my_system(mut commands: Commands) { commands.spawn(A); } fn main() { App::new() .add_systems(Startup, my_system) .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `A` is not a `Bundle` --> examples/app/empty.rs:6:20 | 6 | commands.spawn(A); | ----- ^ invalid `Bundle` | | | required by a bound introduced by this call | = help: the trait `bevy::prelude::Component` is not implemented for `A`, which is required by `A: Bundle` = note: consider annotating `A` with `#[derive(Component)]` or `#[derive(Bundle)]` = help: the following other types implement trait `Bundle`: TransformBundle SceneBundle DynamicSceneBundle AudioSourceBundle<Source> SpriteBundle SpriteSheetBundle Text2dBundle MaterialMesh2dBundle<M> and 34 others = note: required for `A` to implement `Bundle` note: required by a bound in `bevy::prelude::Commands::<'w, 's>::spawn` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_ecs\src\system\commands\mod.rs:243:21 | 243 | pub fn spawn<T: Bundle>(&mut self, bundle: T) -> EntityCommands { | ^^^^^^ required by this bound in `Commands::<'w, 's>::spawn` ``` </details> ### Missing `#[derive(Asset)]` <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; struct A; fn main() { App::new() .init_asset::<A>() .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `A` is not an `Asset` --> examples/app/empty.rs:7:23 | 7 | .init_asset::<A>() | ---------- ^ invalid `Asset` | | | required by a bound introduced by this call | = help: the trait `Asset` is not implemented for `A` = note: consider annotating `A` with `#[derive(Asset)]` = help: the following other types implement trait `Asset`: Font AnimationGraph DynamicScene Scene AudioSource Pitch bevy::bevy_gltf::Gltf GltfNode and 17 others note: required by a bound in `init_asset` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_asset\src\lib.rs:307:22 | 307 | fn init_asset<A: Asset>(&mut self) -> &mut Self; | ^^^^^ required by this bound in `AssetApp::init_asset` ``` </details> ### Mismatched Input and Output on System Piping <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; fn producer() -> u32 { 123 } fn consumer(_: In<u16>) {} fn main() { App::new() .add_systems(Update, producer.pipe(consumer)) .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `fn(bevy::prelude::In<u16>) {consumer}` is not a valid system with input `u32` and output `_` --> examples/app/empty.rs:11:44 | 11 | .add_systems(Update, producer.pipe(consumer)) | ---- ^^^^^^^^ invalid system | | | required by a bound introduced by this call | = help: the trait `bevy::prelude::IntoSystem<u32, _, _>` is not implemented for fn item `fn(bevy::prelude::In<u16>) {consumer}` = note: expecting a system which consumes `u32` and produces `_` note: required by a bound in `pipe` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_ecs\src\system\mod.rs:168:12 | 166 | fn pipe<B, Final, MarkerB>(self, system: B) -> PipeSystem<Self::System, B::System> | ---- required by a bound in this associated function 167 | where 168 | B: IntoSystem<Out, Final, MarkerB>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `IntoSystem::pipe` ``` </details> ### Missing Reflection <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; #[derive(Component)] struct MyComponent; fn main() { App::new() .register_type::<MyComponent>() .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `MyComponent` does not provide type registration information --> examples/app/empty.rs:8:26 | 8 | .register_type::<MyComponent>() | ------------- ^^^^^^^^^^^ the trait `GetTypeRegistration` is not implemented for `MyComponent` | | | required by a bound introduced by this call | = note: consider annotating `MyComponent` with `#[derive(Reflect)]` = help: the following other types implement trait `GetTypeRegistration`: bool char isize i8 i16 i32 i64 i128 and 443 others note: required by a bound in `bevy::prelude::App::register_type` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_app\src\app.rs:619:29 | 619 | pub fn register_type<T: bevy_reflect::GetTypeRegistration>(&mut self) -> &mut Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `App::register_type` ``` </details> ### Missing `#[derive(States)]` Implementation <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; #[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash)] enum AppState { #[default] Menu, InGame { paused: bool, turbo: bool, }, } fn main() { App::new() .init_state::<AppState>() .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: the trait bound `AppState: FreelyMutableState` is not satisfied --> examples/app/empty.rs:15:23 | 15 | .init_state::<AppState>() | ---------- ^^^^^^^^ the trait `FreelyMutableState` is not implemented for `AppState` | | | required by a bound introduced by this call | = note: consider annotating `AppState` with `#[derive(States)]` note: required by a bound in `bevy::prelude::App::init_state` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_app\src\app.rs:282:26 | 282 | pub fn init_state<S: FreelyMutableState + FromWorld>(&mut self) -> &mut Self { | ^^^^^^^^^^^^^^^^^^ required by this bound in `App::init_state` ``` </details> ### Adding a `System` with Unhandled Output <details> <summary>Example Code</summary> ```rust use bevy::prelude::*; fn producer() -> u32 { 123 } fn main() { App::new() .add_systems(Update, consumer) .run(); } ``` </details> <details> <summary>Error Generated</summary> ```error error[E0277]: `fn() -> u32 {producer}` does not describe a valid system configuration --> examples/app/empty.rs:9:30 | 9 | .add_systems(Update, producer) | ----------- ^^^^^^^^ invalid system configuration | | | required by a bound introduced by this call | = help: the trait `IntoSystem<(), (), _>` is not implemented for fn item `fn() -> u32 {producer}`, which is required by `fn() -> u32 {producer}: IntoSystemConfigs<_>` = help: the following other types implement trait `IntoSystemConfigs<Marker>`: <Box<(dyn bevy::prelude::System<In = (), Out = ()> + 'static)> as IntoSystemConfigs<()>> <NodeConfigs<Box<(dyn bevy::prelude::System<In = (), Out = ()> + 'static)>> as IntoSystemConfigs<()>> <(S0,) as IntoSystemConfigs<(SystemConfigTupleMarker, P0)>> <(S0, S1) as IntoSystemConfigs<(SystemConfigTupleMarker, P0, P1)>> <(S0, S1, S2) as IntoSystemConfigs<(SystemConfigTupleMarker, P0, P1, P2)>> <(S0, S1, S2, S3) as IntoSystemConfigs<(SystemConfigTupleMarker, P0, P1, P2, P3)>> <(S0, S1, S2, S3, S4) as IntoSystemConfigs<(SystemConfigTupleMarker, P0, P1, P2, P3, P4)>> <(S0, S1, S2, S3, S4, S5) as IntoSystemConfigs<(SystemConfigTupleMarker, P0, P1, P2, P3, P4, P5)>> and 14 others = note: required for `fn() -> u32 {producer}` to implement `IntoSystemConfigs<_>` note: required by a bound in `bevy::prelude::App::add_systems` --> C:\Users\Zac\Documents\GitHub\bevy\crates\bevy_app\src\app.rs:342:23 | 339 | pub fn add_systems<M>( | ----------- required by a bound in this associated function ... 342 | systems: impl IntoSystemConfigs<M>, | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `App::add_systems` ``` </details> </details> ## Testing CI passed locally. ## Migration Guide Upgrade to version 1.78 (or higher) of Rust. ## Future Work - Currently, hints are not supported in this diagnostic. Ideally, suggestions like _"consider using ..."_ would be in a hint rather than a note, but that is the best option for now. - System chaining and other `all_tuples!(...)`-based traits have bad error messages due to the slightly different error message format. --------- Co-authored-by: Jamie Ridding <Themayu@users.noreply.github.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com>
This commit is contained in:
parent
104dcf5a67
commit
11f0a2dcde
30 changed files with 129 additions and 12 deletions
|
@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/bevyengine/bevy"
|
repository = "https://github.com/bevyengine/bevy"
|
||||||
documentation = "https://docs.rs/bevy"
|
documentation = "https://docs.rs/bevy"
|
||||||
rust-version = "1.77.0"
|
rust-version = "1.78.0"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
exclude = [
|
exclude = [
|
||||||
|
|
|
@ -54,7 +54,7 @@ use std::any::Any;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// # fn damp_flickering() {}
|
/// # fn damp_flickering() {}
|
||||||
/// ````
|
/// ```
|
||||||
pub trait Plugin: Downcast + Any + Send + Sync {
|
pub trait Plugin: Downcast + Any + Send + Sync {
|
||||||
/// Configures the [`App`] to which this plugin is added.
|
/// Configures the [`App`] to which this plugin is added.
|
||||||
fn build(&self, app: &mut App);
|
fn build(&self, app: &mut App);
|
||||||
|
|
|
@ -223,6 +223,11 @@ impl Plugin for AssetPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not an `Asset`",
|
||||||
|
label = "invalid `Asset`",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Asset)]`"
|
||||||
|
)]
|
||||||
pub trait Asset: VisitAssetDependencies + TypePath + Send + Sync + 'static {}
|
pub trait Asset: VisitAssetDependencies + TypePath + Send + Sync + 'static {}
|
||||||
|
|
||||||
pub trait VisitAssetDependencies {
|
pub trait VisitAssetDependencies {
|
||||||
|
|
|
@ -141,6 +141,11 @@ use std::ptr::NonNull;
|
||||||
// bundle, in the _exact_ order that [`DynamicBundle::get_components`] is called.
|
// bundle, in the _exact_ order that [`DynamicBundle::get_components`] is called.
|
||||||
// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by
|
// - [`Bundle::from_components`] must call `func` exactly once for each [`ComponentId`] returned by
|
||||||
// [`Bundle::component_ids`].
|
// [`Bundle::component_ids`].
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a `Bundle`",
|
||||||
|
label = "invalid `Bundle`",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Component)]` or `#[derive(Bundle)]`"
|
||||||
|
)]
|
||||||
pub unsafe trait Bundle: DynamicBundle + Send + Sync + 'static {
|
pub unsafe trait Bundle: DynamicBundle + Send + Sync + 'static {
|
||||||
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
|
/// Gets this [`Bundle`]'s component ids, in the order of this bundle's [`Component`]s
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|
|
@ -150,6 +150,11 @@ use std::{
|
||||||
///
|
///
|
||||||
/// [`SyncCell`]: bevy_utils::synccell::SyncCell
|
/// [`SyncCell`]: bevy_utils::synccell::SyncCell
|
||||||
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
|
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a `Component`",
|
||||||
|
label = "invalid `Component`",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Component)]`"
|
||||||
|
)]
|
||||||
pub trait Component: Send + Sync + 'static {
|
pub trait Component: Send + Sync + 'static {
|
||||||
/// A constant indicating the storage type used for this component.
|
/// A constant indicating the storage type used for this component.
|
||||||
const STORAGE_TYPE: StorageType;
|
const STORAGE_TYPE: StorageType;
|
||||||
|
|
|
@ -37,7 +37,6 @@ use super::EntityHashMap;
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
pub trait MapEntities {
|
pub trait MapEntities {
|
||||||
/// Updates all [`Entity`] references stored inside using `entity_mapper`.
|
/// Updates all [`Entity`] references stored inside using `entity_mapper`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -28,6 +28,11 @@ use std::{
|
||||||
/// You can conveniently access events using the [`EventReader`] and [`EventWriter`] system parameter.
|
/// You can conveniently access events using the [`EventReader`] and [`EventWriter`] system parameter.
|
||||||
///
|
///
|
||||||
/// Events must be thread-safe.
|
/// Events must be thread-safe.
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not an `Event`",
|
||||||
|
label = "invalid `Event`",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Event]`"
|
||||||
|
)]
|
||||||
pub trait Event: Send + Sync + 'static {}
|
pub trait Event: Send + Sync + 'static {}
|
||||||
|
|
||||||
/// An `EventId` uniquely identifies an event stored in a specific [`World`].
|
/// An `EventId` uniquely identifies an event stored in a specific [`World`].
|
||||||
|
|
|
@ -268,6 +268,10 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
///
|
///
|
||||||
/// [`Query`]: crate::system::Query
|
/// [`Query`]: crate::system::Query
|
||||||
/// [`ReadOnly`]: Self::ReadOnly
|
/// [`ReadOnly`]: Self::ReadOnly
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not valid to request as data in a `Query`",
|
||||||
|
label = "invalid `Query` data"
|
||||||
|
)]
|
||||||
pub unsafe trait QueryData: WorldQuery {
|
pub unsafe trait QueryData: WorldQuery {
|
||||||
/// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.
|
/// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.
|
||||||
type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;
|
type ReadOnly: ReadOnlyQueryData<State = <Self as WorldQuery>::State>;
|
||||||
|
|
|
@ -70,7 +70,11 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
||||||
/// [`matches_component_set`]: Self::matches_component_set
|
/// [`matches_component_set`]: Self::matches_component_set
|
||||||
/// [`Query`]: crate::system::Query
|
/// [`Query`]: crate::system::Query
|
||||||
/// [`State`]: Self::State
|
/// [`State`]: Self::State
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a valid `Query` filter",
|
||||||
|
label = "invalid `Query` filter",
|
||||||
|
note = "a `QueryFilter` typically uses a combination of `With<T>` and `Without<T>` statements"
|
||||||
|
)]
|
||||||
pub trait QueryFilter: WorldQuery {
|
pub trait QueryFilter: WorldQuery {
|
||||||
/// Returns true if (and only if) this Filter relies strictly on archetypes to limit which
|
/// Returns true if (and only if) this Filter relies strictly on archetypes to limit which
|
||||||
/// components are accessed by the Query.
|
/// components are accessed by the Query.
|
||||||
|
@ -938,6 +942,11 @@ impl<T: Component> QueryFilter for Changed<T> {
|
||||||
///
|
///
|
||||||
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
|
/// [`Added`] and [`Changed`] works with entities, and therefore are not archetypal. As such
|
||||||
/// they do not implement [`ArchetypeFilter`].
|
/// they do not implement [`ArchetypeFilter`].
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a valid `Query` filter based on archetype information",
|
||||||
|
label = "invalid `Query` filter",
|
||||||
|
note = "an `ArchetypeFilter` typically uses a combination of `With<T>` and `Without<T>` statements"
|
||||||
|
)]
|
||||||
pub trait ArchetypeFilter: QueryFilter {}
|
pub trait ArchetypeFilter: QueryFilter {}
|
||||||
|
|
||||||
impl<T: Component> ArchetypeFilter for With<T> {}
|
impl<T: Component> ArchetypeFilter for With<T> {}
|
||||||
|
|
|
@ -288,6 +288,10 @@ impl<T> NodeConfigs<T> {
|
||||||
/// )
|
/// )
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` does not describe a valid system configuration",
|
||||||
|
label = "invalid system configuration"
|
||||||
|
)]
|
||||||
pub trait IntoSystemConfigs<Marker>
|
pub trait IntoSystemConfigs<Marker>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
@ -562,6 +566,10 @@ impl SystemSetConfig {
|
||||||
pub type SystemSetConfigs = NodeConfigs<InternedSystemSet>;
|
pub type SystemSetConfigs = NodeConfigs<InternedSystemSet>;
|
||||||
|
|
||||||
/// Types that can convert into a [`SystemSetConfigs`].
|
/// Types that can convert into a [`SystemSetConfigs`].
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` does not describe a valid system set configuration",
|
||||||
|
label = "invalid system set configuration"
|
||||||
|
)]
|
||||||
pub trait IntoSystemSetConfigs
|
pub trait IntoSystemSetConfigs
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|
|
@ -149,6 +149,10 @@ impl SystemSet for AnonymousSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Types that can be converted into a [`SystemSet`].
|
/// Types that can be converted into a [`SystemSet`].
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a system set",
|
||||||
|
label = "invalid system set"
|
||||||
|
)]
|
||||||
pub trait IntoSystemSet<Marker>: Sized {
|
pub trait IntoSystemSet<Marker>: Sized {
|
||||||
/// The type of [`SystemSet`] this instance converts into.
|
/// The type of [`SystemSet`] this instance converts into.
|
||||||
type Set: SystemSet;
|
type Set: SystemSet;
|
||||||
|
|
|
@ -39,6 +39,10 @@ use crate::{schedule::InternedSystemSet, world::unsafe_world_cell::UnsafeWorldCe
|
||||||
/// # system.initialize(&mut world);
|
/// # system.initialize(&mut world);
|
||||||
/// # assert!(system.run((), &mut world));
|
/// # assert!(system.run((), &mut world));
|
||||||
/// ```
|
/// ```
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not adapt a system of type `{S}`",
|
||||||
|
label = "invalid system adapter"
|
||||||
|
)]
|
||||||
pub trait Adapt<S: System>: Send + Sync + 'static {
|
pub trait Adapt<S: System>: Send + Sync + 'static {
|
||||||
/// The [input](System::In) type for an [`AdapterSystem`].
|
/// The [input](System::In) type for an [`AdapterSystem`].
|
||||||
type In;
|
type In;
|
||||||
|
|
|
@ -83,6 +83,11 @@ use super::{ReadOnlySystem, System};
|
||||||
/// # assert!(world.resource::<RanFlag>().0);
|
/// # assert!(world.resource::<RanFlag>().0);
|
||||||
/// # world.resource_mut::<RanFlag>().0 = false;
|
/// # world.resource_mut::<RanFlag>().0 = false;
|
||||||
/// ```
|
/// ```
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not combine systems `{A}` and `{B}`",
|
||||||
|
label = "invalid system combination",
|
||||||
|
note = "the inputs and outputs of `{A}` and `{B}` are not compatible with this combiner"
|
||||||
|
)]
|
||||||
pub trait Combine<A: System, B: System> {
|
pub trait Combine<A: System, B: System> {
|
||||||
/// The [input](System::In) type for a [`CombinatorSystem`].
|
/// The [input](System::In) type for a [`CombinatorSystem`].
|
||||||
type In;
|
type In;
|
||||||
|
|
|
@ -161,6 +161,10 @@ where
|
||||||
///
|
///
|
||||||
/// This trait can be useful for making your own systems which accept other systems,
|
/// This trait can be useful for making your own systems which accept other systems,
|
||||||
/// sometimes called higher order systems.
|
/// sometimes called higher order systems.
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not an exclusive system",
|
||||||
|
label = "invalid system"
|
||||||
|
)]
|
||||||
pub trait ExclusiveSystemParamFunction<Marker>: Send + Sync + 'static {
|
pub trait ExclusiveSystemParamFunction<Marker>: Send + Sync + 'static {
|
||||||
/// The input type to this system. See [`System::In`].
|
/// The input type to this system. See [`System::In`].
|
||||||
type In;
|
type In;
|
||||||
|
@ -168,7 +172,7 @@ pub trait ExclusiveSystemParamFunction<Marker>: Send + Sync + 'static {
|
||||||
/// The return type of this system. See [`System::Out`].
|
/// The return type of this system. See [`System::Out`].
|
||||||
type Out;
|
type Out;
|
||||||
|
|
||||||
/// The [`ExclusiveSystemParam`]/s defined by this system's `fn` parameters.
|
/// The [`ExclusiveSystemParam`]'s defined by this system's `fn` parameters.
|
||||||
type Param: ExclusiveSystemParam;
|
type Param: ExclusiveSystemParam;
|
||||||
|
|
||||||
/// Executes this system once. See [`System::run`].
|
/// Executes this system once. See [`System::run`].
|
||||||
|
|
|
@ -10,6 +10,10 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
/// A parameter that can be used in an exclusive system (a system with an `&mut World` parameter).
|
/// A parameter that can be used in an exclusive system (a system with an `&mut World` parameter).
|
||||||
/// Any parameters implementing this trait must come after the `&mut World` parameter.
|
/// Any parameters implementing this trait must come after the `&mut World` parameter.
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not be used as a parameter for an exclusive system",
|
||||||
|
label = "invalid system parameter"
|
||||||
|
)]
|
||||||
pub trait ExclusiveSystemParam: Sized {
|
pub trait ExclusiveSystemParam: Sized {
|
||||||
/// Used to store data which persists across invocations of a system.
|
/// Used to store data which persists across invocations of a system.
|
||||||
type State: Send + Sync + 'static;
|
type State: Send + Sync + 'static;
|
||||||
|
|
|
@ -626,6 +626,10 @@ where
|
||||||
/// ```
|
/// ```
|
||||||
/// [`PipeSystem`]: crate::system::PipeSystem
|
/// [`PipeSystem`]: crate::system::PipeSystem
|
||||||
/// [`ParamSet`]: crate::system::ParamSet
|
/// [`ParamSet`]: crate::system::ParamSet
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a valid system",
|
||||||
|
label = "invalid system"
|
||||||
|
)]
|
||||||
pub trait SystemParamFunction<Marker>: Send + Sync + 'static {
|
pub trait SystemParamFunction<Marker>: Send + Sync + 'static {
|
||||||
/// The input type to this system. See [`System::In`].
|
/// The input type to this system. See [`System::In`].
|
||||||
type In;
|
type In;
|
||||||
|
|
|
@ -147,6 +147,10 @@ use crate::world::World;
|
||||||
// This trait has to be generic because we have potentially overlapping impls, in particular
|
// This trait has to be generic because we have potentially overlapping impls, in particular
|
||||||
// because Rust thinks a type could impl multiple different `FnMut` combinations
|
// because Rust thinks a type could impl multiple different `FnMut` combinations
|
||||||
// even though none can currently
|
// even though none can currently
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a valid system with input `{In}` and output `{Out}`",
|
||||||
|
label = "invalid system"
|
||||||
|
)]
|
||||||
pub trait IntoSystem<In, Out, Marker>: Sized {
|
pub trait IntoSystem<In, Out, Marker>: Sized {
|
||||||
/// The type of [`System`] that this instance converts into.
|
/// The type of [`System`] that this instance converts into.
|
||||||
type System: System<In = In, Out = Out>;
|
type System: System<In = In, Out = Out>;
|
||||||
|
|
|
@ -22,6 +22,7 @@ use super::IntoSystem;
|
||||||
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
|
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
|
||||||
/// It's possible to specify explicit execution order between specific systems,
|
/// It's possible to specify explicit execution order between specific systems,
|
||||||
/// see [`IntoSystemConfigs`](crate::schedule::IntoSystemConfigs).
|
/// see [`IntoSystemConfigs`](crate::schedule::IntoSystemConfigs).
|
||||||
|
#[diagnostic::on_unimplemented(message = "`{Self}` is not a system", label = "invalid system")]
|
||||||
pub trait System: Send + Sync + 'static {
|
pub trait System: Send + Sync + 'static {
|
||||||
/// The system's input. See [`In`](crate::system::In) for
|
/// The system's input. See [`In`](crate::system::In) for
|
||||||
/// [`FunctionSystem`](crate::system::FunctionSystem)s.
|
/// [`FunctionSystem`](crate::system::FunctionSystem)s.
|
||||||
|
|
|
@ -432,6 +432,11 @@ impl_param_set!();
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
|
/// [`Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` is not a `Resource`",
|
||||||
|
label = "invalid `Resource`",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Resource)]`"
|
||||||
|
)]
|
||||||
pub trait Resource: Send + Sync + 'static {}
|
pub trait Resource: Send + Sync + 'static {}
|
||||||
|
|
||||||
// SAFETY: Res only reads a single World resource
|
// SAFETY: Res only reads a single World resource
|
||||||
|
|
|
@ -12,9 +12,9 @@ struct NoReflect(f32);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut foo: Box<dyn Struct> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
|
let mut foo: Box<dyn Struct> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
|
||||||
//~^ ERROR: not satisfied
|
//~^ ERROR: `NoReflect` does not provide type registration information
|
||||||
|
|
||||||
// foo doesn't implement Reflect because NoReflect doesn't implement Reflect
|
// foo doesn't implement Reflect because NoReflect doesn't implement Reflect
|
||||||
foo.get_field::<NoReflect>("a").unwrap();
|
foo.get_field::<NoReflect>("a").unwrap();
|
||||||
//~^ ERROR: not satisfied
|
//~^ ERROR: `NoReflect` can not be reflected
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0277]: the trait bound `NoReflect: Reflect` is not satisfied
|
error[E0277]: `NoReflect` can not be reflected
|
||||||
--> tests/reflect_derive/generics_fail.rs:18:21
|
--> tests/reflect_derive/generics_fail.rs:18:21
|
||||||
|
|
|
|
||||||
18 | foo.get_field::<NoReflect>("a").unwrap();
|
18 | foo.get_field::<NoReflect>("a").unwrap();
|
||||||
|
@ -6,6 +6,7 @@ error[E0277]: the trait bound `NoReflect: Reflect` is not satisfied
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
|
= note: Try using `#[derive(Reflect)]`
|
||||||
= help: the following other types implement trait `Reflect`:
|
= help: the following other types implement trait `Reflect`:
|
||||||
bool
|
bool
|
||||||
char
|
char
|
||||||
|
@ -17,17 +18,19 @@ error[E0277]: the trait bound `NoReflect: Reflect` is not satisfied
|
||||||
i128
|
i128
|
||||||
and 74 others
|
and 74 others
|
||||||
note: required by a bound in `bevy_reflect::GetField::get_field`
|
note: required by a bound in `bevy_reflect::GetField::get_field`
|
||||||
--> $BEVY_ROOT/crates/bevy_reflect/src/struct_trait.rs:242:21
|
--> $BEVY_ROOT/crates/bevy_reflect/src/struct_trait.rs:244:21
|
||||||
|
|
|
|
||||||
242 | fn get_field<T: Reflect>(&self, name: &str) -> Option<&T>;
|
244 | fn get_field<T: Reflect>(&self, name: &str) -> Option<&T>;
|
||||||
| ^^^^^^^ required by this bound in `GetField::get_field`
|
| ^^^^^^^ required by this bound in `GetField::get_field`
|
||||||
|
|
||||||
error[E0277]: the trait bound `NoReflect: GetTypeRegistration` is not satisfied
|
error[E0277]: `NoReflect` does not provide type registration information
|
||||||
--> tests/reflect_derive/generics_fail.rs:14:36
|
--> tests/reflect_derive/generics_fail.rs:14:36
|
||||||
|
|
|
|
||||||
14 | let mut foo: Box<dyn Struct> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
|
14 | let mut foo: Box<dyn Struct> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `GetTypeRegistration` is not implemented for `NoReflect`, which is required by `Foo<NoReflect>: bevy_reflect::Struct`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Invalid Type
|
||||||
|
|
|
|
||||||
|
= help: the trait `GetTypeRegistration` is not implemented for `NoReflect`, which is required by `Foo<NoReflect>: bevy_reflect::Struct`
|
||||||
|
= note: Try using `#[derive(Reflect)]`
|
||||||
= help: the following other types implement trait `GetTypeRegistration`:
|
= help: the following other types implement trait `GetTypeRegistration`:
|
||||||
bool
|
bool
|
||||||
char
|
char
|
||||||
|
|
|
@ -21,6 +21,10 @@ use crate::{FromType, Reflect};
|
||||||
/// [derive macro]: bevy_reflect_derive::FromReflect
|
/// [derive macro]: bevy_reflect_derive::FromReflect
|
||||||
/// [`DynamicStruct`]: crate::DynamicStruct
|
/// [`DynamicStruct`]: crate::DynamicStruct
|
||||||
/// [crate-level documentation]: crate
|
/// [crate-level documentation]: crate
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not be created through reflection",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(FromReflect)]`"
|
||||||
|
)]
|
||||||
pub trait FromReflect: Reflect + Sized {
|
pub trait FromReflect: Reflect + Sized {
|
||||||
/// Constructs a concrete instance of `Self` from a reflected value.
|
/// Constructs a concrete instance of `Self` from a reflected value.
|
||||||
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>;
|
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>;
|
||||||
|
|
|
@ -230,6 +230,10 @@ impl<'a> ReflectPath<'a> for &'a str {
|
||||||
/// [`List`]: crate::List
|
/// [`List`]: crate::List
|
||||||
/// [`Array`]: crate::Array
|
/// [`Array`]: crate::Array
|
||||||
/// [`Enum`]: crate::Enum
|
/// [`Enum`]: crate::Enum
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` does not provide a reflection path",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
|
||||||
|
)]
|
||||||
pub trait GetPath: Reflect {
|
pub trait GetPath: Reflect {
|
||||||
/// Returns a reference to the value specified by `path`.
|
/// Returns a reference to the value specified by `path`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -179,6 +179,10 @@ impl std::fmt::Display for ReflectKind {
|
||||||
/// [`bevy_reflect`]: crate
|
/// [`bevy_reflect`]: crate
|
||||||
/// [derive macro]: bevy_reflect_derive::Reflect
|
/// [derive macro]: bevy_reflect_derive::Reflect
|
||||||
/// [crate-level documentation]: crate
|
/// [crate-level documentation]: crate
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not be reflected",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
|
||||||
|
)]
|
||||||
pub trait Reflect: DynamicTypePath + Any + Send + Sync {
|
pub trait Reflect: DynamicTypePath + Any + Send + Sync {
|
||||||
/// Returns the [`TypeInfo`] of the type _represented_ by this value.
|
/// Returns the [`TypeInfo`] of the type _represented_ by this value.
|
||||||
///
|
///
|
||||||
|
|
|
@ -70,6 +70,10 @@ use std::fmt::Debug;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [utility]: crate::utility
|
/// [utility]: crate::utility
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not provide type information through reflection",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
|
||||||
|
)]
|
||||||
pub trait Typed: Reflect + TypePath {
|
pub trait Typed: Reflect + TypePath {
|
||||||
/// Returns the compile-time [info] for the underlying type.
|
/// Returns the compile-time [info] for the underlying type.
|
||||||
///
|
///
|
||||||
|
|
|
@ -79,6 +79,10 @@ use std::fmt;
|
||||||
/// [`crate_name`]: TypePath::crate_name
|
/// [`crate_name`]: TypePath::crate_name
|
||||||
/// [`module_path`]: TypePath::module_path
|
/// [`module_path`]: TypePath::module_path
|
||||||
/// [`type_ident`]: TypePath::type_ident
|
/// [`type_ident`]: TypePath::type_ident
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` does not have a type path",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Reflect)]` or `#[derive(TypePath)]`"
|
||||||
|
)]
|
||||||
pub trait TypePath: 'static {
|
pub trait TypePath: 'static {
|
||||||
/// Returns the fully qualified path of the underlying type.
|
/// Returns the fully qualified path of the underlying type.
|
||||||
///
|
///
|
||||||
|
@ -129,6 +133,10 @@ pub trait TypePath: 'static {
|
||||||
/// Since this is a supertrait of [`Reflect`] its methods can be called on a `dyn Reflect`.
|
/// Since this is a supertrait of [`Reflect`] its methods can be called on a `dyn Reflect`.
|
||||||
///
|
///
|
||||||
/// [`Reflect`]: crate::Reflect
|
/// [`Reflect`]: crate::Reflect
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not be used as a dynamic type path",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Reflect)]` or `#[derive(TypePath)]`"
|
||||||
|
)]
|
||||||
pub trait DynamicTypePath {
|
pub trait DynamicTypePath {
|
||||||
/// See [`TypePath::type_path`].
|
/// See [`TypePath::type_path`].
|
||||||
fn reflect_type_path(&self) -> &str;
|
fn reflect_type_path(&self) -> &str;
|
||||||
|
|
|
@ -56,6 +56,10 @@ impl Debug for TypeRegistryArc {
|
||||||
/// See the [crate-level documentation] for more information on type registration.
|
/// See the [crate-level documentation] for more information on type registration.
|
||||||
///
|
///
|
||||||
/// [crate-level documentation]: crate
|
/// [crate-level documentation]: crate
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` does not provide type registration information",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(Reflect)]`"
|
||||||
|
)]
|
||||||
pub trait GetTypeRegistration: 'static {
|
pub trait GetTypeRegistration: 'static {
|
||||||
/// Returns the default [`TypeRegistration`] for this type.
|
/// Returns the default [`TypeRegistration`] for this type.
|
||||||
fn get_type_registration() -> TypeRegistration;
|
fn get_type_registration() -> TypeRegistration;
|
||||||
|
|
|
@ -9,6 +9,7 @@ use super::transitions::*;
|
||||||
///
|
///
|
||||||
/// While ordinary states are freely mutable (and implement this trait as part of their derive macro),
|
/// While ordinary states are freely mutable (and implement this trait as part of their derive macro),
|
||||||
/// computed states are not: instead, they can *only* change when the states that drive them do.
|
/// computed states are not: instead, they can *only* change when the states that drive them do.
|
||||||
|
#[diagnostic::on_unimplemented(note = "consider annotating `{Self}` with `#[derive(States)]`")]
|
||||||
pub trait FreelyMutableState: States {
|
pub trait FreelyMutableState: States {
|
||||||
/// This function registers all the necessary systems to apply state changes and run transition schedules
|
/// This function registers all the necessary systems to apply state changes and run transition schedules
|
||||||
fn register_state(schedule: &mut Schedule) {
|
fn register_state(schedule: &mut Schedule) {
|
||||||
|
|
|
@ -54,6 +54,11 @@ use std::hash::Hash;
|
||||||
/// app.add_systems(Update, handle_escape_pressed.run_if(in_state(GameState::MainMenu)));
|
/// app.add_systems(Update, handle_escape_pressed.run_if(in_state(GameState::MainMenu)));
|
||||||
/// app.add_systems(OnEnter(GameState::SettingsMenu), open_settings_menu);
|
/// app.add_systems(OnEnter(GameState::SettingsMenu), open_settings_menu);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not be used as a state",
|
||||||
|
label = "invalid state",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(States)]`"
|
||||||
|
)]
|
||||||
pub trait States: 'static + Send + Sync + Clone + PartialEq + Eq + Hash + Debug {
|
pub trait States: 'static + Send + Sync + Clone + PartialEq + Eq + Hash + Debug {
|
||||||
/// How many other states this state depends on.
|
/// How many other states this state depends on.
|
||||||
/// Used to help order transitions and de-duplicate [`ComputedStates`](crate::state::ComputedStates), as well as prevent cyclical
|
/// Used to help order transitions and de-duplicate [`ComputedStates`](crate::state::ComputedStates), as well as prevent cyclical
|
||||||
|
|
|
@ -143,6 +143,11 @@ pub use bevy_state_macros::SubStates;
|
||||||
///
|
///
|
||||||
/// impl FreelyMutableState for GamePhase {}
|
/// impl FreelyMutableState for GamePhase {}
|
||||||
/// ```
|
/// ```
|
||||||
|
#[diagnostic::on_unimplemented(
|
||||||
|
message = "`{Self}` can not be used as a sub-state",
|
||||||
|
label = "invalid sub-state",
|
||||||
|
note = "consider annotating `{Self}` with `#[derive(SubStates)]`"
|
||||||
|
)]
|
||||||
pub trait SubStates: States + FreelyMutableState {
|
pub trait SubStates: States + FreelyMutableState {
|
||||||
/// The set of states from which the [`Self`] is derived.
|
/// The set of states from which the [`Self`] is derived.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue