Skip to content

Commit ef0951e

Browse files
dnblnweihanglo
andcommitted
Apply patch
Co-authored-by: Weihang Lo <me@weihanglo.tw>
1 parent 2071acd commit ef0951e

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed

src/cargo/core/compiler/fingerprint.rs

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,15 @@ pub fn prepare_target(cx: &mut Context<'_, '_>, unit: &Unit, force: bool) -> Car
399399
}
400400

401401
let dirty_reason = match compare {
402-
Ok(_) => {
402+
Ok(None) => {
403403
if force {
404404
Some(DirtyReason::Forced)
405405
} else {
406406
return Ok(Job::new_fresh());
407407
}
408408
}
409-
Err(e) => e.downcast::<DirtyReason>().ok(),
409+
Ok(reason) => reason,
410+
Err(_) => None,
410411
};
411412

412413
// Clear out the old fingerprint file if it exists. This protects when
@@ -853,64 +854,64 @@ impl Fingerprint {
853854
/// The purpose of this is exclusively to produce a diagnostic message
854855
/// indicating why we're recompiling something. This function always returns
855856
/// an error, it will never return success.
856-
fn compare(&self, old: &Fingerprint) -> Result<(), DirtyReason> {
857+
fn compare(&self, old: &Fingerprint) -> DirtyReason {
857858
if self.rustc != old.rustc {
858-
Err(DirtyReason::RustcChanged)?
859+
return DirtyReason::RustcChanged
859860
}
860861
if self.features != old.features {
861-
Err(DirtyReason::FeaturesChanged {
862+
return DirtyReason::FeaturesChanged {
862863
old: old.features.clone(),
863864
new: self.features.clone(),
864-
})?
865+
}
865866
}
866867
if self.target != old.target {
867-
Err(DirtyReason::TargetConfigurationChanged)?
868+
return DirtyReason::TargetConfigurationChanged;
868869
}
869870
if self.path != old.path {
870-
Err(DirtyReason::PathToSourceChanged)?
871+
return DirtyReason::PathToSourceChanged;
871872
}
872873
if self.profile != old.profile {
873-
Err(DirtyReason::ProfileConfigurationChanged)?
874+
return DirtyReason::ProfileConfigurationChanged;
874875
}
875876
if self.rustflags != old.rustflags {
876-
Err(DirtyReason::RustflagsChanged {
877+
return DirtyReason::RustflagsChanged {
877878
old: old.rustflags.clone(),
878879
new: self.rustflags.clone(),
879-
})?
880+
};
880881
}
881882
if self.metadata != old.metadata {
882-
Err(DirtyReason::MetadataChanged)?
883+
return DirtyReason::MetadataChanged;
883884
}
884885
if self.config != old.config {
885-
Err(DirtyReason::ConfigSettingsChanged)?
886+
return DirtyReason::ConfigSettingsChanged;
886887
}
887888
if self.compile_kind != old.compile_kind {
888-
Err(DirtyReason::CompileKindChanged)?
889+
return DirtyReason::CompileKindChanged;
889890
}
890891
let my_local = self.local.lock().unwrap();
891892
let old_local = old.local.lock().unwrap();
892893
if my_local.len() != old_local.len() {
893-
Err(DirtyReason::LocalLengthsChanged)?
894+
return DirtyReason::LocalLengthsChanged;
894895
}
895896
for (new, old) in my_local.iter().zip(old_local.iter()) {
896897
match (new, old) {
897898
(LocalFingerprint::Precalculated(a), LocalFingerprint::Precalculated(b)) => {
898899
if a != b {
899-
Err(DirtyReason::PrecalculatedComponentsChanged {
900+
return DirtyReason::PrecalculatedComponentsChanged {
900901
old: b.to_string(),
901902
new: a.to_string(),
902-
})?
903+
};
903904
}
904905
}
905906
(
906907
LocalFingerprint::CheckDepInfo { dep_info: adep },
907908
LocalFingerprint::CheckDepInfo { dep_info: bdep },
908909
) => {
909910
if adep != bdep {
910-
Err(DirtyReason::DepInfoOutputChanged {
911+
return DirtyReason::DepInfoOutputChanged {
911912
old: bdep.clone(),
912913
new: adep.clone(),
913-
})?
914+
};
914915
}
915916
}
916917
(
@@ -924,16 +925,16 @@ impl Fingerprint {
924925
},
925926
) => {
926927
if aout != bout {
927-
Err(DirtyReason::RerunIfChangedOutputFileChanged {
928+
return DirtyReason::RerunIfChangedOutputFileChanged {
928929
old: bout.clone(),
929930
new: aout.clone(),
930-
})?
931+
};
931932
}
932933
if apaths != bpaths {
933-
Err(DirtyReason::RerunIfChangedOutputPathsChanged {
934+
return DirtyReason::RerunIfChangedOutputPathsChanged {
934935
old: bpaths.clone(),
935936
new: apaths.clone(),
936-
})?
937+
};
937938
}
938939
}
939940
(
@@ -947,59 +948,59 @@ impl Fingerprint {
947948
},
948949
) => {
949950
if *akey != *bkey {
950-
Err(DirtyReason::EnvVarsChanged {
951+
return DirtyReason::EnvVarsChanged {
951952
old: bkey.clone(),
952953
new: akey.clone(),
953-
})?
954+
};
954955
}
955956
if *avalue != *bvalue {
956-
Err(DirtyReason::EnvVarChanged {
957+
return DirtyReason::EnvVarChanged {
957958
name: akey.clone(),
958959
old_value: bvalue.clone(),
959960
new_value: avalue.clone(),
960-
})?
961+
};
961962
}
962963
}
963-
(a, b) => Err(DirtyReason::LocalFingerprintTypeChanged {
964+
(a, b) => return DirtyReason::LocalFingerprintTypeChanged {
964965
old: b.kind(),
965966
new: a.kind(),
966-
})?,
967+
},
967968
}
968969
}
969970

970971
if self.deps.len() != old.deps.len() {
971-
Err(DirtyReason::NumberOfDependenciesChanged {
972+
return DirtyReason::NumberOfDependenciesChanged {
972973
old: old.deps.len(),
973974
new: self.deps.len(),
974-
})?
975+
};
975976
}
976977
for (a, b) in self.deps.iter().zip(old.deps.iter()) {
977978
if a.name != b.name {
978-
Err(DirtyReason::UnitDependencyNameChanged {
979+
return DirtyReason::UnitDependencyNameChanged {
979980
old: b.name.clone(),
980981
new: a.name.clone(),
981-
})?
982+
};
982983
}
983984

984985
if a.fingerprint.hash_u64() != b.fingerprint.hash_u64() {
985-
Err(DirtyReason::UnitDependencyInfoChanged {
986+
return DirtyReason::UnitDependencyInfoChanged {
986987
new_name: a.name.clone(),
987988
new_fingerprint: a.fingerprint.hash_u64(),
988989
old_name: b.name.clone(),
989990
old_fingerprint: b.fingerprint.hash_u64(),
990-
})?
991+
};
991992
}
992993
}
993994

994995
if !self.fs_status.up_to_date() {
995-
Err(DirtyReason::FsStatusOutdated(self.fs_status.clone()))?
996+
return DirtyReason::FsStatusOutdated(self.fs_status.clone());
996997
}
997998

998999
// This typically means some filesystem modifications happened or
9991000
// something transitive was odd. In general we should strive to provide
10001001
// a better error message than this, so if you see this message a lot it
10011002
// likely means this method needs to be updated!
1002-
Err(DirtyReason::NothingObvious)
1003+
DirtyReason::NothingObvious
10031004
}
10041005

10051006
/// Dynamically inspect the local filesystem to update the `fs_status` field
@@ -1667,7 +1668,7 @@ fn compare_old_fingerprint(
16671668
loc: &Path,
16681669
new_fingerprint: &Fingerprint,
16691670
mtime_on_use: bool,
1670-
) -> CargoResult<()> {
1671+
) -> CargoResult<Option<DirtyReason>> {
16711672
let old_fingerprint_short = paths::read(loc)?;
16721673

16731674
if mtime_on_use {
@@ -1680,7 +1681,7 @@ fn compare_old_fingerprint(
16801681
let new_hash = new_fingerprint.hash_u64();
16811682

16821683
if util::to_hex(new_hash) == old_fingerprint_short && new_fingerprint.fs_status.up_to_date() {
1683-
return Ok(());
1684+
return Ok(None);
16841685
}
16851686

16861687
let old_fingerprint_json = paths::read(&loc.with_extension("json"))?;
@@ -1693,23 +1694,28 @@ fn compare_old_fingerprint(
16931694
old_fingerprint_short
16941695
);
16951696
}
1696-
let result = new_fingerprint.compare(&old_fingerprint);
1697-
match result {
1698-
Ok(_) => panic!("compare should not return Ok"),
1699-
Err(e) => Err(e.into()),
1700-
}
1697+
1698+
Ok(Some(new_fingerprint.compare(&old_fingerprint)))
17011699
}
17021700

1703-
fn log_compare(unit: &Unit, compare: &CargoResult<()>) {
1704-
let ce = match compare {
1705-
Ok(..) => return,
1706-
Err(e) => e,
1707-
};
1708-
info!(
1709-
"fingerprint error for {}/{:?}/{:?}",
1710-
unit.pkg, unit.mode, unit.target,
1711-
);
1712-
info!(" err: {:?}", ce);
1701+
fn log_compare(unit: &Unit, compare: &CargoResult<Option<DirtyReason>>) {
1702+
match compare {
1703+
Ok(None) => {},
1704+
Ok(Some(reason)) => {
1705+
info!(
1706+
"fingerprint dirty for {}/{:?}/{:?}",
1707+
unit.pkg, unit.mode, unit.target,
1708+
);
1709+
info!(" dirty: {reason:?}");
1710+
},
1711+
Err(e) => {
1712+
info!(
1713+
"fingerprint error for {}/{:?}/{:?}",
1714+
unit.pkg, unit.mode, unit.target,
1715+
);
1716+
info!(" err: {e:?}");
1717+
},
1718+
}
17131719
}
17141720

17151721
/// Parses Cargo's internal `EncodedDepInfo` structure that was previously

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@ pub enum DirtyReason {
7171
Forced,
7272
}
7373

74-
// still need to implement Display for Error
75-
impl fmt::Display for DirtyReason {
76-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77-
write!(f, "dirty")
78-
}
79-
}
80-
81-
impl std::error::Error for DirtyReason {}
82-
8374
trait ShellExt {
8475
fn dirty_because(&mut self, unit: &Unit, s: impl fmt::Display) -> CargoResult<()>;
8576
}

0 commit comments

Comments
 (0)