Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit e6370a9

Browse files
committed
Support stacked borrows in BufWriter::into_inner_
This avoids errors in miri due to mem::forget currently behaving like a regular function call with the current stacked borrows model.
1 parent 9788b61 commit e6370a9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ use std::any::Any;
146146
use std::cell::RefCell;
147147
use std::io::prelude::*;
148148
use std::io::SeekFrom;
149-
use std::{cmp, error, fmt, io, mem, ptr};
149+
use std::mem::ManuallyDrop;
150+
use std::{cmp, error, fmt, io, ptr};
150151

151152
#[cfg(all(feature = "nightly", test))]
152153
mod benches;
@@ -629,11 +630,11 @@ impl<W: Write, P> BufWriter<W, P> {
629630

630631
// copy the fields out and forget `self` to avoid dropping twice
631632
fn into_inner_(self) -> (W, Buffer) {
633+
let s = ManuallyDrop::new(self);
632634
unsafe {
633635
// safe because we immediately forget `self`
634-
let inner = ptr::read(&self.inner);
635-
let buf = ptr::read(&self.buf);
636-
mem::forget(self);
636+
let inner = ptr::read(&s.inner);
637+
let buf = ptr::read(&s.buf);
637638
(inner, buf)
638639
}
639640
}

0 commit comments

Comments
 (0)