Skip to content

Commit 21f4de7

Browse files
committed
refactor: remove unnecessary Option in Freshness::Dirty
1 parent 9530355 commit 21f4de7

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use super::{fingerprint, Context, Job, Unit, Work};
3535
use crate::core::compiler::artifact;
3636
use crate::core::compiler::context::Metadata;
37+
use crate::core::compiler::fingerprint::DirtyReason;
3738
use crate::core::compiler::job_queue::JobState;
3839
use crate::core::{profiles::ProfileRoot, PackageId, Target};
3940
use crate::util::errors::CargoResult;
@@ -608,7 +609,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
608609
});
609610

610611
let mut job = if cx.bcx.build_config.build_plan {
611-
Job::new_dirty(Work::noop(), None)
612+
Job::new_dirty(Work::noop(), DirtyReason::FreshBuild)
612613
} else {
613614
fingerprint::prepare_target(cx, unit, false)?
614615
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
506506
Work::new(move |_| write_fingerprint(&loc, &fingerprint))
507507
};
508508

509-
Ok(Job::new_dirty(write_fingerprint, Some(dirty_reason)))
509+
Ok(Job::new_dirty(write_fingerprint, dirty_reason))
510510
}
511511

512512
/// Dependency edge information for fingerprints. This is generated for each

src/cargo/core/compiler/job_queue/job.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Job {
6060
}
6161

6262
/// Creates a new job representing a unit of work.
63-
pub fn new_dirty(work: Work, dirty_reason: Option<DirtyReason>) -> Job {
63+
pub fn new_dirty(work: Work, dirty_reason: DirtyReason) -> Job {
6464
Job {
6565
work,
6666
fresh: Freshness::Dirty(dirty_reason),
@@ -100,7 +100,7 @@ impl fmt::Debug for Job {
100100
#[derive(Debug, Clone)]
101101
pub enum Freshness {
102102
Fresh,
103-
Dirty(Option<DirtyReason>),
103+
Dirty(DirtyReason),
104104
}
105105

106106
impl Freshness {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,10 @@ impl<'cfg> DrainState<'cfg> {
11101110
// Any dirty stage which runs at least one command gets printed as
11111111
// being a compiled package.
11121112
Dirty(dirty_reason) => {
1113-
if let Some(reason) = dirty_reason {
1114-
if !reason.is_fresh_build() {
1115-
config
1116-
.shell()
1117-
.verbose(|shell| reason.present_to(shell, unit, ws_root))?;
1118-
}
1113+
if !dirty_reason.is_fresh_build() {
1114+
config
1115+
.shell()
1116+
.verbose(|shell| dirty_reason.present_to(shell, unit, ws_root))?;
11191117
}
11201118

11211119
if unit.mode.is_doc() {

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn compile<'cfg>(
183183
// We run these targets later, so this is just a no-op for now.
184184
Job::new_fresh()
185185
} else if build_plan {
186-
Job::new_dirty(rustc(cx, unit, &exec.clone())?, None)
186+
Job::new_dirty(rustc(cx, unit, &exec.clone())?, DirtyReason::FreshBuild)
187187
} else {
188188
let force = exec.force_rebuild(unit) || force_rebuild;
189189
let mut job = fingerprint::prepare_target(cx, unit, force)?;

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl InstallTracker {
175175
// Check if any tracked exe's are already installed.
176176
let duplicates = self.find_duplicates(dst, &exes);
177177
if force || duplicates.is_empty() {
178-
return Ok((Freshness::Dirty(Some(DirtyReason::Forced)), duplicates));
178+
return Ok((Freshness::Dirty(DirtyReason::Forced), duplicates));
179179
}
180180
// Check if all duplicates come from packages of the same name. If
181181
// there are duplicates from other packages, then --force will be
@@ -205,7 +205,7 @@ impl InstallTracker {
205205
let source_id = pkg.package_id().source_id();
206206
if source_id.is_path() {
207207
// `cargo install --path ...` is always rebuilt.
208-
return Ok((Freshness::Dirty(Some(DirtyReason::Forced)), duplicates));
208+
return Ok((Freshness::Dirty(DirtyReason::Forced), duplicates));
209209
}
210210
let is_up_to_date = |dupe_pkg_id| {
211211
let info = self
@@ -229,7 +229,7 @@ impl InstallTracker {
229229
if matching_duplicates.iter().all(is_up_to_date) {
230230
Ok((Freshness::Fresh, duplicates))
231231
} else {
232-
Ok((Freshness::Dirty(Some(DirtyReason::Forced)), duplicates))
232+
Ok((Freshness::Dirty(DirtyReason::Forced), duplicates))
233233
}
234234
} else {
235235
// Format the error message.

0 commit comments

Comments
 (0)