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

Mute non-local definition warnings in bevy_reflect #16013

Merged
merged 1 commit into from
Oct 20, 2024

Conversation

stepancheg
Copy link
Contributor

Objective

cargo check -p bevy_reflect

outputs a lot of warnings like:

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
   --> crates/bevy_reflect/src/impls/std.rs:223:13
    |
223 |               impl_type_path!($ty);
    |               ^-------------------
    |               |
    |               `TypePath` is not local
    |               move the `impl` block outside of this constant `_` and up 2 bodies
...
346 | / impl_reflect_for_atomic!(
347 | |     ::core::sync::atomic::AtomicIsize,
    | |     --------------------------------- `AtomicIsize` is not local
348 | |     ::core::sync::atomic::Ordering::SeqCst
349 | | );
    | |_- in this macro invocation
    |
    = note: the macro `impl_type_path` defines the non-local `impl`, and may need to be changed
    = note: the macro `impl_type_path` may come from an old version of the `bevy_reflect_derive` crate, try updating your dependency with `cargo update -p bevy_reflect_derive`
    = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
    = note: `#[warn(non_local_definitions)]` on by default
    = note: this warning originates in the macro `impl_type_path` which comes from the expansion of the macro `impl_reflect_for_atomic` (in Nightly builds, run with -Z macro-backtrace for more info)

Solution

Move impl_type_path! into global scope. Warnings no longer pop up.

Testing

CI

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 19, 2024
@alice-i-cecile alice-i-cecile requested a review from MrGVSV October 19, 2024 21:36
@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change and removed C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Oct 19, 2024
@stepancheg
Copy link
Contributor Author

Also moved impl_full_reflect! call because otherwise I don't know how deal with mentioned rustfmt bug: it seems to ignore #[rustfmt::skip] instruction after my change and increases indentation.

@MrGVSV
Copy link
Member

MrGVSV commented Oct 19, 2024

Note: this seems to be a nightly-only issue. Running cargo check -p bevy_reflect works fine on stable, but gives the warning when running cargo +nightly check -p bevy_reflect.

Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

This feels like a bug on Rust's end tbh. I don't see why a nested const block would cause this issue.

But the changes do seem to fix it regardless, so approving!

@MrGVSV MrGVSV added the D-Trivial Nice and easy! A great choice to get started with Bevy label Oct 19, 2024
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 20, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 20, 2024
Merged via the queue into bevyengine:main with commit 405fa3e Oct 20, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Code-Quality A section of code that is hard to understand or change D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants