Skip to content

Commit 1ce01c5

Browse files
committed
Auto merge of #11960 - ehuss:chdir-unstable, r=weihanglo
Change -C to be unstable Due to #11957, we have decided to change `-C` to be unstable to give us some more time to decide on how it should behave.
2 parents 7bf43f0 + 3da2b3c commit 1ce01c5

File tree

100 files changed

+533
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+533
-37
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767

6868
### Added
6969

70-
- Added `-C` flag for changing current dir before build starts.
71-
[#10952](https://github.com/rust-lang/cargo/pull/10952)
7270
- Cargo now suggests `cargo fix` or `cargo clippy --fix`
7371
when compilation warnings are auto-fixable.
7472
[#11558](https://github.com/rust-lang/cargo/pull/11558)
@@ -130,6 +128,8 @@
130128
- Emit an error message for transitive artifact dependencies with targets the
131129
package doesn't directly interact with.
132130
[#11643](https://github.com/rust-lang/cargo/pull/11643)
131+
- Added `-C` flag for changing current dir before build starts.
132+
[#10952](https://github.com/rust-lang/cargo/pull/10952)
133133

134134
### Documentation
135135

src/bin/cargo/cli.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ pub fn main(config: &mut LazyConfig) -> CliResult {
3131
// This must be completed before config is initialized
3232
assert_eq!(config.is_init(), false);
3333
if let Some(new_cwd) = args.get_one::<std::path::PathBuf>("directory") {
34+
// This is a temporary hack. This cannot access `Config`, so this is a bit messy.
35+
// This does not properly parse `-Z` flags that appear after the subcommand.
36+
// The error message is not as helpful as the standard one.
37+
let nightly_features_allowed = matches!(&*features::channel(), "nightly" | "dev");
38+
if !nightly_features_allowed
39+
|| (nightly_features_allowed
40+
&& !args
41+
.get_many("unstable-features")
42+
.map(|mut z| z.any(|value: &String| value == "unstable-options"))
43+
.unwrap_or(false))
44+
{
45+
return Err(anyhow::format_err!(
46+
"the `-C` flag is unstable, \
47+
pass `-Z unstable-options` on the nightly channel to enable it"
48+
)
49+
.into());
50+
}
3451
std::env::set_current_dir(&new_cwd).context("could not change to requested directory")?;
3552
}
3653

@@ -479,7 +496,7 @@ See 'cargo help <command>' for more information on a specific command.\n",
479496
)
480497
.arg(
481498
Arg::new("directory")
482-
.help("Change to DIRECTORY before doing anything")
499+
.help("Change to DIRECTORY before doing anything (nightly-only)")
483500
.short('C')
484501
.value_name("DIRECTORY")
485502
.value_hint(clap::ValueHint::DirPath)

src/doc/man/generated_txt/cargo-add.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ OPTIONS
195195
option must appear before the command name, for example cargo -C
196196
path/to/my-project build.
197197

198+
This option is only available on the nightly channel
199+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
200+
requires the -Z unstable-options flag to enable (see #10098
201+
<https://github.com/rust-lang/cargo/issues/10098>).
202+
198203
-h, --help
199204
Prints help information.
200205

src/doc/man/generated_txt/cargo-bench.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ OPTIONS
380380
option must appear before the command name, for example cargo -C
381381
path/to/my-project build.
382382

383+
This option is only available on the nightly channel
384+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
385+
requires the -Z unstable-options flag to enable (see #10098
386+
<https://github.com/rust-lang/cargo/issues/10098>).
387+
383388
-h, --help
384389
Prints help information.
385390

src/doc/man/generated_txt/cargo-build.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ OPTIONS
322322
option must appear before the command name, for example cargo -C
323323
path/to/my-project build.
324324

325+
This option is only available on the nightly channel
326+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
327+
requires the -Z unstable-options flag to enable (see #10098
328+
<https://github.com/rust-lang/cargo/issues/10098>).
329+
325330
-h, --help
326331
Prints help information.
327332

src/doc/man/generated_txt/cargo-check.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ OPTIONS
307307
option must appear before the command name, for example cargo -C
308308
path/to/my-project build.
309309

310+
This option is only available on the nightly channel
311+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
312+
requires the -Z unstable-options flag to enable (see #10098
313+
<https://github.com/rust-lang/cargo/issues/10098>).
314+
310315
-h, --help
311316
Prints help information.
312317

src/doc/man/generated_txt/cargo-clean.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ OPTIONS
136136
option must appear before the command name, for example cargo -C
137137
path/to/my-project build.
138138

139+
This option is only available on the nightly channel
140+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
141+
requires the -Z unstable-options flag to enable (see #10098
142+
<https://github.com/rust-lang/cargo/issues/10098>).
143+
139144
-h, --help
140145
Prints help information.
141146

src/doc/man/generated_txt/cargo-doc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ OPTIONS
278278
option must appear before the command name, for example cargo -C
279279
path/to/my-project build.
280280

281+
This option is only available on the nightly channel
282+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
283+
requires the -Z unstable-options flag to enable (see #10098
284+
<https://github.com/rust-lang/cargo/issues/10098>).
285+
281286
-h, --help
282287
Prints help information.
283288

src/doc/man/generated_txt/cargo-fetch.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ OPTIONS
121121
option must appear before the command name, for example cargo -C
122122
path/to/my-project build.
123123

124+
This option is only available on the nightly channel
125+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
126+
requires the -Z unstable-options flag to enable (see #10098
127+
<https://github.com/rust-lang/cargo/issues/10098>).
128+
124129
-h, --help
125130
Prints help information.
126131

src/doc/man/generated_txt/cargo-fix.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ OPTIONS
380380
option must appear before the command name, for example cargo -C
381381
path/to/my-project build.
382382

383+
This option is only available on the nightly channel
384+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
385+
requires the -Z unstable-options flag to enable (see #10098
386+
<https://github.com/rust-lang/cargo/issues/10098>).
387+
383388
-h, --help
384389
Prints help information.
385390

0 commit comments

Comments
 (0)