You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If Signal::global is used in const global instead of a static global, multiple states will be created. Consts effectively copy the const value into every place where the const is used.
constSIGNAL:GlobalSignal<u32> = Signal::global(|| 0);// This will create a signalSIGNAL.read();// -> Signal::global(|| 0).read()// This will create a completely different signalSIGNAL.read();// -> Signal::global(|| 0).read()staticSTATIC_SIGNAL:GlobalSignal<u32> = Signal::global(|| 0);// This just references the existing signal if a signal already exists in the global contextSTATIC_SIGNAL.read();
Implement Suggestion
We should try to prevent this at compile time or if we cannot prevent it at compile time, warn the user with tracing.
Specific Demand
If
Signal::global
is used in const global instead of a static global, multiple states will be created. Consts effectively copy the const value into every place where the const is used.Implement Suggestion
We should try to prevent this at compile time or if we cannot prevent it at compile time, warn the user with tracing.
OnceCell faces a similar issue. It might be worth looking into their discussions/issues: matklad/once_cell#224, rust-lang/rust#40543
The text was updated successfully, but these errors were encountered: