Skip to content

Commit 692df2f

Browse files
authored
Remove _dropck flag from SendError
The nomicon has been outdated about this since 2015, see rust-lang/nomicon#363 for the update. We don't need to tell dropck that we are owning a T as it can already infer that from the generic parameter in the drop impl.
1 parent 3b27d35 commit 692df2f

1 file changed

Lines changed: 0 additions & 37 deletions

File tree

src/errors.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::{dealloc, Channel};
22
use core::fmt;
3-
use core::marker::PhantomData;
43
use core::mem;
54
use core::ptr::NonNull;
65

@@ -10,41 +9,6 @@ use core::ptr::NonNull;
109
/// The message that could not be sent can be retreived again with [`SendError::into_inner`].
1110
pub struct SendError<T> {
1211
channel_ptr: NonNull<Channel<T>>,
13-
/// Required due to the reasons outlined in
14-
/// [this section](https://doc.rust-lang.org/nomicon/dropck.html) of the nomicon, as well as
15-
/// the next section.
16-
///
17-
/// Without the phantom data, the following code would incorrectly compile. This code is
18-
/// invalid because `error` gets dropped first (struct fields are dropped in declaration order)
19-
/// but `oof` then accesses the data deallocated by `error`, causing a use-after-free.
20-
///
21-
/// ```compile_fail
22-
/// let (tx, rx) = oneshot::channel::<Box<u8>>();
23-
/// drop(rx);
24-
/// let error = tx.send(Box::new(0)).unwrap_err();
25-
///
26-
/// struct Oof<'a>(&'a u8);
27-
///
28-
/// impl<'a> Drop for Oof<'a> {
29-
/// fn drop(&mut self) {
30-
/// println!("{}", self.0);
31-
/// }
32-
/// }
33-
///
34-
/// struct Foo<'a> {
35-
/// error: SendError<Box<u8>>,
36-
/// oof: Option<Oof<'a>>,
37-
/// }
38-
///
39-
/// let mut foo = Foo {
40-
/// error,
41-
/// oof: None
42-
/// };
43-
///
44-
/// foo.oof = Some(Oof(&**foo.error.as_inner()));
45-
/// drop(foo);
46-
/// ```
47-
_dropck: PhantomData<T>,
4812
}
4913

5014
unsafe impl<T: Send> Send for SendError<T> {}
@@ -60,7 +24,6 @@ impl<T> SendError<T> {
6024
pub(crate) const unsafe fn new(channel_ptr: NonNull<Channel<T>>) -> Self {
6125
Self {
6226
channel_ptr,
63-
_dropck: PhantomData,
6427
}
6528
}
6629

0 commit comments

Comments
 (0)