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
@oconnor663 Do you know who would be the right person to @ in order to get this reviewed/FCP'd? Given the existence of as_slice_of_cells I don't think we'll have a blocking discussion on the name or semantics, at least.
@TOETOE55Miri is ok with it at least. I could be totally wrong, but I think Miri sees these things in terms of bytes, and all the bytes in this case are covered by UnsafeCell, and that might be why it's ok.
The following code also passes Miri's checks
, but whether this should be UB is questionable. If I remember correctly, the current rule for the checks is that &T is readonly only when T does not contain UnsafeCell.
Should this be named transpose instead for consistency with the same method on MaybeUninit<[N; T]> and [MaybeUninit<T>; N]? It would also be an opportunity to introduce the reverse operation also named transpose.
I don't like transpose as a name, it says very little about what the operation actually does. as_slice_of_cells/as_array_of_cells is nicely explicit, which I think is a good thing.
Does the following code violate the readonly constraint of arr_of_cells: &[Cell]?
No, this is fine -- you're only mutating things inside an UnsafeCell.
What confuses me is that this code modifies arr_of_cells: &[Cell] through cell_arr: Cell<[i32; N]>, yet arr_of_cells itself is not in an UnsafeCell, only its elements are.
For the naming question, I think Cell::as_slice_of_cells has more consistency gravity for us here, since it's on the same type and it's also been stable for a long time? (MaybeUninit::transpose is still unstable.)
I didn't realize before, but there's also Result::transpose and Option::transpose. Though I feel it makes a lot more sense in those cases as any alternative along these lines (as_result_of_option???) would be somewhat "interesting" to understand upon first reading.
Though I still think as_slice_of_cells / as_array_of_cells are more straightforward in this case, maybe MaybeUninit::as_array_of_uninit and MaybeUninit::as_slice_of_uninit would be acceptable too?
For what it's worth, there's also a bit of sporadic discussion about the naming of MaybeUninit::transpose on the tracking issue, though I don't believe anybody has suggested the current style used here. I certainly think it would be nice if both APIs at least went the same direction.
My vibe-read is that MaybeUninit::transpose is probably on the way out, so would lean to not using it here. It does have the issue that without knowing exactly the types involved it's pretty opaque for what it's doing, which is fine sometimes, but less fine for unsafe-related things like MaybeUninit transformations where being more explicit than usual is often a good idea to avoid accidentally doing something might look right but accidentally uses the wrong type.
Activity
pierzchalski commentedon Aug 22, 2023
@oconnor663 Do you know who would be the right person to @ in order to get this reviewed/FCP'd? Given the existence of
as_slice_of_cellsI don't think we'll have a blocking discussion on the name or semantics, at least.pierzchalski commentedon Aug 27, 2023
Wait, can I just do @rfcbot needs-fcp
TOETOE55 commentedon Jan 9, 2024
Does the following code violate the readonly constraint of
arr_of_cells: &[Cell<i32>]?oconnor663 commentedon Jan 10, 2024
@TOETOE55 Miri is ok with it at least. I could be totally wrong, but I think Miri sees these things in terms of bytes, and all the bytes in this case are covered by
UnsafeCell, and that might be why it's ok.@scottmcm what needs to be done to move to FCP?
TOETOE55 commentedon Jan 10, 2024
The following code also passes Miri's checks
, but whether this should be UB is questionable. If I remember correctly, the current rule for the checks is that
&Tis readonly only whenTdoes not containUnsafeCell.RalfJung commentedon Oct 5, 2024
@rust-lang/libs-api do you see any blockers for stabilizing this?
No, this is fine -- you're only mutating things inside an
UnsafeCell.Correct, but similar code can already be written with
as_slice_of_cells. So, that's not really related to this tracking issue at all.Rollup merge of rust-lang#131281 - RalfJung:const-cell, r=Amanieu
Unrolled build for rust-lang#131281
Amanieu commentedon Oct 7, 2024
Should this be named
transposeinstead for consistency with the same method onMaybeUninit<[N; T]>and[MaybeUninit<T>; N]? It would also be an opportunity to introduce the reverse operation also namedtranspose.RalfJung commentedon Oct 7, 2024
I don't like
transposeas a name, it says very little about what the operation actually does.as_slice_of_cells/as_array_of_cellsis nicely explicit, which I think is a good thing.TOETOE55 commentedon Oct 7, 2024
What confuses me is that this code modifies
arr_of_cells: &[Cell]throughcell_arr: Cell<[i32; N]>, yetarr_of_cellsitself is not in anUnsafeCell, only its elements are.RalfJung commentedon Oct 7, 2024
I'm afraid I cannot parse that sentence... " the arr_of_cell is not " is not what?
4 remaining items
jsimmons commentedon Jul 17, 2025
I didn't realize before, but there's also Result::transpose and Option::transpose. Though I feel it makes a lot more sense in those cases as any alternative along these lines (
as_result_of_option???) would be somewhat "interesting" to understand upon first reading.Though I still think
as_slice_of_cells/as_array_of_cellsare more straightforward in this case, maybeMaybeUninit::as_array_of_uninitandMaybeUninit::as_slice_of_uninitwould be acceptable too?For what it's worth, there's also a bit of sporadic discussion about the naming of
MaybeUninit::transposeon the tracking issue, though I don't believe anybody has suggested the current style used here. I certainly think it would be nice if both APIs at least went the same direction.scottmcm commentedon Jul 20, 2025
My vibe-read is that
MaybeUninit::transposeis probably on the way out, so would lean to not using it here. It does have the issue that without knowing exactly the types involved it's pretty opaque for what it's doing, which is fine sometimes, but less fine for unsafe-related things likeMaybeUninittransformations where being more explicit than usual is often a good idea to avoid accidentally doing something might look right but accidentally uses the wrong type.Rollup merge of rust-lang#144054 - jsimmons:stabilize-as-array-of-cel…
Unrolled build for #144054
Rollup merge of rust-lang#144054 - jsimmons:stabilize-as-array-of-cel…
Rollup merge of rust-lang#145504 - Jules-Bertholet:more_conversion_tr…
Rollup merge of rust-lang#145504 - Jules-Bertholet:more_conversion_tr…
Rollup merge of rust-lang#145504 - Jules-Bertholet:more_conversion_tr…
Rollup merge of rust-lang#145504 - Jules-Bertholet:more_conversion_tr…
Rollup merge of rust-lang#145504 - Jules-Bertholet:more_conversion_tr…
Rollup merge of rust-lang#145504 - Jules-Bertholet:more_conversion_tr…
Unrolled build for #145504
Rollup merge of #145504 - Jules-Bertholet:more_conversion_trait_impls…
Rollup merge of #145504 - Jules-Bertholet:more_conversion_trait_impls…