Skip to content

Commit

Permalink
PackageId is copy, clippy thinks we dont need &PackageId or PackageId…
Browse files Browse the repository at this point in the history
….clone()
  • Loading branch information
Eh2406 committed Nov 27, 2018
1 parent e3435d1 commit dae87a2
Show file tree
Hide file tree
Showing 55 changed files with 566 additions and 532 deletions.
10 changes: 6 additions & 4 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::Path;
use std::cell::RefCell;
use std::path::Path;

use serde::ser;

Expand Down Expand Up @@ -51,9 +51,11 @@ impl BuildConfig {
let path = Path::new(target)
.canonicalize()
.chain_err(|| format_err!("Target path {:?} is not a valid file", target))?;
Some(path.into_os_string()
.into_string()
.map_err(|_| format_err!("Target path is not valid unicode"))?)
Some(
path.into_os_string()
.into_string()
.map_err(|_| format_err!("Target path is not valid unicode"))?,
)
}
other => other.clone(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
)
}

pub fn show_warnings(&self, pkg: &PackageId) -> bool {
pub fn show_warnings(&self, pkg: PackageId) -> bool {
pkg.source_id().is_path() || self.config.extra_verbose()
}

Expand Down
21 changes: 10 additions & 11 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::path::PathBuf;
use std::str::{self, FromStr};

use super::env_args;
use util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc};
use core::TargetKind;
use super::Kind;
use core::TargetKind;
use util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc};

