about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-01-19 17:22:09 +0530
committerGitHub <noreply@github.com>2020-01-19 17:22:09 +0530
commitd276e6942ea1af5c1ad79743e7f0ee797010023f (patch)
tree7c54dabdc1a8a57a5da2d78f5c87b21971428cbf
parenta29ba0010765cb63de71a92df8c701e8e87878fc (diff)
parentd7a18f89864a4360230e3cbbdcbf22d9864a86e0 (diff)
downloadrust-d276e6942ea1af5c1ad79743e7f0ee797010023f.tar.gz
rust-d276e6942ea1af5c1ad79743e7f0ee797010023f.zip
Rollup merge of #68348 - xfix:patch-14, r=nagisa
Make iter::Empty<T> Send and Sync for any T

Continuing from #57682

It's quite funny, when I initially submitted this pull request, I said "Likely nobody will be using that property of `iter::empty`", but then a year later I got a compilation error because it wasn't `Send` and `Sync`.

Unfortunately, `PhantomData<fn() -> T>` still errors out. Oh well. I proposed `
struct PhantomFnWorkaround<T>(fn() -> T);`, but dtolnay did not like it, so using explicit implementations.
-rw-r--r--src/libcore/iter/sources.rs5
-rw-r--r--src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs1
2 files changed, 6 insertions, 0 deletions
diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs
index a65d47cc2c1..25dfc573e41 100644
--- a/src/libcore/iter/sources.rs
+++ b/src/libcore/iter/sources.rs
@@ -208,6 +208,11 @@ pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
 #[stable(feature = "iter_empty", since = "1.2.0")]
 pub struct Empty<T>(marker::PhantomData<T>);
 
+#[stable(feature = "iter_empty_send_sync", since = "1.42.0")]
+unsafe impl<T> Send for Empty<T> {}
+#[stable(feature = "iter_empty_send_sync", since = "1.42.0")]
+unsafe impl<T> Sync for Empty<T> {}
+
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
 impl<T> fmt::Debug for Empty<T> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
diff --git a/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs b/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs
index 44beb9dc1e5..2f6d35f01be 100644
--- a/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs
+++ b/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs
@@ -88,6 +88,7 @@ fn main() {
     is_sync_send!((1..));
     is_sync_send!(repeat(1));
     is_sync_send!(empty::<usize>());
+    is_sync_send!(empty::<*mut i32>());
     is_sync_send!(once(1));
 
     // for option.rs