From 405fa3e8ea1d8ff23f0590a18242667e2b21e2d9 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sun, 20 Oct 2024 14:52:52 +0100 Subject: [PATCH] Mute non-local definition warnings in bevy_reflect (#16013) # 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 --- crates/bevy_reflect/src/impls/std.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 60704d602a..27b1d58d05 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -219,9 +219,9 @@ impl_reflect_opaque!(::alloc::collections::BinaryHeap); macro_rules! impl_reflect_for_atomic { ($ty:ty, $ordering:expr) => { - const _: () = { - impl_type_path!($ty); + impl_type_path!($ty); + const _: () = { #[cfg(feature = "functions")] crate::func::macros::impl_function_traits!($ty); @@ -325,10 +325,6 @@ macro_rules! impl_reflect_for_atomic { } } - // strange rustfmt bug gives this invocation the wrong indentation! - #[rustfmt::skip] - impl_full_reflect!(for $ty where $ty: Any + Send + Sync); - impl FromReflect for $ty where $ty: Any + Send + Sync, @@ -340,6 +336,8 @@ macro_rules! impl_reflect_for_atomic { } } }; + + impl_full_reflect!(for $ty where $ty: Any + Send + Sync); }; }