-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Tracking Issue for using std::mem::transmute() in const fn (const_fn_transmute) #53605
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I, for one, would love this, because I've had to use the union transmute hack more times than I feel comfortable. |
@mjbshaw It's already been merged :) |
@TheDarkula I know. I'm just trying to show support for eventually stabilizing this feature (rather than being removed because people are opposed to it). |
Even with the flag, is this possible? I am getting an error stating that the use of unsafe functions are not allowed in pub const unsafe fn rx_buffer_init() -> [BufferDescriptor; BUFFER_CT] {
transmute::<
[u8; size_of::<BufferDescriptor>() * BUFFER_CT],
[BufferDescriptor; BUFFER_CT]
>([0u8; size_of::<BufferDescriptor>() * BUFFER_CT])
} gives me
|
Is there some blocker on this or could this be starting to get stabilized? I'm mostly looking out for a way to define a function from a |
EDIT: Ugh, in fact, there is. For example, usize -> function pointer throws
... which makes |
Given that So I propose we stabilize |
See #64011 for stabilizing |
Is there any news about the stabilization? |
@WaffleLapkin: @oli-obk reopened #64011 today because it got unblocked, then closed it again because apparently stabilizing So I think this is now blocked on union accesses in |
Should we give this another try? Not much progress has been made on the unconst side of things (also see here), but allowing |
I'm creating a new stabilization PR to show the workarounds needed to allow such a split. We can then decide whether we'll take on that technical debt. |
Stabilize `transmute` in constants and statics but not const fn cc rust-lang#53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: rust-lang#64011 r? @RalfJung cc @rust-lang/wg-const-eval
Stabilize `transmute` in constants and statics but not const fn cc rust-lang#53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: rust-lang#64011 r? @RalfJung cc @rust-lang/wg-const-eval
Stabilize `transmute` in constants and statics but not const fn cc rust-lang#53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: rust-lang#64011 r? @RalfJung cc @rust-lang/wg-const-eval
Stabilize `transmute` in constants and statics but not const fn cc rust-lang#53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: rust-lang#64011 r? @RalfJung cc @rust-lang/wg-const-eval
Stabilize `transmute` in constants and statics but not const fn cc rust-lang#53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: rust-lang#64011 r? @RalfJung cc @rust-lang/wg-const-eval
Stabilize `transmute` in constants and statics but not const fn cc rust-lang#53605 (leaving issue open so we can add `transmute` to `const fn` later) Previous attempt: rust-lang#64011 r? @RalfJung cc @rust-lang/wg-const-eval
Is there any summary of what the current status is here to actually get (Coming here because I'd have liked to make |
Raw pointers and transmute are pretty much equal in terms of "what it takes to make them const-stable". The next step is to figure out what we want to do with UB during CTFE, for which I recently proposed an RFC: rust-lang/rfcs#3016. The key PR needed to implement that RFC is up at #78407. |
I think it would be a good idea to split out into a separate feature that can be stabilized transmute of references to types that are #[repr(transparent)]
pub struct MySlice(pub [u8]);
impl MySlice {
pub const fn new(v: &[u8]) -> &MySlice {
unsafe { std::mem::transmute(v) }
}
} |
I think once we find some kind of consensus on rust-lang/rfcs#3016 (which turned out to be much harder than I anticipated), there's not much blocking stabilization here. |
So, rust-lang/rfcs#3016 was merged. @RalfJung, does that mean we can proceed with stabilization here? |
It seems to me that the answer is probably yes, since #75196 has a stabilization PR out and was previously blocked on rust-lang/const-eval#14. |
Add a static_uncased_str macro, which can create `&'static UncasedStr`s from `&'static str`s. This won't be necessary once rust-lang/rust#53605 lands, but that's at least a few months away.
Add a static_uncased_str macro, which can create `&'static UncasedStr`s from `&'static str`s. This won't be necessary once rust-lang/rust#53605 lands, but that's at least a few months away.
The stabilization PR is already up. :) |
Uh oh!
There was an error while loading. Please reload this page.
Using
std::mem::transmute()
in constant functions is behind theconst_transmute
/const_fn_transmute
feature gate.(In constants, it is stable.)
Blocked on rust-lang/const-eval#14.
The text was updated successfully, but these errors were encountered: