-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for Cell::as_array_of_cells #88248
Comments
@oconnor663 Do you know who would be the right person to @ in order to get this reviewed/FCP'd? Given the existence of |
Wait, can I just do @rfcbot needs-fcp |
Does the following code violate the readonly constraint of let mut arr = [0; 10];
let cell_arr = Cell::from_mut(&mut arr);
let arr_of_cells = cell_arr.as_array_of_cells();
cell_arr.set([1; 10]);
// arr_of_cells was changed.
dbg!(arr_of_cells); |
@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 @scottmcm what needs to be done to move to FCP? |
The following code also passes Miri's checks use core::cell::Cell;
fn main() {
let mut opt = Some(1);
let cell_opt = Cell::from_mut(&mut opt);
let opt_cell = unsound(&cell_opt);
dbg!(opt_cell.as_ref().unwrap());
cell_opt.set(None);
dbg!(opt_cell);
}
fn unsound<T>(opt: &Cell<Option<T>>) -> &Option<Cell<T>> {
unsafe { &*(opt as *const Cell<Option<T>> as *const Option<Cell<T>>) }
} |
@rust-lang/libs-api do you see any blockers for stabilizing this?
No, this is fine -- you're only mutating things inside an
Correct, but similar code can already be written with |
make Cell unstably const Now that we can do interior mutability in `const`, most of the Cell API can be `const fn`. :) The main exception is `set`, because it drops the old value. So from const context one has to use `replace`, which delegates the responsibility for dropping to the caller. Tracking issue: rust-lang#131283 `as_array_of_cells` is itself still unstable to I added the const-ness to the feature gate for that function and not to `const_cell`, Cc rust-lang#88248. r? libs-api
Rollup merge of rust-lang#131281 - RalfJung:const-cell, r=Amanieu make Cell unstably const Now that we can do interior mutability in `const`, most of the Cell API can be `const fn`. :) The main exception is `set`, because it drops the old value. So from const context one has to use `replace`, which delegates the responsibility for dropping to the caller. Tracking issue: rust-lang#131283 `as_array_of_cells` is itself still unstable to I added the const-ness to the feature gate for that function and not to `const_cell`, Cc rust-lang#88248. r? libs-api
Should this be named |
I don't like |
What confuses me is that this code modifies |
I'm afraid I cannot parse that sentence... " the arr_of_cell is not " is not what? |
sorry, my English is not very good, the comment has been edited. |
Rust doesn't have an object model where there exists something like an "array object" that "contains" its fields or so. As far as Rust is concerned, an array is exactly the same thing as the collection of all its fields. So if call fields are fully covered by |
Feature gate:
#![feature(as_array_of_cells)]
This is a tracking issue for
Cell::as_array_of_cells
, the const-generic counterpart to the existingCell::as_slice_of_cells
.Public API
Steps / History
Unresolved Questions
The text was updated successfully, but these errors were encountered: