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
Dylan-DPC authored Apr 22, 2021
2 parents 1ecf9b2 + 2ecc820 commit c3eb4b8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 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,5 +1,4 @@
use crate::ffi::OsString;
use crate::marker::PhantomData;
use crate::vec;

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

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

impl Args {
Expand All @@ -28,6 +26,9 @@ impl Args {
}
}

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

impl Iterator for Args {
type Item = OsString;
fn next(&mut self) -> Option<OsString> {
Expand All @@ -53,7 +54,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 @@ -76,7 +76,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
7 changes: 4 additions & 3 deletions library/std/src/sys/hermit/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::error::Error as StdError;
use crate::ffi::{CStr, OsStr, OsString};
use crate::fmt;
use crate::io;
use crate::marker::PhantomData;
use crate::memchr;
use crate::path::{self, PathBuf};
use crate::str;
Expand Down Expand Up @@ -110,9 +109,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 +135,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 @@ -6,7 +6,6 @@
#![allow(dead_code)] // runtime init functions not used during testing

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

/// One-time global initialization.
Expand All @@ -26,9 +25,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 Args {
pub fn inner_debug(&self) -> &[OsString] {
self.iter.as_slice()
Expand Down Expand Up @@ -76,7 +77,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 @@ -133,7 +133,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 @@ -155,7 +155,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 @@ -180,7 +179,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 @@ -247,6 +246,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
@@ -1,7 +1,6 @@
#![deny(unsafe_op_in_unsafe_fn)]

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

Expand All @@ -11,15 +10,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
7 changes: 4 additions & 3 deletions library/std/src/sys/wasi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::error::Error as StdError;
use crate::ffi::{CStr, CString, OsStr, OsString};
use crate::fmt;
use crate::io;
use crate::marker::PhantomData;
use crate::os::wasi::prelude::*;
use crate::path::{self, PathBuf};
use crate::str;
Expand Down Expand Up @@ -129,9 +128,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 +156,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,5 +1,4 @@
use crate::ffi::OsString;
use crate::marker::PhantomData;
use crate::vec;

pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
Expand All @@ -9,14 +8,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 Args {
pub fn inner_debug(&self) -> &[OsString] {
self.iter.as_slice()
Expand Down

0 comments on commit c3eb4b8

Please sign in to comment.