-
Notifications
You must be signed in to change notification settings - Fork 349
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
False positive around mem::forget and ManuallyDrop (or the replace_with
crate has UB)
#1508
Comments
Yeah I think |
Okay, interesting. I’m confused why miri mentions the Anyways, it probably doesn’t hurt to propose a change to pub fn on_unwind<F: FnOnce() -> T, T, P: FnOnce()>(f: F, p: P) -> T {
let x = OnDrop(mem::ManuallyDrop::new(p));
let t = f();
let _closure = unsafe { ptr::read(&*x.0) };
mem::forget(x);
t
} Edit: even better... pub fn on_unwind<F: FnOnce() -> T, T, P: FnOnce()>(f: F, p: P) -> T {
let x = OnDrop(mem::ManuallyDrop::new(p));
let t = f();
let mut x = mem::ManuallyDrop::new(x);
unsafe {mem::ManuallyDrop::drop(&mut x.0)};
t
} |
I’ll close this for now as it might indeed be UB and it seems to be unidiomatic use of |
As shown in rust-lang/miri#1508, it was possible to "find UB" in `replace_with` with Miri.
That's a fair point. However:
In particular, a |
As shown in rust-lang/miri#1508, it was possible to "find UB" in `replace_with` with Miri.
For the record, the |
I’m posting this issue here rather than in the
replace_with
crate because I’m personally not seeing any UB in their code. And because I’m guessing the people around here might be more knowledgeable on the topic of inconspicuous undefined behavior.I’m not too accustomed with miri, in particular I don’t even know if false positives (positive in the sense that UB has been found) are supposed to happen or not.
Here’s my code
using replace_with v0.1.6.
Their (relevant) code is:
Miri output:
The text was updated successfully, but these errors were encountered: