Skip to content

Commit 446ed6e

Browse files
committed
Auto merge of #4578 - derekdreery:refactor/cargo_util_config, r=alexcrichton
Remove some cells from Config In most cases it makes sense to not use interior mutability in Config, so that mutability is more transparent. This PR removes Cells in these cases. It leaves those cases where parameters are only initialized on first access (LazyCell).
2 parents 49ab521 + 24d745a commit 446ed6e

33 files changed

Lines changed: 75 additions & 58 deletions

src/bin/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ not affect how many jobs are used when running the benchmarks.
9595
Compilation can be customized with the `bench` profile in the manifest.
9696
";
9797

98-
pub fn execute(options: Options, config: &Config) -> CliResult {
98+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
9999
debug!("executing; cmd=cargo-bench; args={:?}",
100100
env::args().collect::<Vec<_>>());
101101

src/bin/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ the manifest. The default profile for this command is `dev`, but passing
8787
the --release flag will use the `release` profile instead.
8888
";
8989

90-
pub fn execute(options: Options, config: &Config) -> CliResult {
90+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
9191
debug!("executing; cmd=cargo-build; args={:?}",
9292
env::args().collect::<Vec<_>>());
9393
config.configure(options.flag_verbose,

src/bin/cargo.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ See 'cargo help <command>' for more information on a specific command.
7575
fn main() {
7676
env_logger::init().unwrap();
7777

78-
let config = match Config::default() {
78+
let mut config = match Config::default() {
7979
Ok(cfg) => cfg,
8080
Err(e) => {
8181
let mut shell = Shell::new();
@@ -92,7 +92,7 @@ fn main() {
9292
})
9393
.collect());
9494
let rest = &args;
95-
cargo::call_main_without_stdin(execute, &config, USAGE, rest, true)
95+
cargo::call_main_without_stdin(execute, &mut config, USAGE, rest, true)
9696
})();
9797

9898
match result {
@@ -146,7 +146,7 @@ each_subcommand!(declare_mod);
146146
because they are fundamental (and intertwined). Other commands can rely
147147
on this top-level information.
148148
*/
149-
fn execute(flags: Flags, config: &Config) -> CliResult {
149+
fn execute(flags: Flags, config: &mut Config) -> CliResult {
150150
config.configure(flags.flag_verbose,
151151
flags.flag_quiet,
152152
&flags.flag_color,
@@ -250,11 +250,12 @@ fn execute(flags: Flags, config: &Config) -> CliResult {
250250
execute_external_subcommand(config, &args[1], &args)
251251
}
252252

253-
fn try_execute_builtin_command(config: &Config, args: &[String]) -> Option<CliResult> {
253+
fn try_execute_builtin_command(config: &mut Config, args: &[String]) -> Option<CliResult> {
254254
macro_rules! cmd {
255255
($name:ident) => (if args[1] == stringify!($name).replace("_", "-") {
256256
config.shell().set_verbosity(Verbosity::Verbose);
257-
let r = cargo::call_main_without_stdin($name::execute, config,
257+
let r = cargo::call_main_without_stdin($name::execute,
258+
config,
258259
$name::USAGE,
259260
&args,
260261
false);

src/bin/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub struct Options {
8787
flag_z: Vec<String>,
8888
}
8989

90-
pub fn execute(options: Options, config: &Config) -> CliResult {
90+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
9191
debug!("executing; cmd=cargo-check; args={:?}",
9292
env::args().collect::<Vec<_>>());
9393

src/bin/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ given, then all packages' artifacts are removed. For more information on SPEC
4545
and its format, see the `cargo help pkgid` command.
4646
";
4747

48-
pub fn execute(options: Options, config: &Config) -> CliResult {
48+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
4949
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
5050
config.configure(options.flag_verbose,
5151
options.flag_quiet,

src/bin/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ current package is documented. For more information on SPEC and its format, see
7474
the `cargo help pkgid` command.
7575
";
7676

77-
pub fn execute(options: Options, config: &Config) -> CliResult {
77+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
7878
debug!("executing; cmd=cargo-check; args={:?}",
7979
env::args().collect::<Vec<_>>());
8080

src/bin/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If the lockfile is not available, then this is the equivalent of
4141
all updated.
4242
";
4343

44-
pub fn execute(options: Options, config: &Config) -> CliResult {
44+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
4545
config.configure(options.flag_verbose,
4646
options.flag_quiet,
4747
&options.flag_color,

src/bin/generate_lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Options:
3434
-Z FLAG ... Unstable (nightly-only) flags to Cargo
3535
";
3636

37-
pub fn execute(options: Options, config: &Config) -> CliResult {
37+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
3838
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
3939
config.configure(options.flag_verbose,
4040
options.flag_quiet,

src/bin/git_checkout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Options:
3232
-Z FLAG ... Unstable (nightly-only) flags to Cargo
3333
";
3434

35-
pub fn execute(options: Options, config: &Config) -> CliResult {
35+
pub fn execute(options: Options, config: &mut Config) -> CliResult {
3636
config.configure(options.flag_verbose,
3737
options.flag_quiet,
3838
&options.flag_color,

src/bin/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Options:
1414
-h, --help Print this message
1515
";
1616

17-
pub fn execute(_: Options, _: &Config) -> CliResult {
17+
pub fn execute(_: Options, _: &mut Config) -> CliResult {
1818
// This is a dummy command just so that `cargo help help` works.
1919
// The actual delegation of help flag to subcommands is handled by the
2020
// cargo command.

0 commit comments

Comments
 (0)