-
Notifications
You must be signed in to change notification settings - Fork 8
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
Inline storage types need to use UnsafeCell
or a get_mut
resolver
#3
Comments
InlineStorage
types need to use UnsafeCell
or a get_mut
resolverUnsafeCell
or a get_mut
resolver
Is that a problem? I hesitated adding Did I miss something at the time? Did something change? Or do you believe this is a shortcoming of MIRI? |
Your test must've not actually used the place mutably, because even with default miri settings, this causes UB: use storage_poc::{collections::RawBox, inline::SingleElement};
fn main() {
let storage = SingleElement::<usize>::default();
let mut boxed = RawBox::new(0usize, storage).unwrap();
*boxed = 2;
}
|
I'm working on a revised proposal I hope to propose for MCP/in-tree testing (and maybe a foundation grant 👉👈) when I ran into this. |
That's great to hear! I don't have much time, unfortunately, but I'd be happy to support you. At the very least, feel free to reuse as much code/ideas from this repository as you wish.
I thought they would, but may have missed it :( In this case, I would guess the cleanest is to add a |
If you have time to glance over it, my current revision lives at https://github.com/CAD97/storages-api |
Should be solved by 08f60c1 . I also went ahead and switched to Unlike your API, I did not leave any provision for |
<SingleElement as SingleElementStorage>::get
allows you to go from&SingleElement
to&mut T
, violating&
's mutability restrictions. The same goes for any other inline storage. There are two solutions to this:UnsafeCell
in inline storages (pessimizesBox<T, InlineStorage>
), orget_mut(&mut self, handle: Handle<T>) -> NonNull<T>
resolver, and require that mutable pointee access goes throughget_mut
unless a markertrait SharedMutabilityStorage
is implemented.(To allow e.g.
split_at_mut
style use cases, it could beget_mut(&mut self, [Handle<T>; N]) -> [NonNull<T>; N]
,get_mut(&mut self, Handle<T>) -> (&mut Self, NonNull<T>)
, or even justget(*mut self, Handle<T>) -> NonNull<T>
.)The text was updated successfully, but these errors were encountered: