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
Take a look at this program, which fails to compile:
structFoo{a:int}staticmut x:int = 3;staticmut f:Foo = Foo{a: x };// error: use of mutable static requires unsafe function or blockfnmain(){}
The failure is obviously because the rule is that static mut items have to be wrapped in an unsafe block to be used, which I presume would look like the following:
...but as you can see, using unsafe blocks in constant expressions isn't implemented yet.
The question I want to raise here is whether the unsafe block should be required at all. Currently, constant expressions cannot mutate anything, so x might as well be just static in this case. But if we ever expand our constant expressions in the future to include mutation, allowing people to omit them here might present a backwards-compat hazard.