Skip to content

Commit 5e05b7d

Browse files
committed
Reduce rightward drift
1 parent 9d34fd5 commit 5e05b7d

File tree

1 file changed

+60
-64
lines changed

1 file changed

+60
-64
lines changed

src/dist/mod.rs

Lines changed: 60 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ async fn update_from_dist_(
812812

813813
let mut toolchain = opts.desc.clone();
814814
loop {
815-
match try_update_from_dist_(
815+
let result = try_update_from_dist_(
816816
opts.dl_cfg,
817817
opts.update_hash,
818818
&toolchain,
@@ -826,76 +826,72 @@ async fn update_from_dist_(
826826
opts.targets,
827827
&mut fetched,
828828
)
829-
.await
830-
{
831-
Ok(v) => break Ok(v),
832-
Err(e) => {
833-
if !backtrack {
834-
break Err(e);
835-
}
836-
837-
let cause = e.downcast_ref::<DistError>();
838-
match cause {
839-
Some(DistError::ToolchainComponentsMissing(components, manifest, ..)) => {
840-
(opts.dl_cfg.notify_handler)(
841-
Notification::SkippingNightlyMissingComponent(
842-
&toolchain,
843-
current_manifest.as_ref().unwrap_or(manifest),
844-
components,
845-
),
846-
);
847-
848-
if first_err.is_none() {
849-
first_err = Some(e);
850-
}
851-
// We decrement the backtrack count only on unavailable component errors
852-
// so that the limit only applies to nightlies that were indeed available,
853-
// and ignores missing ones.
854-
backtrack_limit = backtrack_limit.map(|n| n - 1);
855-
}
829+
.await;
856830

857-
Some(DistError::MissingReleaseForToolchain(..)) => {
858-
// no need to even print anything for missing nightlies,
859-
// since we don't really "skip" them
860-
}
861-
_ => {
862-
// All other errors break the loop
863-
break Err(e);
864-
}
865-
};
831+
let e = match result {
832+
Ok(v) => return Ok(v),
833+
Err(e) if !backtrack => return Err(e),
834+
Err(e) => e,
835+
};
866836

867-
if let Some(backtrack_limit) = backtrack_limit {
868-
if backtrack_limit < 1 {
869-
// This unwrap is safe because we can only hit this if we've
870-
// had a chance to set first_err
871-
break Err(first_err.unwrap());
872-
}
837+
let cause = e.downcast_ref::<DistError>();
838+
match cause {
839+
Some(DistError::ToolchainComponentsMissing(components, manifest, ..)) => {
840+
(opts.dl_cfg.notify_handler)(Notification::SkippingNightlyMissingComponent(
841+
&toolchain,
842+
current_manifest.as_ref().unwrap_or(manifest),
843+
components,
844+
));
845+
846+
if first_err.is_none() {
847+
first_err = Some(e);
873848
}
849+
// We decrement the backtrack count only on unavailable component errors
850+
// so that the limit only applies to nightlies that were indeed available,
851+
// and ignores missing ones.
852+
backtrack_limit = backtrack_limit.map(|n| n - 1);
853+
}
874854

875-
// The user asked to update their nightly, but the latest nightly does not have all
876-
// the components that the user currently has installed. Let's try the previous
877-
// nightlies in reverse chronological order until we find a nightly that does,
878-
// starting at one date earlier than the current manifest's date.
879-
let toolchain_date = toolchain.date.as_ref().unwrap_or(&fetched);
880-
let try_next = date_from_manifest_date(toolchain_date)
881-
.unwrap_or_else(|| panic!("Malformed manifest date: {toolchain_date:?}"))
882-
.pred_opt()
883-
.unwrap();
884-
885-
if try_next < last_manifest {
886-
// Wouldn't be an update if we go further back than the user's current nightly.
887-
if let Some(e) = first_err {
888-
break Err(e);
889-
} else {
890-
// In this case, all newer nightlies are missing, which means there are no
891-
// updates, so the user is already at the latest nightly.
892-
break Ok(None);
893-
}
894-
}
855+
Some(DistError::MissingReleaseForToolchain(..)) => {
856+
// no need to even print anything for missing nightlies,
857+
// since we don't really "skip" them
858+
}
859+
_ => {
860+
// All other errors break the loop
861+
break Err(e);
862+
}
863+
};
895864

896-
toolchain.date = Some(try_next.format("%Y-%m-%d").to_string());
865+
if let Some(backtrack_limit) = backtrack_limit {
866+
if backtrack_limit < 1 {
867+
// This unwrap is safe because we can only hit this if we've
868+
// had a chance to set first_err
869+
break Err(first_err.unwrap());
897870
}
898871
}
872+
873+
// The user asked to update their nightly, but the latest nightly does not have all
874+
// the components that the user currently has installed. Let's try the previous
875+
// nightlies in reverse chronological order until we find a nightly that does,
876+
// starting at one date earlier than the current manifest's date.
877+
let toolchain_date = toolchain.date.as_ref().unwrap_or(&fetched);
878+
let try_next = date_from_manifest_date(toolchain_date)
879+
.unwrap_or_else(|| panic!("Malformed manifest date: {toolchain_date:?}"))
880+
.pred_opt()
881+
.unwrap();
882+
883+
if try_next < last_manifest {
884+
// Wouldn't be an update if we go further back than the user's current nightly.
885+
if let Some(e) = first_err {
886+
break Err(e);
887+
} else {
888+
// In this case, all newer nightlies are missing, which means there are no
889+
// updates, so the user is already at the latest nightly.
890+
break Ok(None);
891+
}
892+
}
893+
894+
toolchain.date = Some(try_next.format("%Y-%m-%d").to_string());
899895
}
900896
}
901897

0 commit comments

Comments
 (0)