Skip to content

Commit d8f066e

Browse files
committed
Auto merge of #6352 - Eh2406:dell-copy, r=alexcrichton
remove clones made redundant by Intern PackageId This is a follow up to #6332. I used clippy to find all the places we called `.clone()` on a `PackageId` or where we passed `&PackageId`. Yes that touches 44 files and 400+ lines, that is way we wanted `PackageId` to be `copy`.
2 parents e3435d1 + dae87a2 commit d8f066e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+566
-532
lines changed

src/cargo/core/compiler/build_config.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::path::Path;
21
use std::cell::RefCell;
2+
use std::path::Path;
33

44
use serde::ser;
55

@@ -51,9 +51,11 @@ impl BuildConfig {
5151
let path = Path::new(target)
5252
.canonicalize()
5353
.chain_err(|| format_err!("Target path {:?} is not a valid file", target))?;
54-
Some(path.into_os_string()
55-
.into_string()
56-
.map_err(|_| format_err!("Target path is not valid unicode"))?)
54+
Some(
55+
path.into_os_string()
56+
.into_string()
57+
.map_err(|_| format_err!("Target path is not valid unicode"))?,
58+
)
5759
}
5860
other => other.clone(),
5961
};

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
180180
)
181181
}
182182

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

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::path::PathBuf;
44
use std::str::{self, FromStr};
55

66
use super::env_args;
7-
use util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc};
8-
use core::TargetKind;
97
use super::Kind;
8+
use core::TargetKind;
9+
use util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder, Rustc};
1010

