Skip to content

Commit 3f5c449

Browse files
committed
io::Error: avoid double-boxing of custom repr on 32 bits
1 parent 7de190a commit 3f5c449

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

library/std/src/io/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl Error {
601601
}
602602

603603
fn _new(kind: ErrorKind, error: Box<dyn error::Error + Send + Sync>) -> Error {
604-
Error { repr: Repr::new_custom(Box::new(Custom { kind, error })) }
604+
Error { repr: Repr::new_custom(Custom { kind, error }) }
605605
}
606606

607607
/// Creates a new I/O error from a known kind of error as well as a constant

library/std/src/io/error/repr_bitpacked.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ unsafe impl Send for Repr {}
133133
unsafe impl Sync for Repr {}
134134

135135
impl Repr {
136-
pub(super) fn new_custom(b: Box<Custom>) -> Self {
137-
let p = Box::into_raw(b).cast::<u8>();
136+
pub(super) fn new_custom(b: Custom) -> Self {
137+
let p = Box::into_raw(Box::new(b)).cast::<u8>();
138138
// Should only be possible if an allocator handed out a pointer with
139139
// wrong alignment.
140140
debug_assert_eq!(p.addr() & TAG_MASK, 0);
@@ -217,11 +217,11 @@ impl Repr {
217217
}
218218

219219
#[inline]
220-
pub(super) fn into_data(self) -> ErrorData<Box<Custom>> {
220+
pub(super) fn into_data(self) -> ErrorData<Custom> {
221221
let this = core::mem::ManuallyDrop::new(self);
222222
// Safety: We're a Repr, decode_repr is fine. The `Box::from_raw` is
223223
// safe because we prevent double-drop using `ManuallyDrop`.
224-
unsafe { decode_repr(this.0, |p| Box::from_raw(p)) }
224+
unsafe { decode_repr(this.0, |p| *Box::from_raw(p)) }
225225
}
226226
}
227227

library/std/src/io/error/repr_unpacked.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
55
use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage};
66

7-
type Inner = ErrorData<Box<Custom>>;
7+
type Inner = ErrorData<Custom>;
88

99
pub(super) struct Repr(Inner);
1010

1111
impl Repr {
1212
#[inline]
13-
pub(super) fn new_custom(b: Box<Custom>) -> Self {
13+
pub(super) fn new_custom(b: Custom) -> Self {
1414
Self(Inner::Custom(b))
1515
}
1616
#[inline]
@@ -26,7 +26,7 @@ impl Repr {
2626
Self(Inner::SimpleMessage(m))
2727
}
2828
#[inline]
29-
pub(super) fn into_data(self) -> ErrorData<Box<Custom>> {
29+
pub(super) fn into_data(self) -> ErrorData<Custom> {
3030
self.0
3131
}
3232
#[inline]

0 commit comments

Comments
 (0)