diff options
| author | David Tolnay <dtolnay@gmail.com> | 2019-11-27 10:28:39 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2019-11-29 18:37:58 -0800 |
| commit | c34fbfaad38cf5829ef5cfe780dc9d58480adeaa (patch) | |
| tree | e57b66ed06aec18dc13ff7f14a243ca3dc3c27d1 /src/libstd/sys/windows/args.rs | |
| parent | 9081929d45f12d3f56d43b1d6db7519981580fc9 (diff) | |
| download | rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.tar.gz rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.zip | |
Format libstd/sys with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd/sys *that are not involved in any currently open PR*
to minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8
With the list of files from the script in outstanding_files, the
relevant commands were:
$ find src/libstd/sys -name '*.rs' \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg libstd/sys outstanding_files | xargs git checkout --
Repeating this process several months apart should get us coverage of
most of the rest of the files.
To confirm no funny business:
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT # there should be no difference
Diffstat (limited to 'src/libstd/sys/windows/args.rs')
| -rw-r--r-- | src/libstd/sys/windows/args.rs | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/src/libstd/sys/windows/args.rs b/src/libstd/sys/windows/args.rs index b04bb484eed..5fbea2a2910 100644 --- a/src/libstd/sys/windows/args.rs +++ b/src/libstd/sys/windows/args.rs @@ -1,26 +1,26 @@ #![allow(dead_code)] // runtime init functions not used during testing -use crate::os::windows::prelude::*; -use crate::sys::windows::os::current_exe; -use crate::sys::c; use crate::ffi::OsString; use crate::fmt; -use crate::vec; -use crate::slice; +use crate::os::windows::prelude::*; use crate::path::PathBuf; +use crate::slice; +use crate::sys::c; +use crate::sys::windows::os::current_exe; +use crate::vec; use core::iter; -pub unsafe fn init(_argc: isize, _argv: *const *const u8) { } +pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} -pub unsafe fn cleanup() { } +pub unsafe fn cleanup() {} pub fn args() -> Args { unsafe { let lp_cmd_line = c::GetCommandLineW(); - let parsed_args_list = parse_lp_cmd_line( - lp_cmd_line as *const u16, - || current_exe().map(PathBuf::into_os_string).unwrap_or_else(|_| OsString::new())); + let parsed_args_list = parse_lp_cmd_line(lp_cmd_line as *const u16, || { + current_exe().map(PathBuf::into_os_string).unwrap_or_else(|_| OsString::new()) + }); Args { parsed_args_list: parsed_args_list.into_iter() } } @@ -40,8 +40,10 @@ pub fn args() -> Args { /// Windows 10 Pro v1803, using an exhaustive test suite available at /// <https://gist.github.com/notriddle/dde431930c392e428055b2dc22e638f5> or /// <https://paste.gg/p/anonymous/47d6ed5f5bd549168b1c69c799825223>. -unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_name: F) - -> Vec<OsString> { +unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>( + lp_cmd_line: *const u16, + exe_name: F, +) -> Vec<OsString> { const BACKSLASH: u16 = '\\' as u16; const QUOTE: u16 = '"' as u16; const TAB: u16 = '\t' as u16; @@ -84,7 +86,7 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na 0..=SPACE => { ret_val.push(OsString::new()); &cmd_line[1..] - }, + } // The executable name ends at the next whitespace, // no matter what. _ => { @@ -112,7 +114,7 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na BACKSLASH => { backslash_count += 1; was_in_quotes = false; - }, + } QUOTE if backslash_count % 2 == 0 => { cur.extend(iter::repeat(b'\\' as u16).take(backslash_count / 2)); backslash_count = 0; @@ -171,30 +173,36 @@ impl<'a> fmt::Debug for ArgsInnerDebug<'a> { impl Args { pub fn inner_debug(&self) -> ArgsInnerDebug<'_> { - ArgsInnerDebug { - args: self - } + ArgsInnerDebug { args: self } } } impl Iterator for Args { type Item = OsString; - fn next(&mut self) -> Option<OsString> { self.parsed_args_list.next() } - fn size_hint(&self) -> (usize, Option<usize>) { self.parsed_args_list.size_hint() } + fn next(&mut self) -> Option<OsString> { + self.parsed_args_list.next() + } + fn size_hint(&self) -> (usize, Option<usize>) { + self.parsed_args_list.size_hint() + } } impl DoubleEndedIterator for Args { - fn next_back(&mut self) -> Option<OsString> { self.parsed_args_list.next_back() } + fn next_back(&mut self) -> Option<OsString> { + self.parsed_args_list.next_back() + } } impl ExactSizeIterator for Args { - fn len(&self) -> usize { self.parsed_args_list.len() } + fn len(&self) -> usize { + self.parsed_args_list.len() + } } #[cfg(test)] mod tests { - use crate::sys::windows::args::*; use crate::ffi::OsString; + use crate::sys::windows::args::*; fn chk(string: &str, parts: &[&str]) { let mut wide: Vec<u16> = OsString::from(string).encode_wide().collect(); @@ -245,7 +253,7 @@ mod tests { chk(r#"EXE "" """"#, &["EXE", "", "\""]); chk( r#"EXE "this is """all""" in the same argument""#, - &["EXE", "this is \"all\" in the same argument"] + &["EXE", "this is \"all\" in the same argument"], ); chk(r#"EXE "a"""#, &["EXE", "a\""]); chk(r#"EXE "a"" a"#, &["EXE", "a\"", "a"]); @@ -253,6 +261,6 @@ mod tests { chk(r#""EXE" check"#, &["EXE", "check"]); chk(r#""EXE check""#, &["EXE check"]); chk(r#""EXE """for""" check"#, &["EXE ", r#"for""#, "check"]); - chk(r#""EXE \"for\" check"#, &[r#"EXE \"#, r#"for""#, "check"]); + chk(r#""EXE \"for\" check"#, &[r#"EXE \"#, r#"for""#, "check"]); } } |
