未验证 提交 78306f03 编写于 作者: Y Yuki Okushi 提交者: GitHub

Rollup merge of #84179 - CDirkx:dont_send_sync, r=m-ou-se

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`.
use crate::ffi::OsString; use crate::ffi::OsString;
use crate::fmt; use crate::fmt;
use crate::marker::PhantomData;
use crate::vec; use crate::vec;
/// One-time global initialization. /// One-time global initialization.
...@@ -20,7 +19,6 @@ pub fn args() -> Args { ...@@ -20,7 +19,6 @@ pub fn args() -> Args {
pub struct Args { pub struct Args {
iter: vec::IntoIter<OsString>, iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl fmt::Debug for Args { impl fmt::Debug for Args {
...@@ -29,6 +27,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ...@@ -29,6 +27,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
} }
} }
impl !Send for Args {}
impl !Sync for Args {}
impl Iterator for Args { impl Iterator for Args {
type Item = OsString; type Item = OsString;
fn next(&mut self) -> Option<OsString> { fn next(&mut self) -> Option<OsString> {
...@@ -54,7 +55,6 @@ fn next_back(&mut self) -> Option<OsString> { ...@@ -54,7 +55,6 @@ fn next_back(&mut self) -> Option<OsString> {
mod imp { mod imp {
use super::Args; use super::Args;
use crate::ffi::{CStr, OsString}; use crate::ffi::{CStr, OsString};
use crate::marker::PhantomData;
use crate::ptr; use crate::ptr;
use crate::sys_common::os_str_bytes::*; use crate::sys_common::os_str_bytes::*;
...@@ -77,7 +77,7 @@ pub unsafe fn cleanup() { ...@@ -77,7 +77,7 @@ pub unsafe fn cleanup() {
} }
pub fn args() -> Args { pub fn args() -> Args {
Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData } Args { iter: clone().into_iter() }
} }
fn clone() -> Vec<OsString> { fn clone() -> Vec<OsString> {
......
...@@ -110,9 +110,11 @@ fn parse(input: &[u8]) -> Option<(OsString, OsString)> { ...@@ -110,9 +110,11 @@ fn parse(input: &[u8]) -> Option<(OsString, OsString)> {
pub struct Env { pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>, iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl !Send for Env {}
impl !Sync for Env {}
impl Iterator for Env { impl Iterator for Env {
type Item = (OsString, OsString); type Item = (OsString, OsString);
fn next(&mut self) -> Option<(OsString, OsString)> { fn next(&mut self) -> Option<(OsString, OsString)> {
...@@ -134,7 +136,7 @@ pub fn env() -> Env { ...@@ -134,7 +136,7 @@ pub fn env() -> Env {
result.push((key.clone(), value.clone())); result.push((key.clone(), value.clone()));
} }
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; return Env { iter: result.into_iter() };
} }
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
use crate::ffi::OsString; use crate::ffi::OsString;
use crate::fmt; use crate::fmt;
use crate::marker::PhantomData;
use crate::vec; use crate::vec;
/// One-time global initialization. /// One-time global initialization.
...@@ -27,9 +26,11 @@ pub fn args() -> Args { ...@@ -27,9 +26,11 @@ pub fn args() -> Args {
pub struct Args { pub struct Args {
iter: vec::IntoIter<OsString>, iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl !Send for Args {}
impl !Sync for Args {}
impl fmt::Debug for Args { impl fmt::Debug for Args {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.as_slice().fmt(f) self.iter.as_slice().fmt(f)
...@@ -77,7 +78,6 @@ fn next_back(&mut self) -> Option<OsString> { ...@@ -77,7 +78,6 @@ fn next_back(&mut self) -> Option<OsString> {
mod imp { mod imp {
use super::Args; use super::Args;
use crate::ffi::{CStr, OsString}; use crate::ffi::{CStr, OsString};
use crate::marker::PhantomData;
use crate::os::unix::prelude::*; use crate::os::unix::prelude::*;
use crate::ptr; use crate::ptr;
use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering}; use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering};
...@@ -134,7 +134,7 @@ pub unsafe fn cleanup() { ...@@ -134,7 +134,7 @@ pub unsafe fn cleanup() {
} }
pub fn args() -> Args { pub fn args() -> Args {
Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData } Args { iter: clone().into_iter() }
} }
fn clone() -> Vec<OsString> { fn clone() -> Vec<OsString> {
...@@ -156,7 +156,6 @@ fn clone() -> Vec<OsString> { ...@@ -156,7 +156,6 @@ fn clone() -> Vec<OsString> {
mod imp { mod imp {
use super::Args; use super::Args;
use crate::ffi::CStr; use crate::ffi::CStr;
use crate::marker::PhantomData;
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
...@@ -181,7 +180,7 @@ pub fn args() -> Args { ...@@ -181,7 +180,7 @@ pub fn args() -> Args {
}) })
.collect::<Vec<_>>() .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 // As _NSGetArgc and _NSGetArgv aren't mentioned in iOS docs
...@@ -248,6 +247,6 @@ pub fn args() -> Args { ...@@ -248,6 +247,6 @@ pub fn args() -> Args {
} }
} }
Args { iter: res.into_iter(), _dont_send_or_sync_me: PhantomData } Args { iter: res.into_iter() }
} }
} }
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
use crate::fmt; use crate::fmt;
use crate::io; use crate::io;
use crate::iter; use crate::iter;
use crate::marker::PhantomData;
use crate::mem; use crate::mem;
use crate::memchr; use crate::memchr;
use crate::path::{self, PathBuf}; use crate::path::{self, PathBuf};
...@@ -460,9 +459,11 @@ pub fn current_exe() -> io::Result<PathBuf> { ...@@ -460,9 +459,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
pub struct Env { pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>, iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl !Send for Env {}
impl !Sync for Env {}
impl Iterator for Env { impl Iterator for Env {
type Item = (OsString, OsString); type Item = (OsString, OsString);
fn next(&mut self) -> Option<(OsString, OsString)> { fn next(&mut self) -> Option<(OsString, OsString)> {
...@@ -510,7 +511,7 @@ pub fn env() -> Env { ...@@ -510,7 +511,7 @@ pub fn env() -> Env {
environ = environ.add(1); 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)> { fn parse(input: &[u8]) -> Option<(OsString, OsString)> {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
use crate::ffi::{CStr, OsStr, OsString}; use crate::ffi::{CStr, OsStr, OsString};
use crate::fmt; use crate::fmt;
use crate::marker::PhantomData;
use crate::os::wasi::ffi::OsStrExt; use crate::os::wasi::ffi::OsStrExt;
use crate::vec; use crate::vec;
...@@ -12,15 +11,14 @@ pub unsafe fn cleanup() {} ...@@ -12,15 +11,14 @@ pub unsafe fn cleanup() {}
pub struct Args { pub struct Args {
iter: vec::IntoIter<OsString>, iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl !Send for Args {}
impl !Sync for Args {}
/// Returns the command line arguments /// Returns the command line arguments
pub fn args() -> Args { pub fn args() -> Args {
Args { Args { iter: maybe_args().unwrap_or(Vec::new()).into_iter() }
iter: maybe_args().unwrap_or(Vec::new()).into_iter(),
_dont_send_or_sync_me: PhantomData,
}
} }
fn maybe_args() -> Option<Vec<OsString>> { fn maybe_args() -> Option<Vec<OsString>> {
......
...@@ -129,9 +129,11 @@ pub fn current_exe() -> io::Result<PathBuf> { ...@@ -129,9 +129,11 @@ pub fn current_exe() -> io::Result<PathBuf> {
} }
pub struct Env { pub struct Env {
iter: vec::IntoIter<(OsString, OsString)>, iter: vec::IntoIter<(OsString, OsString)>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl !Send for Env {}
impl !Sync for Env {}
impl Iterator for Env { impl Iterator for Env {
type Item = (OsString, OsString); type Item = (OsString, OsString);
fn next(&mut self) -> Option<(OsString, OsString)> { fn next(&mut self) -> Option<(OsString, OsString)> {
...@@ -155,7 +157,7 @@ pub fn env() -> Env { ...@@ -155,7 +157,7 @@ pub fn env() -> Env {
environ = environ.add(1); 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 // See src/libstd/sys/unix/os.rs, same as that
......
use crate::ffi::OsString; use crate::ffi::OsString;
use crate::fmt; use crate::fmt;
use crate::marker::PhantomData;
use crate::vec; use crate::vec;
pub unsafe fn init(_argc: isize, _argv: *const *const u8) { pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
...@@ -10,14 +9,16 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8) { ...@@ -10,14 +9,16 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
pub unsafe fn cleanup() {} pub unsafe fn cleanup() {}
pub fn args() -> Args { 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 { pub struct Args {
iter: vec::IntoIter<OsString>, iter: vec::IntoIter<OsString>,
_dont_send_or_sync_me: PhantomData<*mut ()>,
} }
impl !Send for Args {}
impl !Sync for Args {}
impl fmt::Debug for Args { impl fmt::Debug for Args {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.as_slice().fmt(f) self.iter.as_slice().fmt(f)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册