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

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

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

99+
This option is only available on the nightly channel
100+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
101+
requires the -Z unstable-options flag to enable (see #10098
102+
<https://github.com/rust-lang/cargo/issues/10098>).
103+
99104
-h, --help
100105
Prints help information.
101106

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

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

107+
This option is only available on the nightly channel
108+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
109+
requires the -Z unstable-options flag to enable (see #10098
110+
<https://github.com/rust-lang/cargo/issues/10098>).
111+
107112
-h, --help
108113
Prints help information.
109114

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

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

362+
This option is only available on the nightly channel
363+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
364+
requires the -Z unstable-options flag to enable (see #10098
365+
<https://github.com/rust-lang/cargo/issues/10098>).
366+
362367
-h, --help
363368
Prints help information.
364369

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

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

90+
This option is only available on the nightly channel
91+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
92+
requires the -Z unstable-options flag to enable (see #10098
93+
<https://github.com/rust-lang/cargo/issues/10098>).
94+
9095
-h, --help
9196
Prints help information.
9297

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

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

82+
This option is only available on the nightly channel
83+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
84+
requires the -Z unstable-options flag to enable (see #10098
85+
<https://github.com/rust-lang/cargo/issues/10098>).
86+
8287
-h, --help
8388
Prints help information.
8489

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

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

412+
This option is only available on the nightly channel
413+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
414+
requires the -Z unstable-options flag to enable (see #10098
415+
<https://github.com/rust-lang/cargo/issues/10098>).
416+
412417
-h, --help
413418
Prints help information.
414419

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

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

102+
This option is only available on the nightly channel
103+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
104+
requires the -Z unstable-options flag to enable (see #10098
105+
<https://github.com/rust-lang/cargo/issues/10098>).
106+
102107
-h, --help
103108
Prints help information.
104109

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

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

109+
This option is only available on the nightly channel
110+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
111+
requires the -Z unstable-options flag to enable (see #10098
112+
<https://github.com/rust-lang/cargo/issues/10098>).
113+
109114
-h, --help
110115
Prints help information.
111116

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

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

251+
This option is only available on the nightly channel
252+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
253+
requires the -Z unstable-options flag to enable (see #10098
254+
<https://github.com/rust-lang/cargo/issues/10098>).
255+
251256
-h, --help
252257
Prints help information.
253258

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

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

129+
This option is only available on the nightly channel
130+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
131+
requires the -Z unstable-options flag to enable (see #10098
132+
<https://github.com/rust-lang/cargo/issues/10098>).
133+
129134
-h, --help
130135
Prints help information.
131136

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

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

217+
This option is only available on the nightly channel
218+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
219+
requires the -Z unstable-options flag to enable (see #10098
220+
<https://github.com/rust-lang/cargo/issues/10098>).
221+
217222
-h, --help
218223
Prints help information.
219224

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

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

118+
This option is only available on the nightly channel
119+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
120+
requires the -Z unstable-options flag to enable (see #10098
121+
<https://github.com/rust-lang/cargo/issues/10098>).
122+
118123
-h, --help
119124
Prints help information.
120125

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

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

229+
This option is only available on the nightly channel
230+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
231+
requires the -Z unstable-options flag to enable (see #10098
232+
<https://github.com/rust-lang/cargo/issues/10098>).
233+
229234
-h, --help
230235
Prints help information.
231236

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

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

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

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

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

297+
This option is only available on the nightly channel
298+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
299+
requires the -Z unstable-options flag to enable (see #10098
300+
<https://github.com/rust-lang/cargo/issues/10098>).
301+
297302
-h, --help
298303
Prints help information.
299304

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

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

79+
This option is only available on the nightly channel
80+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
81+
requires the -Z unstable-options flag to enable (see #10098
82+
<https://github.com/rust-lang/cargo/issues/10098>).
83+
7984
-h, --help
8085
Prints help information.
8186

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

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

401+
This option is only available on the nightly channel
402+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
403+
requires the -Z unstable-options flag to enable (see #10098
404+
<https://github.com/rust-lang/cargo/issues/10098>).
405+
401406
-h, --help
402407
Prints help information.
403408

src/doc/man/generated_txt/cargo-tree.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-uninstall.txt

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

91+
This option is only available on the nightly channel
92+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
93+
requires the -Z unstable-options flag to enable (see #10098
94+
<https://github.com/rust-lang/cargo/issues/10098>).
95+
9196
-h, --help
9297
Prints help information.
9398

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

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

129+
This option is only available on the nightly channel
130+
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
131+
requires the -Z unstable-options flag to enable (see #10098
132+
<https://github.com/rust-lang/cargo/issues/10098>).
133+
129134
-h, --help
130135
Prints help information.
131136

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

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

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

0 commit comments

Comments
 (0)