Skip to content

Commit 53fca75

Browse files
committed
Move desc to DistributableToolchain
1 parent 2ebfa92 commit 53fca75

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/cli/rustup_mode.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,9 @@ fn component_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
11721172

11731173
fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
11741174
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
1175+
let distributable = DistributableToolchain::new(&toolchain)?;
11751176
let target = m.value_of("target").map(TargetTriple::new).or_else(|| {
1176-
toolchain
1177+
distributable
11771178
.desc()
11781179
.as_ref()
11791180
.ok()
@@ -1183,7 +1184,6 @@ fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
11831184
for component in m.values_of("component").unwrap() {
11841185
let new_component = Component::new_with_target(component, false)
11851186
.unwrap_or_else(|| Component::new(component.to_string(), target.clone(), true));
1186-
let distributable = DistributableToolchain::new(&toolchain)?;
11871187
distributable.add_component(new_component)?;
11881188
}
11891189

@@ -1192,8 +1192,10 @@ fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
11921192

11931193
fn component_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
11941194
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
1195+
let distributable = DistributableToolchain::new(&toolchain)
1196+
.chain_err(|| rustup::ErrorKind::ComponentsUnsupported(toolchain.name().to_string()))?;
11951197
let target = m.value_of("target").map(TargetTriple::new).or_else(|| {
1196-
toolchain
1198+
distributable
11971199
.desc()
11981200
.as_ref()
11991201
.ok()
@@ -1203,9 +1205,6 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
12031205
for component in m.values_of("component").unwrap() {
12041206
let new_component = Component::new_with_target(component, false)
12051207
.unwrap_or_else(|| Component::new(component.to_string(), target.clone(), true));
1206-
1207-
let distributable = DistributableToolchain::new(&toolchain)
1208-
.chain_err(|| rustup::ErrorKind::ComponentsUnsupported(toolchain.name().to_string()))?;
12091208
distributable.remove_component(new_component)?;
12101209
}
12111210

src/toolchain.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ impl<'a> Toolchain<'a> {
6262
pub fn name(&self) -> &str {
6363
&self.name
6464
}
65-
// Distributable only
66-
pub fn desc(&self) -> Result<ToolchainDesc> {
67-
Ok(ToolchainDesc::from_str(&self.name)?)
68-
}
6965
pub fn path(&self) -> &Path {
7066
&self.path
7167
}
@@ -618,6 +614,11 @@ impl<'a> DistributableToolchain<'a> {
618614
}
619615
}
620616

617+
// Installed and not-installed?
618+
pub fn desc(&self) -> Result<ToolchainDesc> {
619+
Ok(ToolchainDesc::from_str(&self.0.name)?)
620+
}
621+
621622
// Installed only?
622623
fn get_component_suggestion(
623624
&self,
@@ -728,7 +729,7 @@ impl<'a> DistributableToolchain<'a> {
728729
let update_hash = self.0.update_hash()?;
729730
let old_date = self.get_manifest().ok().and_then(|m| m.map(|m| m.date));
730731
self.0.install(InstallMethod::Dist(
731-
&self.0.desc()?,
732+
&self.desc()?,
732733
self.0.cfg.get_profile()?,
733734
update_hash.as_ref().map(|p| &**p),
734735
self.0.download_cfg(),
@@ -745,7 +746,7 @@ impl<'a> DistributableToolchain<'a> {
745746
pub fn install_from_dist_if_not_installed(&self) -> Result<UpdateStatus> {
746747
let update_hash = self.0.update_hash()?;
747748
self.0.install_if_not_installed(InstallMethod::Dist(
748-
&self.0.desc()?,
749+
&self.desc()?,
749750
self.0.cfg.get_profile()?,
750751
update_hash.as_ref().map(|p| &**p),
751752
self.0.download_cfg(),
@@ -888,7 +889,7 @@ impl<'a> DistributableToolchain<'a> {
888889
match crate::dist::dist::dl_v2_manifest(
889890
self.0.download_cfg(),
890891
update_hash.as_ref().map(|p| &**p),
891-
&self.0.desc()?,
892+
&self.desc()?,
892893
)? {
893894
Some((manifest, _)) => Ok(Some(manifest.get_rust_version()?.to_string())),
894895
None => Ok(None),

0 commit comments

Comments
 (0)