-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mem::transmute should be a const fn
.
#49450
Comments
The union-in-const transmute trick is actually already stable on nightly (without |
@solson yes, that's what I meant with:
|
I'm ideologically opposed to the generality and special-ness of |
These methods call |
Yes, and I am fine with that. It's an acceptable trade off for not presenting |
The The current problem with this approach is that it requires |
But these are issues for any interface that is more specific than |
This has now been implemented behind a feature gate: #53535 The tracking issue is #53605 . Please raise any objections to the stabilization there. My personal stance is that if we do not stabilize it, but allow unions in const fn, then users will just write union Transmute<T, U> {
t: T,
u: U,
}
pub const unsafe fn my_hacky_transmute<T, U>(t: T) -> U {
Transmute { t }.u
} and everything will be worse with that than with |
A common request in
stdsimd
is being able to initialize static variables with architecture-specific vector types.There are many ways to hack this out, but AFAICt all of them basically reduce to using an union to implement a
mem::transmute
clone whose only different frommem::transmute
is that it is aconst fn
.Since this is already possible today, we should IMO just go ahead and make
mem::transmute
aconst fn
.The text was updated successfully, but these errors were encountered: