Skip to content

Commit 7cbe7fa

Browse files
authored
Rollup merge of rust-lang#114965 - benschulz:mpsc-drop, r=dtolnay
Remove Drop impl of mpsc Receiver and (Sync)Sender This change removes the empty `Drop` implementations for `mpsc::Receiver`, `mpsc::Sender` and `mpsc::SyncSender`. These implementations do not specify `#[may_dangle]`, so by removing them we make `mpsc` types play nice with drop check. This was previously attempted in [rust-lang#105243](rust-lang#105243 (comment)) but then [abandoned due to a test failure](rust-lang#105243 (comment)). I've aligned the test with those for `Mutex` and `RwLock`.
2 parents cdd182c + a38ea96 commit 7cbe7fa

File tree

3 files changed

+4
-21
lines changed

3 files changed

+4
-21
lines changed

library/std/src/sync/mpsc/mod.rs

-15
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,6 @@ impl<T> Clone for Sender<T> {
626626
}
627627
}
628628

629-
#[stable(feature = "rust1", since = "1.0.0")]
630-
impl<T> Drop for Sender<T> {
631-
fn drop(&mut self) {}
632-
}
633-
634629
#[stable(feature = "mpsc_debug", since = "1.8.0")]
635630
impl<T> fmt::Debug for Sender<T> {
636631
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -755,11 +750,6 @@ impl<T> Clone for SyncSender<T> {
755750
}
756751
}
757752

758-
#[stable(feature = "rust1", since = "1.0.0")]
759-
impl<T> Drop for SyncSender<T> {
760-
fn drop(&mut self) {}
761-
}
762-
763753
#[stable(feature = "mpsc_debug", since = "1.8.0")]
764754
impl<T> fmt::Debug for SyncSender<T> {
765755
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -1096,11 +1086,6 @@ impl<T> IntoIterator for Receiver<T> {
10961086
}
10971087
}
10981088

1099-
#[stable(feature = "rust1", since = "1.0.0")]
1100-
impl<T> Drop for Receiver<T> {
1101-
fn drop(&mut self) {}
1102-
}
1103-
11041089
#[stable(feature = "mpsc_debug", since = "1.8.0")]
11051090
impl<T> fmt::Debug for Receiver<T> {
11061091
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

tests/ui/span/send-is-not-static-std-sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn channel() {
4646
tx.send(&z).unwrap();
4747
}
4848
//~^^ ERROR `z` does not live long enough
49-
// (channels lack #[may_dangle], thus their dtors are implicit uses of `z`)
49+
tx.use_ref(); // (channel drop glue does not use `z` => needs explicit use)
5050
}
5151

5252
fn main() {}

tests/ui/span/send-is-not-static-std-sync.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ LL | tx.send(&z).unwrap();
7575
| ^^ borrowed value does not live long enough
7676
LL | }
7777
| - `z` dropped here while still borrowed
78-
...
79-
LL | }
80-
| - borrow might be used here, when `tx` is dropped and runs the `Drop` code for type `Sender`
81-
|
82-
= note: values in a scope are dropped in the opposite order they are defined
78+
LL |
79+
LL | tx.use_ref(); // (channel drop glue does not use `z` => needs explicit use)
80+
| -- borrow later used here
8381

8482
error: aborting due to 6 previous errors
8583

0 commit comments

Comments
 (0)