Skip to content

Commit cfc0f54

Browse files
authored
Rollup merge of rust-lang#68348 - xfix:patch-14, r=nagisa
Make iter::Empty<T> Send and Sync for any T Continuing from rust-lang#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.
2 parents 013f253 + d7a18f8 commit cfc0f54

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libcore/iter/sources.rs

+5
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
208208
#[stable(feature = "iter_empty", since = "1.2.0")]
209209
pub struct Empty<T>(marker::PhantomData<T>);
210210

211+
#[stable(feature = "iter_empty_send_sync", since = "1.42.0")]
212+
unsafe impl<T> Send for Empty<T> {}
213+
#[stable(feature = "iter_empty_send_sync", since = "1.42.0")]
214+
unsafe impl<T> Sync for Empty<T> {}
215+
211216
#[stable(feature = "core_impl_debug", since = "1.9.0")]
212217
impl<T> fmt::Debug for Empty<T> {
213218
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ fn main() {
8888
is_sync_send!((1..));
8989
is_sync_send!(repeat(1));
9090
is_sync_send!(empty::<usize>());
91+
is_sync_send!(empty::<*mut i32>());
9192
is_sync_send!(once(1));
9293

9394
// for option.rs

0 commit comments

Comments
 (0)