Skip to content

Commit

Permalink
Remove _dropck flags
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Noratrieb committed Aug 14, 2022
1 parent 3b27d35 commit f5a00c7
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{dealloc, Channel};
use core::fmt;
use core::marker::PhantomData;
use core::mem;
use core::ptr::NonNull;

Expand All @@ -10,41 +9,6 @@ use core::ptr::NonNull;
/// The message that could not be sent can be retreived again with [`SendError::into_inner`].
pub struct SendError<T> {
channel_ptr: NonNull<Channel<T>>,
/// Required due to the reasons outlined in
/// [this section](https://doc.rust-lang.org/nomicon/dropck.html) of the nomicon, as well as
/// the next section.
///
/// Without the phantom data, the following code would incorrectly compile. This code is
/// invalid because `error` gets dropped first (struct fields are dropped in declaration order)
/// but `oof` then accesses the data deallocated by `error`, causing a use-after-free.
///
/// ```compile_fail
/// let (tx, rx) = oneshot::channel::<Box<u8>>();
/// drop(rx);
/// let error = tx.send(Box::new(0)).unwrap_err();
///
/// struct Oof<'a>(&'a u8);
///
/// impl<'a> Drop for Oof<'a> {
/// fn drop(&mut self) {
/// println!("{}", self.0);
/// }
/// }
///
/// struct Foo<'a> {
/// error: SendError<Box<u8>>,
/// oof: Option<Oof<'a>>,
/// }
///
/// let mut foo = Foo {
/// error,
/// oof: None
/// };
///
/// foo.oof = Some(Oof(&**foo.error.as_inner()));
/// drop(foo);
/// ```
_dropck: PhantomData<T>,
}

unsafe impl<T: Send> Send for SendError<T> {}
Expand All @@ -60,7 +24,6 @@ impl<T> SendError<T> {
pub(crate) const unsafe fn new(channel_ptr: NonNull<Channel<T>>) -> Self {
Self {
channel_ptr,
_dropck: PhantomData,
}
}

Expand Down

0 comments on commit f5a00c7

Please sign in to comment.