#[derive(Clone)]
pub struct TargetInfo {
Expand Down Expand Up @@ -173,17 +173,16 @@ impl TargetInfo {
Some((ref prefix, ref suffix)) => (prefix, suffix),
None => return Ok(None),
};
let mut ret = vec![
FileType {
suffix: suffix.clone(),
prefix: prefix.clone(),
flavor,
should_replace_hyphens: false,
},
];
let mut ret = vec![FileType {
suffix: suffix.clone(),
prefix: prefix.clone(),
flavor,
should_replace_hyphens: false,
}];

// rust-lang/cargo#4500
if target_triple.ends_with("pc-windows-msvc") && crate_type.ends_with("dylib")
if target_triple.ends_with("pc-windows-msvc")
&& crate_type.ends_with("dylib")
&& suffix == ".dll"
{
ret.push(FileType {
Expand Down
24 changes: 13 additions & 11 deletions src/cargo/core/compiler/build_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

use std::collections::BTreeMap;

use core::TargetKind;
use super::{CompileMode, Context, Kind, Unit};
use super::context::OutputFile;
use util::{internal, CargoResult, ProcessBuilder};
use std::path::PathBuf;
use serde_json;
use super::{CompileMode, Context, Kind, Unit};
use core::TargetKind;
use semver;
use serde_json;
use std::path::PathBuf;
use util::{internal, CargoResult, ProcessBuilder};

#[derive(Debug, Serialize)]
struct Invocation {
Expand Down Expand Up @@ -71,7 +71,8 @@ impl Invocation {
}

pub fn update_cmd(&mut self, cmd: &ProcessBuilder) -> CargoResult<()> {
self.program = cmd.get_program()
self.program = cmd
.get_program()
.to_str()
.ok_or_else(|| format_err!("unicode program string required"))?
.to_string();
Expand Down Expand Up @@ -111,7 +112,8 @@ impl BuildPlan {
pub fn add(&mut self, cx: &Context, unit: &Unit) -> CargoResult<()> {
let id = self.plan.invocations.len();
self.invocation_map.insert(unit.buildkey(), id);
let deps = cx.dep_targets(&unit)
let deps = cx
.dep_targets(&unit)
.iter()
.map(|dep| self.invocation_map[&dep.buildkey()])
.collect();
Expand All @@ -127,10 +129,10 @@ impl BuildPlan {
outputs: &[OutputFile],
) -> CargoResult<()> {
let id = self.invocation_map[invocation_name];
let invocation = self.plan
.invocations
.get_mut(id)
.ok_or_else(|| internal(format!("couldn't find invocation for {}", invocation_name)))?;
let invocation =
self.plan.invocations.get_mut(id).ok_or_else(|| {
internal(format!("couldn't find invocation for {}", invocation_name))
})?;

invocation.update_cmd(cmd)?;
for output in outputs.iter() {
Expand Down
10 changes: 6 additions & 4 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::path::PathBuf;

use semver::Version;

use super::BuildContext;
use core::{Edition, Package, PackageId, Target, TargetKind};
use util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder};
use super::BuildContext;

pub struct Doctest {
/// The package being doctested.
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'cfg> Compilation<'cfg> {
let search_path = join_paths(&search_path, util::dylib_path_envvar())?;

cmd.env(util::dylib_path_envvar(), &search_path);
if let Some(env) = self.extra_env.get(pkg.package_id()) {
if let Some(env) = self.extra_env.get(&pkg.package_id()) {
for &(ref k, ref v) in env {
cmd.env(k, v);
}
Expand Down Expand Up @@ -276,8 +276,10 @@ fn target_runner(bcx: &BuildContext) -> CargoResult<Option<(PathBuf, Vec<String>
if let Some(runner) = bcx.config.get_path_and_args(&key)? {
// more than one match, error out
if matching_runner.is_some() {
bail!("several matching instances of `target.'cfg(..)'.runner` \
in `.cargo/config`")
bail!(
"several matching instances of `target.'cfg(..)'.runner` \
in `.cargo/config`"
)
}

matching_runner = Some(runner.val);
Expand Down
48 changes: 26 additions & 22 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,27 +271,29 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
)?;

match file_types {
Some(types) => for file_type in types {
let path = out_dir.join(file_type.filename(&file_stem));
let hardlink = link_stem
.as_ref()
.map(|&(ref ld, ref ls)| ld.join(file_type.filename(ls)));
let export_path = if unit.target.is_custom_build() {
None
} else {
self.export_dir.as_ref().and_then(|export_dir| {
hardlink.as_ref().and_then(|hardlink| {
Some(export_dir.join(hardlink.file_name().unwrap()))
Some(types) => {
for file_type in types {
let path = out_dir.join(file_type.filename(&file_stem));
let hardlink = link_stem
.as_ref()
.map(|&(ref ld, ref ls)| ld.join(file_type.filename(ls)));
let export_path = if unit.target.is_custom_build() {
None
} else {
self.export_dir.as_ref().and_then(|export_dir| {
hardlink.as_ref().and_then(|hardlink| {
Some(export_dir.join(hardlink.file_name().unwrap()))
})
})
})
};
ret.push(OutputFile {
path,
hardlink,
export_path,
flavor: file_type.flavor,
});
},
};
ret.push(OutputFile {
path,
hardlink,
export_path,
flavor: file_type.flavor,
});
}
}
// not supported, don't worry about it
None => {
unsupported.push(crate_type.to_string());
Expand Down Expand Up @@ -392,7 +394,8 @@ fn compute_metadata<'a, 'cfg>(
let bcx = &cx.bcx;
let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA");
if !(unit.mode.is_any_test() || unit.mode.is_check())
&& (unit.target.is_dylib() || unit.target.is_cdylib()
&& (unit.target.is_dylib()
|| unit.target.is_cdylib()
|| (unit.target.is_bin() && bcx.target_triple().starts_with("wasm32-")))
&& unit.pkg.package_id().source_id().is_path()
&& __cargo_default_lib_metadata.is_err()
Expand Down Expand Up @@ -433,7 +436,8 @@ fn compute_metadata<'a, 'cfg>(

// Mix in the target-metadata of all the dependencies of this target
{
let mut deps_metadata = cx.dep_targets(unit)
let mut deps_metadata = cx
.dep_targets(unit)
.iter()
.map(|dep| metadata_of(dep, cx, metas))
.collect::<Vec<_>>();
Expand Down
Loading

0 comments on commit dae87a2

Please sign in to comment.