Skip to content

Commit 44c760d

Browse files
committed
Avoid logic duplication
As suggested by @alexcrichton, reverted back to the old way of handling both Job::new and Job::noop that avoids ugly constructs and code duplication
1 parent ec87ed4 commit 44c760d

File tree

1 file changed

+9
-6
lines changed
  • src/cargo/ops/cargo_rustc

1 file changed

+9
-6
lines changed

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
201201
// a real job. Packages which are *not* compiled still have their jobs
202202
// executed, but only if the work is fresh. This is to preserve their
203203
// artifacts if any exist.
204+
let job = if compiled {
205+
Job::new as fn(Work, Work) -> Job
206+
} else {
207+
Job::noop as fn(Work, Work) -> Job
208+
};
209+
204210
if !compiled { jobs.ignore(pkg); }
205211

206212
if targets.is_empty() {
@@ -252,8 +258,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
252258
try!(work.call(desc_tx.clone()));
253259
dirty.call(desc_tx)
254260
});
255-
dst.push((if compiled { Job::new(dirty, fresh) }
256-
else { Job::noop(dirty, fresh) }, freshness));
261+
dst.push((job(dirty, fresh), freshness));
257262
}
258263

259264
// If this is a custom build command, we need to not only build the
@@ -290,8 +295,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
290295
}
291296
let (dirty, fresh, freshness) =
292297
try!(custom_build::prepare(pkg, target, req, cx));
293-
run_custom.push((if compiled { Job::new(dirty, fresh) }
294-
else { Job::noop(dirty, fresh) }, freshness));
298+
run_custom.push((job(dirty, fresh), freshness));
295299
}
296300

297301
// If no build scripts were run, no need to compile the build script!
@@ -330,8 +334,7 @@ fn compile<'a, 'b>(targets: &[&'a Target], pkg: &'a Package,
330334
dirty.call(desc_tx)
331335
});
332336
jobs.enqueue(pkg, Stage::BuildCustomBuild, vec![]);
333-
jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(if compiled { Job::new(dirty, fresh) }
334-
else { Job::noop(dirty, fresh) }, freshness)]);
337+
jobs.enqueue(pkg, Stage::RunCustomBuild, vec![(job(dirty, fresh), freshness)]);
335338
}
336339

337340
jobs.enqueue(pkg, Stage::Libraries, libs);

0 commit comments

Comments
 (0)