Skip to content

Commit

Permalink
feat(config)!: remove implicit installation from `toolchain_from_part…
Browse files Browse the repository at this point in the history
…ial()`
  • Loading branch information
rami3l committed Aug 8, 2024
1 parent f131d6e commit ad2df9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ async fn target_list(
quiet: bool,
) -> Result<utils::ExitCode> {
// downcasting required because the toolchain files can name any toolchain
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
let distributable = DistributableToolchain::from_partial(toolchain, cfg)?;
common::list_items(
distributable,
|c| {
Expand All @@ -1124,7 +1124,7 @@ async fn target_add(
// isn't a feature yet.
// list_components *and* add_component would both be inappropriate for
// custom toolchains.
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
let distributable = DistributableToolchain::from_partial(toolchain, cfg)?;
let components = distributable.components()?;

if targets.contains(&"all".to_string()) {
Expand Down Expand Up @@ -1168,7 +1168,7 @@ async fn target_remove(
targets: Vec<String>,
toolchain: Option<PartialToolchainDesc>,
) -> Result<utils::ExitCode> {
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
let distributable = DistributableToolchain::from_partial(toolchain, cfg)?;

for target in targets {
let target = TargetTriple::new(target);
Expand Down Expand Up @@ -1204,7 +1204,7 @@ async fn component_list(
quiet: bool,
) -> Result<utils::ExitCode> {
// downcasting required because the toolchain files can name any toolchain
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
let distributable = DistributableToolchain::from_partial(toolchain, cfg)?;
common::list_items(
distributable,
|c| Some(&c.name),
Expand All @@ -1220,7 +1220,7 @@ async fn component_add(
toolchain: Option<PartialToolchainDesc>,
target: Option<String>,
) -> Result<utils::ExitCode> {
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
let distributable = DistributableToolchain::from_partial(toolchain, cfg)?;
let target = get_target(target, &distributable);

for component in &components {
Expand All @@ -1246,7 +1246,7 @@ async fn component_remove(
toolchain: Option<PartialToolchainDesc>,
target: Option<String>,
) -> Result<utils::ExitCode> {
let distributable = DistributableToolchain::from_partial(toolchain, cfg).await?;
let distributable = DistributableToolchain::from_partial(toolchain, cfg)?;
let target = get_target(target, &distributable);

for component in &components {
Expand Down Expand Up @@ -1447,7 +1447,7 @@ async fn doc(
mut topic: Option<&str>,
doc_page: &DocPage,
) -> Result<utils::ExitCode> {
let toolchain = cfg.toolchain_from_partial(toolchain).await?;
let toolchain = cfg.toolchain_from_partial(toolchain)?;

if let Ok(distributable) = DistributableToolchain::try_from(&toolchain) {
if let [_] = distributable
Expand Down Expand Up @@ -1508,7 +1508,7 @@ async fn man(
command: &str,
toolchain: Option<PartialToolchainDesc>,
) -> Result<utils::ExitCode> {
let toolchain = cfg.toolchain_from_partial(toolchain).await?;
let toolchain = cfg.toolchain_from_partial(toolchain)?;
let path = toolchain.man_path();
utils::assert_is_directory(&path)?;

Expand Down
14 changes: 6 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,18 @@ impl<'a> Cfg<'a> {
.transpose()?)
}

pub(crate) async fn toolchain_from_partial(
pub(crate) fn toolchain_from_partial(
&self,
toolchain: Option<PartialToolchainDesc>,
) -> anyhow::Result<Toolchain<'_>> {
match toolchain {
let toolchain = match toolchain {
Some(toolchain) => {
let desc = toolchain.resolve(&self.get_default_host_triple()?)?;
Ok(Toolchain::new(
self,
LocalToolchainName::Named(ToolchainName::Official(desc)),
)?)
Some(LocalToolchainName::Named(ToolchainName::Official(desc)))
}
None => Ok(self.find_or_install_active_toolchain(false).await?.0),
}
None => None,
};
self.local_toolchain(toolchain)
}

pub(crate) fn find_active_toolchain(
Expand Down
6 changes: 2 additions & 4 deletions src/toolchain/distributable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ pub(crate) struct DistributableToolchain<'a> {
}

impl<'a> DistributableToolchain<'a> {
pub(crate) async fn from_partial(
pub(crate) fn from_partial(
toolchain: Option<PartialToolchainDesc>,
cfg: &'a Cfg<'a>,
) -> anyhow::Result<Self> {
Ok(Self::try_from(
&cfg.toolchain_from_partial(toolchain).await?,
)?)
Ok(Self::try_from(&cfg.toolchain_from_partial(toolchain)?)?)
}

pub(crate) fn new(cfg: &'a Cfg<'a>, desc: ToolchainDesc) -> Result<Self, RustupError> {
Expand Down

0 comments on commit ad2df9e

Please sign in to comment.