-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ManuallyDrop with bumpalo's Box instead of mem::forget
Miri now reports UB with some uses of bumpalo's Box where it did not before: rust-lang/miri#2704 The previous behavior of Miri was a false negative. rustc applies noalias to newtype wrappers around &mut, so Miri has to retag &mut when passed by value to a function even if it is in a wrapper struct, such as bumpalo's Box. mem::forget is a common aliasing footgun, because for a unique-owning wrapper like Box, leaking an RAII handle re-asserts the uniqueness of the handle as it is sent to the void. Ouch. ManuallyDrop solves this problem.
- Loading branch information
Showing
3 changed files
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![cfg(feature = "boxed")] | ||
|
||
use bumpalo::Bump; | ||
use bumpalo::boxed::Box; | ||
|
||
#[test] | ||
fn into_raw_aliasing() { | ||
let bump = Bump::new(); | ||
let boxed = Box::new_in(1, &bump); | ||
let raw = Box::into_raw(boxed); | ||
|
||
let mut_ref = unsafe { &mut *raw }; | ||
dbg!(mut_ref); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ mod tests; | |
mod try_alloc_try_with; | ||
mod try_alloc_with; | ||
mod vec; | ||
mod boxed; | ||
|
||
fn main() {} |