1111
#[derive(Clone)]
1212
pub struct TargetInfo {
@@ -173,17 +173,16 @@ impl TargetInfo {
173173
Some((ref prefix, ref suffix)) => (prefix, suffix),
174174
None => return Ok(None),
175175
};
176-
let mut ret = vec![
177-
FileType {
178-
suffix: suffix.clone(),
179-
prefix: prefix.clone(),
180-
flavor,
181-
should_replace_hyphens: false,
182-
},
183-
];
176+
let mut ret = vec![FileType {
177+
suffix: suffix.clone(),
178+
prefix: prefix.clone(),
179+
flavor,
180+
should_replace_hyphens: false,
181+
}];
184182

185183
// rust-lang/cargo#4500
186-
if target_triple.ends_with("pc-windows-msvc") && crate_type.ends_with("dylib")
184+
if target_triple.ends_with("pc-windows-msvc")
185+
&& crate_type.ends_with("dylib")
187186
&& suffix == ".dll"
188187
{
189188
ret.push(FileType {

src/cargo/core/compiler/build_plan.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
99
use std::collections::BTreeMap;
1010

11-
use core::TargetKind;
12-
use super::{CompileMode, Context, Kind, Unit};
1311
use super::context::OutputFile;
14-
use util::{internal, CargoResult, ProcessBuilder};
15-
use std::path::PathBuf;
16-
use serde_json;
12+
use super::{CompileMode, Context, Kind, Unit};
13+
use core::TargetKind;
1714
use semver;
15+
use serde_json;
16+
use std::path::PathBuf;
17+
use util::{internal, CargoResult, ProcessBuilder};
1818

1919
#[derive(Debug, Serialize)]
2020
struct Invocation {
@@ -71,7 +71,8 @@ impl Invocation {
7171
}
7272

7373
pub fn update_cmd(&mut self, cmd: &ProcessBuilder) -> CargoResult<()> {
74-
self.program = cmd.get_program()
74+
self.program = cmd
75+
.get_program()
7576
.to_str()
7677
.ok_or_else(|| format_err!("unicode program string required"))?
7778
.to_string();
@@ -111,7 +112,8 @@ impl BuildPlan {
111112
pub fn add(&mut self, cx: &Context, unit: &Unit) -> CargoResult<()> {
112113
let id = self.plan.invocations.len();
113114
self.invocation_map.insert(unit.buildkey(), id);
114-
let deps = cx.dep_targets(&unit)
115+
let deps = cx
116+
.dep_targets(&unit)
115117
.iter()
116118
.map(|dep| self.invocation_map[&dep.buildkey()])
117119
.collect();
@@ -127,10 +129,10 @@ impl BuildPlan {
127129
outputs: &[OutputFile],
128130
) -> CargoResult<()> {
129131
let id = self.invocation_map[invocation_name];
130-
let invocation = self.plan
131-
.invocations
132-
.get_mut(id)
133-
.ok_or_else(|| internal(format!("couldn't find invocation for {}", invocation_name)))?;
132+
let invocation =
133+
self.plan.invocations.get_mut(id).ok_or_else(|| {
134+
internal(format!("couldn't find invocation for {}", invocation_name))
135+
})?;
134136

135137
invocation.update_cmd(cmd)?;
136138
for output in outputs.iter() {

src/cargo/core/compiler/compilation.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::path::PathBuf;
55

66
use semver::Version;
77

8+
use super::BuildContext;
89
use core::{Edition, Package, PackageId, Target, TargetKind};
910
use util::{self, join_paths, process, CargoResult, CfgExpr, Config, ProcessBuilder};
10-
use super::BuildContext;
1111

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

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

283285
matching_runner = Some(runner.val);

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,27 +271,29 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
271271
)?;
272272

273273
match file_types {
274-
Some(types) => for file_type in types {
275-
let path = out_dir.join(file_type.filename(&file_stem));
276-
let hardlink = link_stem
277-
.as_ref()
278-
.map(|&(ref ld, ref ls)| ld.join(file_type.filename(ls)));
279-
let export_path = if unit.target.is_custom_build() {
280-
None
281-
} else {
282-
self.export_dir.as_ref().and_then(|export_dir| {
283-
hardlink.as_ref().and_then(|hardlink| {
284-
Some(export_dir.join(hardlink.file_name().unwrap()))
274+
Some(types) => {
275+
for file_type in types {
276+
let path = out_dir.join(file_type.filename(&file_stem));
277+
let hardlink = link_stem
278+
.as_ref()
279+
.map(|&(ref ld, ref ls)| ld.join(file_type.filename(ls)));
280+
let export_path = if unit.target.is_custom_build() {
281+
None
282+
} else {
283+
self.export_dir.as_ref().and_then(|export_dir| {
284+
hardlink.as_ref().and_then(|hardlink| {
285+
Some(export_dir.join(hardlink.file_name().unwrap()))
286+
})
285287
})
286-
})
287-
};
288-
ret.push(OutputFile {
289-
path,
290-
hardlink,
291-
export_path,
292-
flavor: file_type.flavor,
293-
});
294-
},
288+
};
289+
ret.push(OutputFile {
290+
path,
291+
hardlink,
292+
export_path,
293+
flavor: file_type.flavor,
294+
});
295+
}
296+
}
295297
// not supported, don't worry about it
296298
None => {
297299
unsupported.push(crate_type.to_string());
@@ -392,7 +394,8 @@ fn compute_metadata<'a, 'cfg>(
392394
let bcx = &cx.bcx;
393395
let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA");
394396
if !(unit.mode.is_any_test() || unit.mode.is_check())
395-
&& (unit.target.is_dylib() || unit.target.is_cdylib()
397+
&& (unit.target.is_dylib()
398+
|| unit.target.is_cdylib()
396399
|| (unit.target.is_bin() && bcx.target_triple().starts_with("wasm32-")))
397400
&& unit.pkg.package_id().source_id().is_path()
398401
&& __cargo_default_lib_metadata.is_err()
@@ -433,7 +436,8 @@ fn compute_metadata<'a, 'cfg>(
433436

434437
// Mix in the target-metadata of all the dependencies of this target
435438
{
436-
let mut deps_metadata = cx.dep_targets(unit)
439+
let mut deps_metadata = cx
440+
.dep_targets(unit)
437441
.iter()
438442
.map(|dep| metadata_of(dep, cx, metas))
439443
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)