Skip to content

Commit

Permalink
Auto merge of #6347 - Eh2406:dell-copy, r=alexcrichton
Browse files Browse the repository at this point in the history
remove clones made redundant by Intern SourceId

This is a follow up to #6342. I used clippy to find all the places we called `.clone()`  on a `SourceId` or where we passed `&SourceId`. This also involved fixing a large number of other things clippy was complaining about, and running `fmt` on a large number of files.
  • Loading branch information
bors committed Nov 26, 2018
2 parents 1ff5975 + 92485f8 commit de1d0de
Show file tree
Hide file tree
Showing 51 changed files with 1,091 additions and 979 deletions.
9 changes: 5 additions & 4 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"

pub fn get_version_string(is_verbose: bool) -> String {
let version = cargo::version();
let mut version_string = String::from(version.to_string());
let mut version_string = version.to_string();
version_string.push_str("\n");
if is_verbose {
version_string.push_str(&format!(
Expand Down Expand Up @@ -218,9 +218,10 @@ See 'cargo help <command>' for more information on a specific command.\n",
opt(
"verbose",
"Use verbose output (-vv very verbose/build.rs output)",
).short("v")
.multiple(true)
.global(true),
)
.short("v")
.multiple(true)
.global(true),
)
.arg(
opt("quiet", "No output printed to stdout")
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/git_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let reference = GitReference::Branch(reference.to_string());
let source_id = SourceId::for_git(&url, reference)?;

let mut source = GitSource::new(&source_id, config)?;
let mut source = GitSource::new(source_id, config)?;

source.update()?;

Expand Down
5 changes: 3 additions & 2 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {

compile_opts.build_config.release = !args.is_present("debug");

let krates = args.values_of("crate")
let krates = args
.values_of("crate")
.unwrap_or_default()
.collect::<Vec<_>>();

Expand Down Expand Up @@ -120,7 +121,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
ops::install(
root,
krates,
&source,
source,
from_cwd,
version,
&compile_opts,
Expand Down
7 changes: 4 additions & 3 deletions src/bin/cargo/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use command_prelude::*;
use std::io::{self, BufRead};

use cargo::core::{Source, SourceId};
use cargo::ops;
use cargo::sources::RegistrySource;
use cargo::util::{CargoError, CargoResultExt};
use cargo::ops;

pub fn cli() -> App {
subcommand("login")
Expand All @@ -29,11 +29,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
return Err(format_err!(
"token must be provided when \
--registry is provided."
).into());
)
.into());
}
None => {
let src = SourceId::crates_io(config)?;
let mut src = RegistrySource::remote(&src, config);
let mut src = RegistrySource::remote(src, config);
src.update()?;
let config = src.config()?.unwrap();
args.value_of("host")
Expand Down
6 changes: 3 additions & 3 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // large project
#![cfg_attr(feature = "cargo-clippy", allow(redundant_closure))] // there's a false positive
#![cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))] // large project
#![cfg_attr(feature = "cargo-clippy", allow(clippy::redundant_closure))] // there's a false positive

extern crate cargo;
extern crate clap;
Expand All @@ -13,10 +13,10 @@ extern crate serde_derive;
extern crate serde_json;
extern crate toml;

use std::collections::BTreeSet;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::collections::BTreeSet;

use cargo::core::shell::Shell;
use cargo::util::{self, command_prelude, lev_distance, CargoResult, CliResult, Config};
Expand Down
30 changes: 16 additions & 14 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
}

pub fn extern_crate_name(&self, unit: &Unit<'a>, dep: &Unit<'a>) -> CargoResult<String> {
self.resolve.extern_crate_name(unit.pkg.package_id(), dep.pkg.package_id(), dep.target)
self.resolve
.extern_crate_name(unit.pkg.package_id(), dep.pkg.package_id(), dep.target)
}

/// Whether a dependency should be compiled for the host or target platform,
Expand Down Expand Up @@ -266,10 +267,12 @@ impl TargetConfig {
let list = value.list(k)?;
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
}
"rustc-env" => for (name, val) in value.table(k)?.0 {
let val = val.string(name)?.0;
output.env.push((name.clone(), val.to_string()));
},
"rustc-env" => {
for (name, val) in value.table(k)?.0 {
let val = val.string(name)?.0;
output.env.push((name.clone(), val.to_string()));
}
}
"warning" | "rerun-if-changed" | "rerun-if-env-changed" => {
bail!("`{}` is not supported in build script overrides", k);
}
Expand Down Expand Up @@ -342,7 +345,8 @@ fn env_args(

// First try RUSTFLAGS from the environment
if let Ok(a) = env::var(name) {
let args = a.split(' ')
let args = a
.split(' ')
.map(str::trim)
.filter(|s| !s.is_empty())
.map(str::to_string);
Expand All @@ -351,7 +355,8 @@ fn env_args(

let mut rustflags = Vec::new();

let name = name.chars()
let name = name
.chars()
.flat_map(|c| c.to_lowercase())
.collect::<String>();
// Then the target.*.rustflags value...
Expand All @@ -367,13 +372,10 @@ fn env_args(
// ...including target.'cfg(...)'.rustflags
if let Some(target_cfg) = target_cfg {
if let Some(table) = config.get_table("target")? {
let cfgs = table.val.keys().filter_map(|key| {
if CfgExpr::matches_key(key, target_cfg) {
Some(key)
} else {
None
}
});
let cfgs = table
.val
.keys()
.filter(|key| CfgExpr::matches_key(key, target_cfg));

// Note that we may have multiple matching `[target]` sections and
// because we're passing flags to the compiler this can affect
Expand Down
Loading

0 comments on commit de1d0de

Please sign in to comment.