-
Notifications
You must be signed in to change notification settings - Fork 185
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
heapless Vec does not work good with stacked borrows, while std Vec does #514
Comments
miri doesn't have false positives, but it can have false negatives, ie it's possible it reports no error on code that is unsound. So "there's no miri error" doesn't prove it's sound. And i'm actually not sure if it is. This issue rust-lang/rust#85697 and particularly this comment rust-lang/rust#85697 (comment) have interesting info. So it seems it's OK with today's implementation. The reason it works for Vec is the current implementation contains a raw pointer to the data in the heap, and raw pointers allow aliasing. Allowing this for heapless would require adding an UnsafeCell to all containers, which would complicate the code and inhibit some optimizations, so I'm not sure if it's worth it. What are you doing that requires this? Why can't you use indexes instead of pointers? |
i have a structure like this struct StableVec<T, const N: usize> {
inner: Vec<Box<heapless::Vec<T, N>>>,
size: usize,
} it works as a vector with stable pointers, after pushing element to it, i am passing pointer to it to different parts of code, so they don't need to know about the whole vector, but recently i found a problem, that pushing a new element invalidates all previously created pointers |
Vec is not really designed for this. To make it sound you need some UnsafeCell somewhere, and IMO Vec is not the right place for it. I'd suggest you find an alternative. Maybe |
I've already done my workaround, mostly wanted to attract attention, to potential problem if someone wants to use heapless::Vec instead of regular Vec |
Pushing to heapless:Vec invalidates all previously created pointers into Vector
small example
miri shows error
right now i don't see any way to go around it, except for method like this
The text was updated successfully, but these errors were encountered: