Skip to content

Explicitly implement !Send and !Sync for sys::{Args, Env} #84179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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