Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve some error messages for bevy_ecs generated by nightly rustc #5786

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ debug_asset_server = ["bevy_internal/debug_asset_server"]

# Enable animation support, and glTF animation loading
animation = ["bevy_internal/animation"]
nightly-error-messages = ["bevy_internal/nightly-error-messages"]

[dependencies]
bevy_dylib = { path = "crates/bevy_dylib", version = "0.9.0-dev", default-features = false, optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ categories = ["game-engines", "data-structures"]
[features]
trace = []
default = ["bevy_reflect"]
nightly-error-messages = []

[dependencies]
bevy_ptr = { path = "../bevy_ptr", version = "0.9.0-dev" }
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(clippy::undocumented_unsafe_blocks)]
#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "nightly-error-messages", feature(rustc_attrs))]

#[cfg(target_pointer_width = "16")]
compile_error!("bevy_ecs cannot safely compile for a 16-bit platform.");
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ use std::{cell::UnsafeCell, marker::PhantomData};
/// [`WorldQuery::update_archetype_component_access`] exactly reflects the results of
/// [`WorldQuery::matches_component_set`], [`WorldQuery::archetype_fetch`], and
/// [`WorldQuery::table_fetch`].
#[cfg_attr(
feature = "nightly-error-messages",
rustc_on_unimplemented(on(
not(any(_Self = "& _", _Self = "&mut _", _Self = "()", _Self = "(_, _)")),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself: I need to check if that actually does something or if it's unnecessary. In the second case I likely need to find a solution for false positives if Self is a tuple or something like that.

message = "Using a `WorldQuery` object as parameter to `Query` requires the usage of a reference",
label = "consider using `& {Self}` here"
),)
)]
pub unsafe trait WorldQuery: for<'w> WorldQueryGats<'w> {
/// The read-only variant of this [`WorldQuery`], which satisfies the [`ReadOnlyWorldQuery`] trait.
type ReadOnly: ReadOnlyWorldQuery<State = Self::State>;
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ impl_param_set!();
/// # schedule.add_system_to_stage("update", write_resource_system.after("first"));
/// # schedule.run_once(&mut world);
/// ```
#[cfg_attr(
feature = "nightly-error-messages",
rustc_on_unimplemented(note = "consider adding `#[derive(bevy::Resource)]` to `{Self}`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should match this for the Component trait :)

)]
pub trait Resource: Send + Sync + 'static {}

/// Shared borrow of a [`Resource`].
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ trace_chrome = [ "bevy_log/tracing-chrome" ]
trace_tracy = ["bevy_render?/tracing-tracy", "bevy_log/tracing-tracy" ]
wgpu_trace = ["bevy_render/wgpu_trace"]
debug_asset_server = ["bevy_asset/debug_asset_server"]
nightly-error-messages = ["bevy_ecs/nightly-error-messages"]

# Image format support for texture loading (PNG and HDR are enabled by default)
hdr = ["bevy_render/hdr"]
Expand Down