diff --git a/src/bin/cargo/commands/build.rs b/src/bin/cargo/commands/build.rs index d045f004ed5..2309114b7ad 100644 --- a/src/bin/cargo/commands/build.rs +++ b/src/bin/cargo/commands/build.rs @@ -54,22 +54,11 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { if let Some(artifact_dir) = args.value_of_path("artifact-dir", gctx) { // If the user specifies `--artifact-dir`, use that compile_opts.build_config.export_dir = Some(artifact_dir); - } else if let Some(artifact_dir) = args.value_of_path("out-dir", gctx) { - // `--out-dir` is deprecated, but still supported for now - gctx.shell() - .warn("the --out-dir flag has been changed to --artifact-dir")?; - compile_opts.build_config.export_dir = Some(artifact_dir); } else if let Some(artifact_dir) = gctx.build_config()?.artifact_dir.as_ref() { // If a CLI option is not specified for choosing the artifact dir, use the `artifact-dir` from the build config, if // present let artifact_dir = artifact_dir.resolve_path(gctx); compile_opts.build_config.export_dir = Some(artifact_dir); - } else if let Some(artifact_dir) = gctx.build_config()?.out_dir.as_ref() { - // As a last priority, check `out-dir` in the build config - gctx.shell() - .warn("the out-dir config option has been changed to artifact-dir")?; - let artifact_dir = artifact_dir.resolve_path(gctx); - compile_opts.build_config.export_dir = Some(artifact_dir); } if compile_opts.build_config.export_dir.is_some() { diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 58b98f1cbed..45269b8a9c8 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -542,15 +542,16 @@ pub trait CommandExt: Sized { .help_heading(heading::COMPILATION_OPTIONS), ) ._arg(unsupported_short_arg) - ._arg( - opt( - "out-dir", - "Copy final artifacts to this directory (deprecated; use --artifact-dir instead)", - ) - .value_name("PATH") - .conflicts_with("artifact-dir") - .hide(true), - ) + ._arg({ + let value_parser = UnknownArgumentValueParser::suggest_arg("--artifact-dir"); + Arg::new("unsupported-out-dir-flag") + .help("") + .long("out-dir") + .value_name("PATH") + .value_parser(value_parser) + .action(ArgAction::SetTrue) + .hide(true) + }) } fn arg_compile_time_deps(self) -> Self { diff --git a/src/cargo/util/context/schema.rs b/src/cargo/util/context/schema.rs index ca826892e26..a0c4bcb86fa 100644 --- a/src/cargo/util/context/schema.rs +++ b/src/cargo/util/context/schema.rs @@ -209,8 +209,6 @@ pub struct CargoBuildConfig { pub rustc_workspace_wrapper: Option, pub rustc: Option, pub rustdoc: Option, - // deprecated alias for artifact-dir - pub out_dir: Option, pub artifact_dir: Option, pub warnings: Option, /// Unstable feature `-Zsbom`. diff --git a/tests/testsuite/artifact_dir.rs b/tests/testsuite/artifact_dir.rs index d5838d5bb00..d8eec3ede78 100644 --- a/tests/testsuite/artifact_dir.rs +++ b/tests/testsuite/artifact_dir.rs @@ -326,60 +326,26 @@ For more information, try '--help'. } #[cargo_test] -fn deprecated_out_dir() { +fn removed_out_dir_flag() { let p = project() .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#) .build(); p.cargo("build -Z unstable-options --out-dir out") .masquerade_as_nightly_cargo(&["out-dir"]) + .with_status(1) .enable_mac_dsym() .with_stderr_data(str![[r#" -[WARNING] the --out-dir flag has been changed to --artifact-dir -[COMPILING] foo v0.0.1 ([ROOT]/foo) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[ERROR] unexpected argument '--out-dir' found -"#]]) - .run(); - check_dir_contents( - &p.root().join("out"), - &["foo"], - &["foo", "foo.dSYM"], - &["foo.exe", "foo.pdb"], - &["foo.exe"], - ); -} + tip: a similar argument exists: '--artifact-dir' -#[cargo_test] -fn cargo_build_deprecated_out_dir() { - let p = project() - .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#) - .file( - ".cargo/config.toml", - r#" - [build] - out-dir = "out" - "#, - ) - .build(); +Usage: cargo[EXE] build [OPTIONS] - p.cargo("build -Z unstable-options") - .masquerade_as_nightly_cargo(&["out-dir"]) - .enable_mac_dsym() - .with_stderr_data(str![[r#" -[WARNING] the out-dir config option has been changed to artifact-dir -[COMPILING] foo v0.0.1 ([ROOT]/foo) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +For more information, try '--help'. "#]]) .run(); - check_dir_contents( - &p.root().join("out"), - &["foo"], - &["foo", "foo.dSYM"], - &["foo.exe", "foo.pdb"], - &["foo.exe"], - ); } #[cargo_test]