From db09895f3c123c36e05175e2c0273bf487068b37 Mon Sep 17 00:00:00 2001 From: nasa Date: Sun, 27 Jan 2019 22:39:49 +0900 Subject: [PATCH] $cargo fmt --all --- src/bin/cargo/commands/rustdoc.rs | 7 +++-- src/cargo/core/source/source_id.rs | 2 +- src/cargo/ops/cargo_new.rs | 47 ++++++++++++++--------------- src/cargo/util/errors.rs | 2 +- src/cargo/util/process_builder.rs | 2 +- src/cargo/util/toml/targets.rs | 3 +- tests/testsuite/alt_registry.rs | 14 ++++----- tests/testsuite/build.rs | 9 +++--- tests/testsuite/fix.rs | 10 ++++-- tests/testsuite/init.rs | 20 ++++++------ tests/testsuite/metadata.rs | 6 ++-- tests/testsuite/new.rs | 6 +--- tests/testsuite/package.rs | 18 +++++++---- tests/testsuite/support/publish.rs | 2 +- tests/testsuite/support/registry.rs | 1 - 15 files changed, 79 insertions(+), 70 deletions(-) diff --git a/src/bin/cargo/commands/rustdoc.rs b/src/bin/cargo/commands/rustdoc.rs index f016d2863..a46eaa5da 100644 --- a/src/bin/cargo/commands/rustdoc.rs +++ b/src/bin/cargo/commands/rustdoc.rs @@ -50,8 +50,11 @@ the `cargo help pkgid` command. pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let ws = args.workspace(config)?; - let mut compile_opts = - args.compile_options_for_single_package(config, CompileMode::Doc { deps: false }, Some(&ws))?; + let mut compile_opts = args.compile_options_for_single_package( + config, + CompileMode::Doc { deps: false }, + Some(&ws), + )?; let target_args = values(args, "args"); compile_opts.target_rustdoc_args = if target_args.is_empty() { None diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index 3fe12ebe1..72f382355 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -4,8 +4,8 @@ use std::fmt::{self, Formatter}; use std::hash::{self, Hash}; use std::path::Path; use std::ptr; -use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering::SeqCst; use std::sync::Mutex; use log::trace; diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index d16952bfa..979d14bb9 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::env; use std::fmt; use std::fs; -use std::io::{BufReader, BufRead, ErrorKind}; +use std::io::{BufRead, BufReader, ErrorKind}; use std::path::{Path, PathBuf}; use git2::Config as GitConfig; @@ -410,7 +410,6 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { Ok(()) } - /// IgnoreList struct IgnoreList { /// git like formatted entries @@ -428,7 +427,7 @@ impl IgnoreList { } } - /// add a new entry to the ignore list. Requires two arguments with the + /// add a new entry to the ignore list. Requires two arguments with the /// entry in two different formats. One for "git style" entries and one for /// "mercurial like" entries. fn push(&mut self, ignore: &str, hg_ignore: &str) { @@ -451,23 +450,23 @@ impl IgnoreList { /// file. fn format_existing(&self, existing: T, vcs: VersionControl) -> String { // TODO: is unwrap safe? - let existing_items = existing.lines().collect::, _>>().unwrap(); + let existing_items = existing.lines().collect::, _>>().unwrap(); - let ignore_items = match vcs { - VersionControl::Hg => &self.hg_ignore, - _ => &self.ignore, + let ignore_items = match vcs { + VersionControl::Hg => &self.hg_ignore, + _ => &self.ignore, }; let mut out = "\n\n#Added by cargo\n\ - #\n\ - #already existing elements are commented out\n". - to_string(); + #\n\ + #already existing elements are commented out\n" + .to_string(); for item in ignore_items { out.push('\n'); if existing_items.contains(item) { out.push('#'); - } + } out.push_str(item) } @@ -478,25 +477,25 @@ impl IgnoreList { /// write the ignore file to the given directory. If the ignore file for the /// given vcs system already exists, its content is read and duplicate ignore /// file entries are filtered out. -fn write_ignore_file(base_path: &Path, list: &IgnoreList, vcs: VersionControl) -> CargoResult{ +fn write_ignore_file( + base_path: &Path, + list: &IgnoreList, + vcs: VersionControl, +) -> CargoResult { let fp_ignore = match vcs { VersionControl::Git => base_path.join(".gitignore"), - VersionControl::Hg => base_path.join(".hgignore"), - VersionControl::Pijul => base_path.join(".ignore"), + VersionControl::Hg => base_path.join(".hgignore"), + VersionControl::Pijul => base_path.join(".ignore"), VersionControl::Fossil => return Ok("".to_string()), - VersionControl::NoVcs => return Ok("".to_string()), + VersionControl::NoVcs => return Ok("".to_string()), }; let ignore: String = match fs::File::open(&fp_ignore) { - Err(why) => { - match why.kind() { - ErrorKind::NotFound => list.format_new(vcs), - _ => return Err(failure::format_err!("{}", why)), - } - }, - Ok(file) => { - list.format_existing(BufReader::new(file), vcs) + Err(why) => match why.kind() { + ErrorKind::NotFound => list.format_new(vcs), + _ => return Err(failure::format_err!("{}", why)), }, + Ok(file) => list.format_existing(BufReader::new(file), vcs), }; paths::append(&fp_ignore, ignore.as_bytes())?; @@ -540,7 +539,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> { let name = opts.name; let cfg = global_config(config)?; - // using the push method with two arguments ensures that the entries for // both ignore and hgignore are in sync. let mut ignore = IgnoreList::new(); @@ -562,7 +560,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> { init_vcs(path, vcs, config)?; write_ignore_file(path, &ignore, vcs)?; - let (author_name, email) = discover_author()?; // Hoo boy, sure glad we've got exhaustiveness checking behind us. let author = match (cfg.name, cfg.email, author_name, email) { diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index 64eeaf20c..fb50157ff 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -337,8 +337,8 @@ pub fn process_error( #[cfg(windows)] fn status_to_string(status: ExitStatus) -> String { - use winapi::um::winnt::*; use winapi::shared::minwindef::DWORD; + use winapi::um::winnt::*; let mut base = status.to_string(); let extra = match status.code().unwrap() as DWORD { diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 2fe8cd06e..5fe2901fe 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -28,7 +28,7 @@ pub struct ProcessBuilder { /// [jobserver_docs]: https://docs.rs/jobserver/0.1.6/jobserver/ jobserver: Option, /// Whether to include environment variable in display - display_env_vars: bool + display_env_vars: bool, } impl fmt::Display for ProcessBuilder { diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index dd81b7153..88bf2d6d8 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -661,7 +661,7 @@ fn toml_targets_and_inferred( let autodiscover = match autodiscover { Some(autodiscover) => autodiscover, - None => + None => { if edition == Edition::Edition2015 { if !rem_targets.is_empty() { let mut rem_targets_str = String::new(); @@ -696,6 +696,7 @@ https://github.com/rust-lang/cargo/issues/5330", } else { true } + } }; if autodiscover { diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 28f42de6d..09098eb0b 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1118,9 +1118,7 @@ fn unknown_registry() { .file("src/main.rs", "fn main() {}") .build(); - Package::new("baz", "0.0.1") - .alternative(true) - .publish(); + Package::new("baz", "0.0.1").alternative(true).publish(); Package::new("bar", "0.0.1") .registry_dep("baz", "0.0.1") .publish(); @@ -1134,16 +1132,15 @@ fn unknown_registry() { config.insert(start + start_index, '#'); fs::write(&cfg_path, config).unwrap(); - p.cargo("build") - .masquerade_as_nightly_cargo() - .run(); + p.cargo("build").masquerade_as_nightly_cargo().run(); // Important parts: // foo -> bar registry = null // bar -> baz registry = alternate p.cargo("metadata --format-version=1") .masquerade_as_nightly_cargo() - .with_json(r#" + .with_json( + r#" { "packages": [ { @@ -1244,6 +1241,7 @@ fn unknown_registry() { "version": 1, "workspace_root": "[..]/foo" } - "#) + "#, + ) .run(); } diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 75c26d75d..bd54ab648 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1584,11 +1584,10 @@ fn vv_prints_rustc_env_vars() { r#"[RUNNING] `[..]set CARGO_PKG_AUTHORS="escape='\"@example.com"&& [..]rustc [..]`"# ) } else { - b.with_stderr_contains( - "[RUNNING] `[..]CARGO_PKG_NAME=foo [..]rustc [..]`" - ).with_stderr_contains( - r#"[RUNNING] `[..]CARGO_PKG_AUTHORS='escape='\''"@example.com' [..]rustc [..]`"# - ) + b.with_stderr_contains("[RUNNING] `[..]CARGO_PKG_NAME=foo [..]rustc [..]`") + .with_stderr_contains( + r#"[RUNNING] `[..]CARGO_PKG_AUTHORS='escape='\''"@example.com' [..]rustc [..]`"#, + ) }; b.run(); diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index 89c81fd42..0bdcf221d 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -1263,8 +1263,14 @@ fn fix_to_broken_code() { fn fix_with_common() { let p = project() .file("src/lib.rs", "") - .file("tests/t1.rs", "mod common; #[test] fn t1() { common::try(); }") - .file("tests/t2.rs", "mod common; #[test] fn t2() { common::try(); }") + .file( + "tests/t1.rs", + "mod common; #[test] fn t1() { common::try(); }", + ) + .file( + "tests/t2.rs", + "mod common; #[test] fn t2() { common::try(); }", + ) .file("tests/common/mod.rs", "pub fn try() {}") .build(); diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index 4218765a4..102dfb06a 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -49,7 +49,9 @@ fn simple_git_ignore_exists() { // write a .gitignore file with one entry fs::create_dir_all(paths::root().join("foo")).unwrap(); let mut ignore_file = File::create(paths::root().join("foo/.gitignore")).unwrap(); - ignore_file.write("/target\n**/some.file".as_bytes()).unwrap(); + ignore_file + .write("/target\n**/some.file".as_bytes()) + .unwrap(); cargo_process("init --lib foo --edition 2015") .env("USER", "foo") @@ -70,14 +72,14 @@ fn simple_git_ignore_exists() { assert_eq!( contents, "/target\n\ - **/some.file\n\n\ - #Added by cargo\n\ - #\n\ - #already existing elements are commented out\n\ - \n\ - #/target\n\ - **/*.rs.bk\n\ - Cargo.lock", + **/some.file\n\n\ + #Added by cargo\n\ + #\n\ + #already existing elements are commented out\n\ + \n\ + #/target\n\ + **/*.rs.bk\n\ + Cargo.lock", ); cargo_process("build").cwd(&paths::root().join("foo")).run(); diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index aeaad126f..7c5a2bf4e 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1598,7 +1598,8 @@ fn metadata_links() { .build(); p.cargo("metadata") - .with_json(r#" + .with_json( + r#" { "packages": [ { @@ -1664,6 +1665,7 @@ fn metadata_links() { ], "workspace_root": "[..]/foo" } -"#) +"#, + ) .run() } diff --git a/tests/testsuite/new.rs b/tests/testsuite/new.rs index 7b3a814b5..8c60fb26a 100644 --- a/tests/testsuite/new.rs +++ b/tests/testsuite/new.rs @@ -89,15 +89,11 @@ fn simple_git() { .unwrap() .read_to_string(&mut contents) .unwrap(); - assert_eq!( - contents, - "/target\n**/*.rs.bk\nCargo.lock", - ); + assert_eq!(contents, "/target\n**/*.rs.bk\nCargo.lock",); cargo_process("build").cwd(&paths::root().join("foo")).run(); } - #[test] fn no_argument() { cargo_process("new") diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 2485c1439..fe2e392e9 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1254,12 +1254,14 @@ fn package_with_select_features() { required = [] optional = [] "#, - ).file( + ) + .file( "src/main.rs", "#[cfg(not(feature = \"required\"))] compile_error!(\"This crate requires `required` feature!\"); fn main() {}", - ).build(); + ) + .build(); p.cargo("package --features required") .masquerade_as_nightly_cargo() @@ -1284,12 +1286,14 @@ fn package_with_all_features() { required = [] optional = [] "#, - ).file( + ) + .file( "src/main.rs", "#[cfg(not(feature = \"required\"))] compile_error!(\"This crate requires `required` feature!\"); fn main() {}", - ).build(); + ) + .build(); p.cargo("package --all-features") .masquerade_as_nightly_cargo() @@ -1314,12 +1318,14 @@ fn package_no_default_features() { default = ["required"] required = [] "#, - ).file( + ) + .file( "src/main.rs", "#[cfg(not(feature = \"required\"))] compile_error!(\"This crate requires `required` feature!\"); fn main() {}", - ).build(); + ) + .build(); p.cargo("package --no-default-features") .masquerade_as_nightly_cargo() diff --git a/tests/testsuite/support/publish.rs b/tests/testsuite/support/publish.rs index e536a1bf4..1c8b0054d 100644 --- a/tests/testsuite/support/publish.rs +++ b/tests/testsuite/support/publish.rs @@ -3,8 +3,8 @@ use std::fs::File; use std::io::{prelude::*, SeekFrom}; use std::path::{Path, PathBuf}; -use crate::support::registry::{self, alt_api_path}; use crate::support::find_json_mismatch; +use crate::support::registry::{self, alt_api_path}; use byteorder::{LittleEndian, ReadBytesExt}; use flate2::read::GzDecoder; diff --git a/tests/testsuite/support/registry.rs b/tests/testsuite/support/registry.rs index 721f743b8..eaf944d27 100644 --- a/tests/testsuite/support/registry.rs +++ b/tests/testsuite/support/registry.rs @@ -186,7 +186,6 @@ pub fn init() { "# )); - // Init a new registry let _ = repo(®istry_path()) .file(