Skip to content

Commit cbded6e

Browse files
committed
cli: avoid Cfg construction indirection
1 parent ca96bac commit cbded6e

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

src/cli/common.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fmt::Display;
44
use std::fs;
55
use std::io::{BufRead, Write};
6-
use std::path::{Path, PathBuf};
6+
use std::path::Path;
77
use std::sync::LazyLock;
88
use std::{cmp, env};
99

@@ -119,11 +119,6 @@ pub(crate) fn read_line(process: &Process) -> Result<String> {
119119
.context("unable to read from stdin for confirmation")
120120
}
121121

122-
#[tracing::instrument(level = "trace", skip(process))]
123-
pub(crate) fn set_globals(current_dir: PathBuf, quiet: bool, process: &Process) -> Result<Cfg<'_>> {
124-
Cfg::from_env(current_dir, quiet, process)
125-
}
126-
127122
pub(crate) fn show_channel_update(
128123
cfg: &Cfg<'_>,
129124
name: PackageUpdate,

src/cli/proxy_mode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::{path::PathBuf, process::ExitStatus};
33
use anyhow::Result;
44

55
use crate::{
6-
cli::{common::set_globals, job, self_update},
6+
cli::{job, self_update},
77
command::run_command_for_dir,
8-
config::ActiveSource,
8+
config::{ActiveSource, Cfg},
99
process::Process,
1010
toolchain::ResolvableLocalToolchainName,
1111
};
@@ -33,7 +33,7 @@ pub async fn main(arg0: &str, current_dir: PathBuf, process: &Process) -> Result
3333
.skip(1 + toolchain.is_some() as usize)
3434
.collect();
3535

36-
let cfg = set_globals(current_dir, true, process)?;
36+
let cfg = Cfg::from_env(current_dir, true, process)?;
3737
let toolchain = cfg.resolve_local_toolchain(toolchain).await?;
3838
let mut cmd = toolchain.command(arg0)?;
3939
if toolchain_specified {

src/cli/rustup_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ pub async fn main(
584584
Err(err) if err.kind() == DisplayVersion => {
585585
write!(process.stdout().lock(), "{err}")?;
586586
info!("This is the version for the rustup toolchain manager, not the rustc compiler.");
587-
let mut cfg = common::set_globals(current_dir, true, process)?;
587+
let mut cfg = Cfg::from_env(current_dir, true, process)?;
588588
match cfg.active_rustc_version().await {
589589
Ok(Some(version)) => info!("The currently active `rustc` version is `{version}`"),
590590
Ok(None) => info!("No `rustc` is currently active"),
@@ -611,7 +611,7 @@ pub async fn main(
611611

612612
update_console_filter(process, &console_filter, matches.quiet, matches.verbose);
613613

614-
let cfg = &mut common::set_globals(current_dir, matches.quiet, process)?;
614+
let cfg = &mut Cfg::from_env(current_dir, matches.quiet, process)?;
615615
cfg.toolchain_override = matches.plus_toolchain;
616616

617617
let Some(subcmd) = matches.subcmd else {

src/cli/self_update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,8 @@ pub(crate) fn cleanup_self_updater(process: &Process) -> Result<()> {
13851385
mod tests {
13861386
use std::collections::HashMap;
13871387

1388-
use crate::cli::common;
13891388
use crate::cli::self_update::InstallOpts;
1389+
use crate::config::Cfg;
13901390
use crate::dist::{PartialToolchainDesc, Profile};
13911391
use crate::test::{Env, test_dir, with_rustup_home};
13921392
use crate::{for_host, process::TestProcess};
@@ -1398,7 +1398,7 @@ mod tests {
13981398
home.apply(&mut vars);
13991399
let tp = TestProcess::with_vars(vars);
14001400
let mut cfg =
1401-
common::set_globals(tp.process.current_dir().unwrap(), false, &tp.process).unwrap();
1401+
Cfg::from_env(tp.process.current_dir().unwrap(), false, &tp.process).unwrap();
14021402

14031403
let opts = InstallOpts {
14041404
default_host_triple: None,

src/cli/setup_mode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
common::{self, update_console_filter},
1111
self_update::{self, InstallOpts},
1212
},
13+
config::Cfg,
1314
dist::Profile,
1415
process::Process,
1516
toolchain::MaybeOfficialToolchainName,
@@ -128,6 +129,6 @@ pub async fn main(
128129
targets: &target.iter().map(|s| &**s).collect::<Vec<_>>(),
129130
};
130131

131-
let mut cfg = common::set_globals(current_dir, quiet, process)?;
132+
let mut cfg = Cfg::from_env(current_dir, quiet, process)?;
132133
self_update::install(no_prompt, opts, &mut cfg).await
133134
}

0 commit comments

Comments
 (0)