Const tuples

After years perhaps this will see the light (destructuring assignment):

Related, sometimes I'd like to write:

const (A, B): (u32, u32) = (10, 20);

This is handy because sometimes I have compile-time (const) functions that return a tuple.

7 Likes

I think that all forms forms of destructuring should be allowed in a const scenario, as I don’t think there are any technical limitations to it and it seems orthogonal to how let statements work. Doesn’t seem particularly controversial.

8 Likes

By the way, what is the reason why const items allow writing _ instead of an identifier, but not static variables? Does it have something to do with statics never getting dropped?

Maybe because a plain _ doesn't bind anything? And the whole point of static is to have something bound for the rest of the program?

2 Likes

Probably because nobody needs it. const _ can be useful to make compile time assertion that don't need to be accessed. But I can't figure out any practical use of inaccessible static.

1 Like

But then how will everyone implement their fill-up-the-entire-memory-with-.rodata attacks in Rust? /s

const _: () = {
    static __: <type> = <value>;
};

:upside_down_face:

6 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.