Skip to content

Commit 336450d

Browse files
committed
No need to store cfg in DistributableToolchain
1 parent c4c7674 commit 336450d

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/toolchain/distributable.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use super::{
2828
#[derive(Debug)]
2929
pub(crate) struct DistributableToolchain<'a> {
3030
pub(super) toolchain: Toolchain<'a>,
31-
cfg: &'a Cfg<'a>,
3231
desc: ToolchainDesc,
3332
}
3433

@@ -43,11 +42,7 @@ impl<'a> DistributableToolchain<'a> {
4342
}
4443

4544
pub(crate) fn new(cfg: &'a Cfg<'a>, desc: ToolchainDesc) -> Result<Self, RustupError> {
46-
Toolchain::new(cfg, (&desc).into()).map(|toolchain| Self {
47-
toolchain,
48-
cfg,
49-
desc,
50-
})
45+
Toolchain::new(cfg, (&desc).into()).map(|toolchain| Self { toolchain, desc })
5146
}
5247

5348
pub(crate) fn desc(&self) -> &ToolchainDesc {
@@ -109,8 +104,8 @@ impl<'a> DistributableToolchain<'a> {
109104
};
110105

111106
let notify_handler =
112-
&|n: crate::dist::Notification<'_>| (self.cfg.notify_handler)(n.into());
113-
let download_cfg = self.cfg.download_cfg(&notify_handler);
107+
&|n: crate::dist::Notification<'_>| (self.toolchain.cfg.notify_handler)(n.into());
108+
let download_cfg = self.toolchain.cfg.download_cfg(&notify_handler);
114109

115110
manifestation
116111
.update(
@@ -204,7 +199,7 @@ impl<'a> DistributableToolchain<'a> {
204199
// it to do that, because cargo's directory contains the _wrong_ rustc. See
205200
// the documentation for the lpCommandLine argument of CreateProcess.
206201
let exe_path = if cfg!(windows) {
207-
let fallback_dir = self.cfg.rustup_dir.join("fallback");
202+
let fallback_dir = self.toolchain.cfg.rustup_dir.join("fallback");
208203
fs::create_dir_all(&fallback_dir)
209204
.context("unable to create dir to hold fallback exe")?;
210205
let fallback_file = fallback_dir.join("cargo.exe");
@@ -413,17 +408,16 @@ impl<'a> DistributableToolchain<'a> {
413408
})
414409
.ok();
415410

416-
let hash_path = self.cfg.get_hash_file(&self.desc, true)?;
411+
let cfg = self.toolchain.cfg;
412+
let hash_path = cfg.get_hash_file(&self.desc, true)?;
417413
let update_hash = Some(&hash_path as &Path);
418414

419415
InstallMethod::Dist {
420-
cfg: self.cfg,
416+
cfg,
421417
desc: &self.desc,
422418
profile,
423419
update_hash,
424-
dl_cfg: self
425-
.cfg
426-
.download_cfg(&|n| (self.cfg.notify_handler)(n.into())),
420+
dl_cfg: cfg.download_cfg(&|n| (cfg.notify_handler)(n.into())),
427421
force,
428422
allow_downgrade,
429423
exists: true,
@@ -456,7 +450,7 @@ impl<'a> DistributableToolchain<'a> {
456450
"the '{binary_lossy}' binary, normally provided by the '{short_name}' component, is not applicable to the '{desc}' toolchain"))
457451
} else {
458452
// available, not installed, recommend installation
459-
let selector = match self.cfg.get_default()? {
453+
let selector = match self.toolchain.cfg.get_default()? {
460454
Some(ToolchainName::Official(n)) if n == self.desc => String::new(),
461455
_ => format!("--toolchain {} ", self.toolchain.name()),
462456
};
@@ -516,8 +510,8 @@ impl<'a> DistributableToolchain<'a> {
516510
};
517511

518512
let notify_handler =
519-
&|n: crate::dist::Notification<'_>| (self.cfg.notify_handler)(n.into());
520-
let download_cfg = self.cfg.download_cfg(&notify_handler);
513+
&|n: crate::dist::Notification<'_>| (self.toolchain.cfg.notify_handler)(n.into());
514+
let download_cfg = self.toolchain.cfg.download_cfg(&notify_handler);
521515

522516
manifestation
523517
.update(
@@ -534,10 +528,10 @@ impl<'a> DistributableToolchain<'a> {
534528
}
535529

536530
pub async fn show_dist_version(&self) -> anyhow::Result<Option<String>> {
537-
let update_hash = self.cfg.get_hash_file(&self.desc, false)?;
531+
let update_hash = self.toolchain.cfg.get_hash_file(&self.desc, false)?;
538532
let notify_handler =
539-
&|n: crate::dist::Notification<'_>| (self.cfg.notify_handler)(n.into());
540-
let download_cfg = self.cfg.download_cfg(&notify_handler);
533+
&|n: crate::dist::Notification<'_>| (self.toolchain.cfg.notify_handler)(n.into());
534+
let download_cfg = self.toolchain.cfg.download_cfg(&notify_handler);
541535

542536
match crate::dist::dl_v2_manifest(download_cfg, Some(&update_hash), &self.desc).await? {
543537
Some((manifest, _)) => Ok(Some(manifest.get_rust_version()?.to_string())),
@@ -574,7 +568,6 @@ impl<'a> TryFrom<&Toolchain<'a>> for DistributableToolchain<'a> {
574568
match value.name() {
575569
LocalToolchainName::Named(ToolchainName::Official(desc)) => Ok(Self {
576570
toolchain: value.clone(),
577-
cfg: value.cfg,
578571
desc: desc.clone(),
579572
}),
580573
n => Err(RustupError::ComponentsUnsupported(n.to_string())),

0 commit comments

Comments
 (0)