From 3aa99422ca7808f1bc5621fda3a8f32f27273d9b Mon Sep 17 00:00:00 2001 From: Martin Donlon Date: Mon, 15 Feb 2021 15:29:08 -0800 Subject: [PATCH] Run `cargo fmt --all` Fix formatting errors --- src/cargo/core/compiler/compilation.rs | 1 - src/cargo/util/config/mod.rs | 10 +++--- tests/testsuite/cargo_env_config.rs | 47 ++++++++++++++++---------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 8e0483907..50f5945a8 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -339,7 +339,6 @@ impl<'cfg> Compilation<'cfg> { ) .env("CARGO_PKG_AUTHORS", &pkg.authors().join(":")) .cwd(pkg.root()); - // Apply any environment variables from the config for (key, value) in self.config.env_config()?.iter() { diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index 1ee30aa65..c5d658eda 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -49,10 +49,12 @@ //! translate from `ConfigValue` and environment variables to the caller's //! desired type. +use std::borrow::Cow; use std::cell::{RefCell, RefMut}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::{HashMap, HashSet}; use std::env; +use std::ffi::OsStr; use std::fmt; use std::fs::{self, File}; use std::io::prelude::*; @@ -62,8 +64,6 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::Once; use std::time::Instant; -use std::borrow::Cow; -use std::ffi::OsStr; use anyhow::{anyhow, bail, format_err}; use curl::easy::Easy; @@ -1278,9 +1278,7 @@ impl Config { } pub fn env_config(&self) -> CargoResult<&EnvConfig> { - self.env_config.try_borrow_with(|| { - self.get_env_config() - }) + self.env_config.try_borrow_with(|| self.get_env_config()) } /// This is used to validate the `term` table has valid syntax. @@ -2006,7 +2004,7 @@ impl EnvConfigValue { EnvConfigValue { value, force: false, - relative: false + relative: false, } } diff --git a/tests/testsuite/cargo_env_config.rs b/tests/testsuite/cargo_env_config.rs index 742f66895..874976b38 100644 --- a/tests/testsuite/cargo_env_config.rs +++ b/tests/testsuite/cargo_env_config.rs @@ -6,16 +6,19 @@ use cargo_test_support::{basic_bin_manifest, project}; fn env_basic() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/main.rs", r#" + .file( + "src/main.rs", + r#" use std::env; fn main() { println!( "compile-time:{}", env!("ENV_TEST_1233") ); println!( "run-time:{}", env::var("ENV_TEST_1233").unwrap()); } - "#) + "#, + ) .file( - ".cargo/config", - r#" + ".cargo/config", + r#" [env] ENV_TEST_1233 = "Hello" "#, @@ -32,13 +35,16 @@ fn env_basic() { fn env_invalid() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/main.rs", r#" + .file( + "src/main.rs", + r#" fn main() { } - "#) + "#, + ) .file( - ".cargo/config", - r#" + ".cargo/config", + r#" [env] ENV_TEST_BOOL = false "#, @@ -55,16 +61,19 @@ fn env_invalid() { fn env_force() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo")) - .file("src/main.rs", r#" + .file( + "src/main.rs", + r#" use std::env; fn main() { println!( "ENV_TEST_FORCED:{}", env!("ENV_TEST_FORCED") ); println!( "ENV_TEST_UNFORCED:{}", env!("ENV_TEST_UNFORCED") ); } - "#) + "#, + ) .file( - ".cargo/config", - r#" + ".cargo/config", + r#" [env] ENV_TEST_UNFORCED = "from-config" ENV_TEST_FORCED = { value = "from-config", force = true } @@ -84,7 +93,9 @@ fn env_force() { fn env_relative() { let p = project() .file("Cargo.toml", &basic_bin_manifest("foo2")) - .file("src/main.rs", r#" + .file( + "src/main.rs", + r#" use std::env; use std::path::Path; fn main() { @@ -94,10 +105,11 @@ fn env_relative() { assert!( Path::new(env!("ENV_TEST_ABSOLUTE")).is_absolute() ); assert!( !Path::new(env!("ENV_TEST_RELATIVE")).is_absolute() ); } - "#) + "#, + ) .file( - ".cargo/config", - r#" + ".cargo/config", + r#" [env] ENV_TEST_RELATIVE = "Cargo.toml" ENV_TEST_ABSOLUTE = { value = "Cargo.toml", relative = true } @@ -105,6 +117,5 @@ fn env_relative() { ) .build(); - p.cargo("run") - .run(); + p.cargo("run").run(); }