diff options
| author | bors <bors@rust-lang.org> | 2021-07-02 20:00:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-02 20:00:51 +0000 |
| commit | 798baebde1fe77e5a660490ec64e727a5d79970d (patch) | |
| tree | 271df8bcac32ffd8ffd2d52d4a56f0094cecdcbf /library/std | |
| parent | 2545459bff0aae43288e2e17bff0d332c49a6353 (diff) | |
| parent | 1b136323dcd219241bf8b8949f50992a83b28954 (diff) | |
| download | rust-798baebde1fe77e5a660490ec64e727a5d79970d.tar.gz rust-798baebde1fe77e5a660490ec64e727a5d79970d.zip | |
Auto merge of #86817 - JohnTitor:rollup-rcysc95, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #84029 (add `track_path::path` fn for usage in `proc_macro`s) - #85001 (Merge `sys_common::bytestring` back into `os_str_bytes`) - #86308 (Docs: clarify that certain intrinsics are not unsafe) - #86796 (Add a regression test for issue-70703) - #86803 (Remove & from Command::args calls in documentation) - #86807 (Fix double import in wasm thread ) - #86813 (Add a help message to `unused_doc_comments` lint) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/process.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/wasm/atomics/thread.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys_common/bytestring.rs | 26 | ||||
| -rw-r--r-- | library/std/src/sys_common/bytestring/tests.rs | 19 | ||||
| -rw-r--r-- | library/std/src/sys_common/mod.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys_common/os_str_bytes.rs | 22 | ||||
| -rw-r--r-- | library/std/src/sys_common/os_str_bytes/tests.rs | 10 |
7 files changed, 30 insertions, 53 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs index e6f8b9cfcc7..b46d3dfc1e7 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -452,7 +452,7 @@ impl fmt::Debug for ChildStderr { /// /// let output = if cfg!(target_os = "windows") { /// Command::new("cmd") -/// .args(&["/C", "echo hello"]) +/// .args(["/C", "echo hello"]) /// .output() /// .expect("failed to execute process") /// } else { @@ -609,7 +609,7 @@ impl Command { /// use std::process::Command; /// /// Command::new("ls") - /// .args(&["-l", "-a"]) + /// .args(["-l", "-a"]) /// .spawn() /// .expect("ls command failed to start"); /// ``` diff --git a/library/std/src/sys/wasm/atomics/thread.rs b/library/std/src/sys/wasm/atomics/thread.rs index 09714835104..a66ab083757 100644 --- a/library/std/src/sys/wasm/atomics/thread.rs +++ b/library/std/src/sys/wasm/atomics/thread.rs @@ -1,4 +1,3 @@ -use super::unsupported; use crate::ffi::CStr; use crate::io; use crate::num::NonZeroUsize; diff --git a/library/std/src/sys_common/bytestring.rs b/library/std/src/sys_common/bytestring.rs deleted file mode 100644 index 97fba60c271..00000000000 --- a/library/std/src/sys_common/bytestring.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![allow(dead_code)] - -#[cfg(test)] -mod tests; - -use crate::fmt::{Formatter, Result, Write}; -use core::str::lossy::{Utf8Lossy, Utf8LossyChunk}; - -pub fn debug_fmt_bytestring(slice: &[u8], f: &mut Formatter<'_>) -> Result { - // Writes out a valid unicode string with the correct escape sequences - fn write_str_escaped(f: &mut Formatter<'_>, s: &str) -> Result { - for c in s.chars().flat_map(|c| c.escape_debug()) { - f.write_char(c)? - } - Ok(()) - } - - f.write_str("\"")?; - for Utf8LossyChunk { valid, broken } in Utf8Lossy::from_bytes(slice).chunks() { - write_str_escaped(f, valid)?; - for b in broken { - write!(f, "\\x{:02X}", b)?; - } - } - f.write_str("\"") -} diff --git a/library/std/src/sys_common/bytestring/tests.rs b/library/std/src/sys_common/bytestring/tests.rs deleted file mode 100644 index 1685f087d18..00000000000 --- a/library/std/src/sys_common/bytestring/tests.rs +++ /dev/null @@ -1,19 +0,0 @@ -use super::*; -use crate::fmt::{Debug, Formatter, Result}; - -#[test] -fn smoke() { - struct Helper<'a>(&'a [u8]); - - impl Debug for Helper<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { - debug_fmt_bytestring(self.0, f) - } - } - - let input = b"\xF0hello,\tworld"; - let expected = r#""\xF0hello,\tworld""#; - let output = format!("{:?}", Helper(input)); - - assert!(output == expected); -} diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index 1a9caa22c92..db83bad60d8 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -21,7 +21,6 @@ mod tests; pub mod backtrace; -pub mod bytestring; pub mod condvar; pub mod fs; pub mod io; diff --git a/library/std/src/sys_common/os_str_bytes.rs b/library/std/src/sys_common/os_str_bytes.rs index 470f401a6d2..569600470db 100644 --- a/library/std/src/sys_common/os_str_bytes.rs +++ b/library/std/src/sys_common/os_str_bytes.rs @@ -2,16 +2,18 @@ //! systems: just a `Vec<u8>`/`[u8]`. use crate::borrow::Cow; - use crate::fmt; +use crate::fmt::Write; use crate::mem; use crate::rc::Rc; use crate::str; use crate::sync::Arc; -use crate::sys_common::bytestring::debug_fmt_bytestring; use crate::sys_common::{AsInner, IntoInner}; -use core::str::lossy::Utf8Lossy; +use core::str::lossy::{Utf8Lossy, Utf8LossyChunk}; + +#[cfg(test)] +mod tests; #[derive(Hash)] #[repr(transparent)] @@ -26,7 +28,19 @@ pub struct Slice { impl fmt::Debug for Slice { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - debug_fmt_bytestring(&self.inner, formatter) + // Writes out a valid unicode string with the correct escape sequences + + formatter.write_str("\"")?; + for Utf8LossyChunk { valid, broken } in Utf8Lossy::from_bytes(&self.inner).chunks() { + for c in valid.chars().flat_map(|c| c.escape_debug()) { + formatter.write_char(c)? + } + + for b in broken { + write!(formatter, "\\x{:02X}", b)?; + } + } + formatter.write_str("\"") } } diff --git a/library/std/src/sys_common/os_str_bytes/tests.rs b/library/std/src/sys_common/os_str_bytes/tests.rs new file mode 100644 index 00000000000..37967378155 --- /dev/null +++ b/library/std/src/sys_common/os_str_bytes/tests.rs @@ -0,0 +1,10 @@ +use super::*; + +#[test] +fn slice_debug_output() { + let input = Slice::from_u8_slice(b"\xF0hello,\tworld"); + let expected = r#""\xF0hello,\tworld""#; + let output = format!("{:?}", input); + + assert_eq!(output, expected); +} |
