Skip to content

Commit

Permalink
Rollup merge of rust-lang#84179 - CDirkx:dont_send_sync, r=m-ou-se
Browse files Browse the repository at this point in the history
Explicitly implement `!Send` and `!Sync` for `sys::{Args, Env}`

Remove the field `_dont_send_or_sync_me: PhantomData<*mut ()>` in favor of an explicit implementation of `!Send` and `!Sync`.
  • Loading branch information
JohnTitor authored Apr 24, 2021
2 parents f30da53 + dc110af commit 759be25
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
8 changes: 4 additions & 4 deletions library/std/src/sys/hermit/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::ffi::OsString;
use crate::fmt;
use crate::marker::PhantomData;
use crate::vec;

/// One-time global initialization.
Expand All @@ -20,7 +19,6 @@ pub fn args() -> Args {

pub struct Args {
iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl fmt::Debug for Args {
Expand All @@ -29,6 +27,9 @@ impl fmt::Debug for Args {
}
}

impl !Send for Args {}
impl !Sync for Args {}

impl Iterator for Args {
type Item = OsString;
fn next(&mut self) -> Option<OsString> {
Expand All @@ -54,7 +55,6 @@ impl DoubleEndedIterator for Args {
mod imp {
use super::Args;
use crate::ffi::{CStr, OsString};
use crate::marker::PhantomData;
use crate::ptr;
use crate::sys_common::os_str_bytes::*;

Expand All @@ -77,7 +77,7 @@ mod imp {
}

pub fn args() -> Args {
Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData }
Args { iter: clone().into_iter() }
}

fn clone() -> Vec<OsString> {
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/hermit/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ pub fn init_environment(env: *const *const i8) {

pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl !Send for Env {}
impl !Sync for Env {}

impl Iterator for Env {
type Item = (OsString, OsString);
fn next(&mut self) -> Option<(OsString, OsString)> {
Expand All @@ -134,7 +136,7 @@ pub fn env() -> Env {
result.push((key.clone(), value.clone()));
}

return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
return Env { iter: result.into_iter() };
}
}

Expand Down
13 changes: 6 additions & 7 deletions library/std/src/sys/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use crate::ffi::OsString;
use crate::fmt;
use crate::marker::PhantomData;
use crate::vec;

/// One-time global initialization.
Expand All @@ -27,9 +26,11 @@ pub fn args() -> Args {

pub struct Args {
iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl !Send for Args {}
impl !Sync for Args {}

impl fmt::Debug for Args {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.as_slice().fmt(f)
Expand Down Expand Up @@ -77,7 +78,6 @@ impl DoubleEndedIterator for Args {
mod imp {
use super::Args;
use crate::ffi::{CStr, OsString};
use crate::marker::PhantomData;
use crate::os::unix::prelude::*;
use crate::ptr;
use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering};
Expand Down Expand Up @@ -134,7 +134,7 @@ mod imp {
}

pub fn args() -> Args {
Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData }
Args { iter: clone().into_iter() }
}

fn clone() -> Vec<OsString> {
Expand All @@ -156,7 +156,6 @@ mod imp {
mod imp {
use super::Args;
use crate::ffi::CStr;
use crate::marker::PhantomData;

pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}

Expand All @@ -181,7 +180,7 @@ mod imp {
})
.collect::<Vec<_>>()
};
Args { iter: vec.into_iter(), _dont_send_or_sync_me: PhantomData }
Args { iter: vec.into_iter() }
}

// As _NSGetArgc and _NSGetArgv aren't mentioned in iOS docs
Expand Down Expand Up @@ -248,6 +247,6 @@ mod imp {
}
}

Args { iter: res.into_iter(), _dont_send_or_sync_me: PhantomData }
Args { iter: res.into_iter() }
}
}
7 changes: 4 additions & 3 deletions library/std/src/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::ffi::{CStr, CString, OsStr, OsString};
use crate::fmt;
use crate::io;
use crate::iter;
use crate::marker::PhantomData;
use crate::mem;
use crate::memchr;
use crate::path::{self, PathBuf};
Expand Down Expand Up @@ -460,9 +459,11 @@ pub fn current_exe() -> io::Result<PathBuf> {

pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl !Send for Env {}
impl !Sync for Env {}

impl Iterator for Env {
type Item = (OsString, OsString);
fn next(&mut self) -> Option<(OsString, OsString)> {
Expand Down Expand Up @@ -510,7 +511,7 @@ pub fn env() -> Env {
environ = environ.add(1);
}
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
return Env { iter: result.into_iter() };
}

fn parse(input: &[u8]) -> Option<(OsString, OsString)> {
Expand Down
10 changes: 4 additions & 6 deletions library/std/src/sys/wasi/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::ffi::{CStr, OsStr, OsString};
use crate::fmt;
use crate::marker::PhantomData;
use crate::os::wasi::ffi::OsStrExt;
use crate::vec;

Expand All @@ -12,15 +11,14 @@ pub unsafe fn cleanup() {}

pub struct Args {
iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl !Send for Args {}
impl !Sync for Args {}

/// Returns the command line arguments
pub fn args() -> Args {
Args {
iter: maybe_args().unwrap_or(Vec::new()).into_iter(),
_dont_send_or_sync_me: PhantomData,
}
Args { iter: maybe_args().unwrap_or(Vec::new()).into_iter() }
}

fn maybe_args() -> Option<Vec<OsString>> {
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/sys/wasi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl !Send for Env {}
impl !Sync for Env {}

impl Iterator for Env {
type Item = (OsString, OsString);
fn next(&mut self) -> Option<(OsString, OsString)> {
Expand All @@ -155,7 +157,7 @@ pub fn env() -> Env {
environ = environ.add(1);
}
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
return Env { iter: result.into_iter() };
}

// See src/libstd/sys/unix/os.rs, same as that
Expand Down
7 changes: 4 additions & 3 deletions library/std/src/sys/wasm/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::ffi::OsString;
use crate::fmt;
use crate::marker::PhantomData;
use crate::vec;

pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
Expand All @@ -10,14 +9,16 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
pub unsafe fn cleanup() {}

pub fn args() -> Args {
Args { iter: Vec::new().into_iter(), _dont_send_or_sync_me: PhantomData }
Args { iter: Vec::new().into_iter() }
}

pub struct Args {
iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
}

impl !Send for Args {}
impl !Sync for Args {}

impl fmt::Debug for Args {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.as_slice().fmt(f)
Expand Down

0 comments on commit 759be25

Please sign in to comment.