nicopap / bevy_mod_sysfail

Decorate your bevy system with the sysfail macro attribute to make them handle cleanly failure mods.
Apache License 2.0
25 stars 5 forks source link

`#[sysfail(Log<T>)]` fails to compile if `T` contains a system-generic type #7

Open nicopap opened 9 months ago

nicopap commented 9 months ago

This only occurs for generic systems with a Log failure mode.

#[sysfail(Log<GizmoError<T>>)]
fn drag_gizmo<T>(time: Res<Time>)
where
    T: std::fmt::Debug,

This is because in sysfail, we special-case Log to generate a static similar to how the info!, debug! etc macros from the tracing crate works. The problem is that we use the Log's parameter (here GizmoError<T>) to determine the log level of the error (specifically this line in generate.rs: <#ret_type as #prefix::Failure>::LEVEL).

This is a fundamental limitation of rust, we simply can't (yet) use generics parameters in static or const value expressions.

Partial fix

For Log specifically, the level is declared as the second type parameter of Log, so we should be able to select (though the is_log check accepts any arbitrary type) the error type directly from it, and not need to include the generic parameter in the static expression.

Workarounds