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
This commit is contained in:
Stepan Koltsov 2024-10-20 14:52:52 +01:00 committed by GitHub
parent 0cc53458cc
commit 405fa3e8ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,9 +219,9 @@ impl_reflect_opaque!(::alloc::collections::BinaryHeap<T: Clone>);
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);
};
}