@@ -19,7 +19,13 @@ use serde::{Deserialize, Serialize};
1919use thiserror:: Error as ThisError ;
2020use tracing:: { debug, info, warn} ;
2121
22- use crate :: { config:: Cfg , errors:: RustupError , process:: Process , toolchain:: ToolchainName , utils} ;
22+ use crate :: {
23+ config:: Cfg ,
24+ errors:: RustupError ,
25+ process:: Process ,
26+ toolchain:: { DistributableToolchain , ToolchainName } ,
27+ utils,
28+ } ;
2329
2430pub mod component;
2531pub ( crate ) mod config;
@@ -876,14 +882,14 @@ impl fmt::Display for Profile {
876882 }
877883}
878884
879- pub ( crate ) struct DistOptions < ' a > {
880- pub ( super ) cfg : & ' a Cfg < ' a > ,
885+ pub ( crate ) struct DistOptions < ' cfg , ' a > {
886+ pub ( super ) cfg : & ' cfg Cfg < ' cfg > ,
881887 pub ( super ) toolchain : & ' a ToolchainDesc ,
882888 profile : Profile ,
883889 pub ( super ) update_hash : PathBuf ,
884- dl_cfg : DownloadCfg < ' a > ,
890+ dl_cfg : DownloadCfg < ' cfg > ,
885891 /// --force bool is whether to force an update/install
886- force : bool ,
892+ pub ( super ) force : bool ,
887893 /// --allow-downgrade
888894 pub ( super ) allow_downgrade : bool ,
889895 /// toolchain already exists
@@ -896,14 +902,14 @@ pub(crate) struct DistOptions<'a> {
896902 targets : & ' a [ & ' a str ] ,
897903}
898904
899- impl < ' a > DistOptions < ' a > {
905+ impl < ' cfg , ' a > DistOptions < ' cfg , ' a > {
900906 pub ( super ) fn new (
901907 components : & ' a [ & ' a str ] ,
902908 targets : & ' a [ & ' a str ] ,
903909 toolchain : & ' a ToolchainDesc ,
904910 profile : Profile ,
905911 force : bool ,
906- cfg : & ' a Cfg < ' _ > ,
912+ cfg : & ' cfg Cfg < ' cfg > ,
907913 ) -> Result < Self > {
908914 Ok ( Self {
909915 cfg,
@@ -919,6 +925,31 @@ impl<'a> DistOptions<'a> {
919925 targets,
920926 } )
921927 }
928+
929+ pub ( super ) fn for_update (
930+ mut self ,
931+ toolchain : & ' a DistributableToolchain < ' cfg > ,
932+ allow_downgrade : bool ,
933+ ) -> Self {
934+ self . allow_downgrade = allow_downgrade;
935+ self . exists = true ;
936+ self . old_date_version =
937+ // Ignore a missing manifest: we can't report the old version
938+ // correctly, and it probably indicates an incomplete install, so do
939+ // not report an old rustc version either.
940+ toolchain. get_manifest ( )
941+ . map ( |m| {
942+ (
943+ m. date ,
944+ // should rustc_version be a free function on a trait?
945+ // note that prev_version can be junk if the rustc component is missing ...
946+ toolchain. toolchain . rustc_version ( ) ,
947+ )
948+ } )
949+ . ok ( ) ;
950+
951+ self
952+ }
922953}
923954
924955// Installs or updates a toolchain from a dist server. If an initial
@@ -929,7 +960,7 @@ impl<'a> DistOptions<'a> {
929960#[ tracing:: instrument( level = "trace" , err( level = "trace" ) , skip_all, fields( profile = ?opts. profile, prefix = %prefix. path( ) . display( ) ) ) ]
930961pub ( crate ) async fn update_from_dist (
931962 prefix : & InstallPrefix ,
932- opts : & DistOptions < ' _ > ,
963+ opts : & DistOptions < ' _ , ' _ > ,
933964) -> Result < Option < String > > {
934965 let fresh_install = !prefix. path ( ) . exists ( ) ;
935966 // fresh_install means the toolchain isn't present, but hash_exists means there is a stray hash file
0 commit comments