Conversation
`&mut T` which can be used to move `T` between threads!
address stacked borrows UB detected by Miri. This is similar to mozilla/atomic_refcell#18
Imberflur
left a comment
There was a problem hiding this comment.
Here are some notes to help reviewers
| miri: | ||
| name: "Miri" | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: true # Needed until all Miri errors are fixed |
There was a problem hiding this comment.
Added Miri to the CI, however it still runs into some errors in the MetaTable code that is handling vtable pointers. So I set continue-on-error: true for now (hopefully this does what I think it does...)
There was a problem hiding this comment.
Well it seems like there is no way to not show the red X in the PR list: https://github.com/orgs/community/discussions/15452
| black_box(world.fetch::<DeltaTime>()); | ||
| black_box(world.fetch::<VecStorage<Pos>>()); | ||
| black_box(world.fetch::<VecStorage<Spring>>()); |
There was a problem hiding this comment.
I added black_box just to be more sure that the compiler doesn't optimize these out (didn't really see much difference in the benchmark though)
| // https://github.com/rust-lang/rust/issues/63787 | ||
| #[test] | ||
| fn drop_and_borrow_in_fn_call() { | ||
| fn drop_and_borrow(cell: &TrustCell<u8>, borrow: Ref<'_, u8>) { | ||
| drop(borrow); | ||
| *cell.borrow_mut() = 7u8; | ||
| } | ||
|
|
||
| let a = TrustCell::new(4u8); | ||
| let borrow = a.borrow(); | ||
| drop_and_borrow(&a, borrow); | ||
| } |
There was a problem hiding this comment.
I added this to reproduce the scenario in the issue linked in the comment, however Miri was already reporting UB due to retagging of the reference by the mem::forget call in RefMut::map.
Fixing some unsoundness, see commit messages.
I'm hoping to eventually replace TrustCell with atomic_refcell::AtomicRefCell, however that should probably wait on mozilla/atomic_refcell#18