bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.4k stars 3.59k forks source link

Fix `bevy_hierarchy` failing to compile without `reflect` feature #16428

Closed aecsocket closed 6 days ago

aecsocket commented 1 week ago

Objective

Run this without this PR: cargo build -p bevy_hierarchy --no-default-features

You'll get:

error[E0432]: unresolved import `bevy_reflect`
 --> crates/bevy_hierarchy/src/events.rs:2:5
  |
2 | use bevy_reflect::Reflect;
  |     ^^^^^^^^^^^^ use of undeclared crate or module `bevy_reflect`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `bevy_hierarchy` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

Because of this line:

use bevy_reflect::Reflect;

#[derive(Event, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "reflect", derive(Reflect), reflect(Debug, PartialEq))]
pub enum HierarchyEvent { .. }

Solution

use FQN: derive(bevy_reflect::Reflect)

Testing

cargo build -p bevy_hierarchy --no-default-features

aecsocket commented 1 week ago

Done. Personally I prefer FQN and dislike feature gating imports, but ideally Bevy sets outs its own guidelines on when to use FQN and when to feature gate imports.

BenjaminBrienen commented 1 week ago

Yeah, I don't mind the FQP myself actually, but I prefer consistency.