Skip to content

Commit 92485f8

Browse files
committed
Other clippy things and fmt
1 parent dad9fe6 commit 92485f8

File tree

9 files changed

+217
-213
lines changed

9 files changed

+217
-213
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
8888
}
8989

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

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

343346
// First try RUSTFLAGS from the environment
344347
if let Ok(a) = env::var(name) {
345-
let args = a.split(' ')
348+
let args = a
349+
.split(' ')
346350
.map(str::trim)
347351
.filter(|s| !s.is_empty())
348352
.map(str::to_string);
@@ -351,7 +355,8 @@ fn env_args(
351355

352356
let mut rustflags = Vec::new();
353357

354-
let name = name.chars()
358+
let name = name
359+
.chars()
355360
.flat_map(|c| c.to_lowercase())
356361
.collect::<String>();
357362
// Then the target.*.rustflags value...
@@ -367,13 +372,10 @@ fn env_args(
367372
// ...including target.'cfg(...)'.rustflags
368373
if let Some(target_cfg) = target_cfg {
369374
if let Some(table) = config.get_table("target")? {
370-
let cfgs = table.val.keys().filter_map(|key| {
371-
if CfgExpr::matches_key(key, target_cfg) {
372-
Some(key)
373-
} else {
374-
None
375-
}
376-
});
375+
let cfgs = table
376+
.val
377+
.keys()
378+
.filter(|key| CfgExpr::matches_key(key, target_cfg));
377379

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

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

Lines changed: 60 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
use std::cell::RefCell;
1919
use std::collections::{HashMap, HashSet};
2020

21-
use CargoResult;
21+
use super::{BuildContext, CompileMode, Kind, Unit};
2222
use core::dependency::Kind as DepKind;
23-
use core::profiles::UnitFor;
24-
use core::{Package, Target, PackageId};
2523
use core::package::Downloads;
26-
use super::{BuildContext, CompileMode, Kind, Unit};
24+
use core::profiles::UnitFor;
25+
use core::{Package, PackageId, Target};
26+
use CargoResult;
2727

2828
struct State<'a: 'tmp, 'cfg: 'a, 'tmp> {
2929
bcx: &'tmp BuildContext<'a, 'cfg>,
@@ -74,11 +74,11 @@ pub fn build_unit_dependencies<'a, 'cfg>(
7474
deps_of(unit, &mut state, unit_for)?;
7575
}
7676

77-
if state.waiting_on_download.len() > 0 {
77+
if !state.waiting_on_download.is_empty() {
7878
state.finish_some_downloads()?;
7979
state.deps.clear();
8080
} else {
81-
break
81+
break;
8282
}
8383
}
8484
trace!("ALL UNIT DEPENDENCIES {:#?}", state.deps);
@@ -128,46 +128,43 @@ fn compute_deps<'a, 'cfg, 'tmp>(
128128

129129
let bcx = state.bcx;
130130
let id = unit.pkg.package_id();
131-
let deps = bcx.resolve.deps(id)
132-
.filter(|&(_id, deps)| {
133-
assert!(!deps.is_empty());
134-
deps.iter().any(|dep| {
135-
// If this target is a build command, then we only want build
136-
// dependencies, otherwise we want everything *other than* build
137-
// dependencies.
138-
if unit.target.is_custom_build() != dep.is_build() {
139-
return false;
140-
}
131+
let deps = bcx.resolve.deps(id).filter(|&(_id, deps)| {
132+
assert!(!deps.is_empty());
133+
deps.iter().any(|dep| {
134+
// If this target is a build command, then we only want build
135+
// dependencies, otherwise we want everything *other than* build
136+
// dependencies.
137+
if unit.target.is_custom_build() != dep.is_build() {
138+
return false;
139+
}
141140

142-
// If this dependency is *not* a transitive dependency, then it
143-
// only applies to test/example targets
144-
if !dep.is_transitive() &&
145-
!unit.target.is_test() &&
146-
!unit.target.is_example() &&
147-
!unit.mode.is_any_test()
148-
{
149-
return false;
150-
}
141+
// If this dependency is *not* a transitive dependency, then it
142+
// only applies to test/example targets
143+
if !dep.is_transitive()
144+
&& !unit.target.is_test()
145+
&& !unit.target.is_example()
146+
&& !unit.mode.is_any_test()
147+
{
148+
return false;
149+
}
151150

152-
// If this dependency is only available for certain platforms,
153-
// make sure we're only enabling it for that platform.
154-
if !bcx.dep_platform_activated(dep, unit.kind) {
155-
return false;
156-
}
151+
// If this dependency is only available for certain platforms,
152+
// make sure we're only enabling it for that platform.
153+
if !bcx.dep_platform_activated(dep, unit.kind) {
154+
return false;
155+
}
157156

158-
// If the dependency is optional, then we're only activating it
159-
// if the corresponding feature was activated
160-
if dep.is_optional() &&
161-
!bcx.resolve.features(id).contains(&*dep.name_in_toml())
162-
{
163-
return false;
164-
}
157+
// If the dependency is optional, then we're only activating it
158+
// if the corresponding feature was activated
159+
if dep.is_optional() && !bcx.resolve.features(id).contains(&*dep.name_in_toml()) {
160+
return false;
161+
}
165162

166-
// If we've gotten past all that, then this dependency is
167-
// actually used!
168-
true
169-
})
170-
});
163+
// If we've gotten past all that, then this dependency is
164+
// actually used!
165+
true
166+
})
167+
});
171168

172169
let mut ret = Vec::new();
173170
for (id, _) in deps {
@@ -181,14 +178,7 @@ fn compute_deps<'a, 'cfg, 'tmp>(
181178
};
182179
let mode = check_or_build_mode(unit.mode, lib);
183180
let dep_unit_for = unit_for.with_for_host(lib.for_host());
184-
let unit = new_unit(
185-
bcx,
186-
pkg,
187-
lib,
188-
dep_unit_for,
189-
unit.kind.for_target(lib),
190-
mode,
191-
);
181+
let unit = new_unit(bcx, pkg, lib, dep_unit_for, unit.kind.for_target(lib), mode);
192182
ret.push((unit, dep_unit_for));
193183
}
194184

@@ -211,7 +201,8 @@ fn compute_deps<'a, 'cfg, 'tmp>(
211201

212202
// If any integration tests/benches are being run, make sure that
213203
// binaries are built as well.
214-
if !unit.mode.is_check() && unit.mode.is_any_test()
204+
if !unit.mode.is_check()
205+
&& unit.mode.is_any_test()
215206
&& (unit.target.is_test() || unit.target.is_bench())
216207
{
217208
ret.extend(
@@ -282,7 +273,8 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
282273
state: &mut State<'a, 'cfg, 'tmp>,
283274
) -> CargoResult<Vec<(Unit<'a>, UnitFor)>> {
284275
let bcx = state.bcx;
285-
let deps = bcx.resolve
276+
let deps = bcx
277+
.resolve
286278
.deps(unit.pkg.package_id())
287279
.filter(|&(_id, deps)| {
288280
deps.iter().any(|dep| match dep.kind() {
@@ -308,14 +300,7 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
308300
// However, for plugins/proc-macros, deps should be built like normal.
309301
let mode = check_or_build_mode(unit.mode, lib);
310302
let dep_unit_for = UnitFor::new_normal().with_for_host(lib.for_host());
311-
let lib_unit = new_unit(
312-
bcx,
313-
dep,
314-
lib,
315-
dep_unit_for,
316-
unit.kind.for_target(lib),
317-
mode,
318-
);
303+
let lib_unit = new_unit(bcx, dep, lib, dep_unit_for, unit.kind.for_target(lib), mode);
319304
ret.push((lib_unit, dep_unit_for));
320305
if let CompileMode::Doc { deps: true } = unit.mode {
321306
// Document this lib as well.
@@ -348,14 +333,7 @@ fn maybe_lib<'a>(
348333
) -> Option<(Unit<'a>, UnitFor)> {
349334
unit.pkg.targets().iter().find(|t| t.linkable()).map(|t| {
350335
let mode = check_or_build_mode(unit.mode, t);
351-
let unit = new_unit(
352-
bcx,
353-
unit.pkg,
354-
t,
355-
unit_for,
356-
unit.kind.for_target(t),
357-
mode,
358-
);
336+
let unit = new_unit(bcx, unit.pkg, t, unit_for, unit.kind.for_target(t), mode);
359337
(unit, unit_for)
360338
})
361339
}
@@ -453,7 +431,8 @@ fn connect_run_custom_build_deps(state: &mut State) {
453431
for (unit, deps) in state.deps.iter() {
454432
for dep in deps {
455433
if dep.mode == CompileMode::RunCustomBuild {
456-
reverse_deps.entry(dep)
434+
reverse_deps
435+
.entry(dep)
457436
.or_insert_with(HashSet::new)
458437
.insert(unit);
459438
}
@@ -469,7 +448,11 @@ fn connect_run_custom_build_deps(state: &mut State) {
469448
// `links`, then we depend on that package's build script! Here we use
470449
// `dep_build_script` to manufacture an appropriate build script unit to
471450
// depend on.
472-
for unit in state.deps.keys().filter(|k| k.mode == CompileMode::RunCustomBuild) {
451+
for unit in state
452+
.deps
453+
.keys()
454+
.filter(|k| k.mode == CompileMode::RunCustomBuild)
455+
{
473456
let reverse_deps = match reverse_deps.get(unit) {
474457
Some(set) => set,
475458
None => continue,
@@ -479,9 +462,9 @@ fn connect_run_custom_build_deps(state: &mut State) {
479462
.iter()
480463
.flat_map(|reverse_dep| state.deps[reverse_dep].iter())
481464
.filter(|other| {
482-
other.pkg != unit.pkg &&
483-
other.target.linkable() &&
484-
other.pkg.manifest().links().is_some()
465+
other.pkg != unit.pkg
466+
&& other.target.linkable()
467+
&& other.pkg.manifest().links().is_some()
485468
})
486469
.filter_map(|other| dep_build_script(other, state.bcx).map(|p| p.0))
487470
.collect::<HashSet<_>>();
@@ -502,15 +485,15 @@ impl<'a, 'cfg, 'tmp> State<'a, 'cfg, 'tmp> {
502485
fn get(&mut self, id: &'a PackageId) -> CargoResult<Option<&'a Package>> {
503486
let mut pkgs = self.pkgs.borrow_mut();
504487
if let Some(pkg) = pkgs.get(id) {
505-
return Ok(Some(pkg))
488+
return Ok(Some(pkg));
506489
}
507490
if !self.waiting_on_download.insert(id) {
508-
return Ok(None)
491+
return Ok(None);
509492
}
510493
if let Some(pkg) = self.downloads.start(id)? {
511494
pkgs.insert(id, pkg);
512495
self.waiting_on_download.remove(id);
513-
return Ok(Some(pkg))
496+
return Ok(Some(pkg));
514497
}
515498
Ok(None)
516499
}
@@ -535,7 +518,7 @@ impl<'a, 'cfg, 'tmp> State<'a, 'cfg, 'tmp> {
535518
// less than this let's recompute the whole unit dependency graph
536519
// again and try to find some more packages to download.
537520
if self.downloads.remaining() < 5 {
538-
break
521+
break;
539522
}
540523
}
541524
Ok(())

0 commit comments

Comments
 (0)