From 3c40d6194d41f27035b57523595abb219fa8301e Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 8 Nov 2022 09:11:25 +0800 Subject: [PATCH 1/3] Error when precise or aggressive without -p flag Signed-off-by: hi-rustin --- src/bin/cargo/commands/update.rs | 14 +++++++++----- src/cargo/ops/cargo_generate_lockfile.rs | 19 ------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/bin/cargo/commands/update.rs b/src/bin/cargo/commands/update.rs index b1be319f22b..15921e51cb2 100644 --- a/src/bin/cargo/commands/update.rs +++ b/src/bin/cargo/commands/update.rs @@ -9,17 +9,21 @@ pub fn cli() -> Command { .arg_quiet() .arg(flag("workspace", "Only update the workspace packages").short('w')) .arg_package_spec_simple("Package to update") - .arg(flag( - "aggressive", - "Force updating all dependencies of SPEC as well when used with -p", - )) + .arg( + flag( + "aggressive", + "Force updating all dependencies of SPEC as well when used with -p", + ) + .requires("package"), + ) .arg_dry_run("Don't actually write the lockfile") .arg( opt( "precise", "Update a single dependency to exactly PRECISE when used with -p", ) - .value_name("PRECISE"), + .value_name("PRECISE") + .requires("package"), ) .arg_manifest_path() .after_help("Run `cargo help update` for more detailed information.\n") diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index b18c338f6c7..04d4010f45e 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -36,25 +36,6 @@ pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> { } pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> { - // Currently this is only a warning, but after a transition period this will become - // a hard error. - // See https://github.com/rust-lang/cargo/issues/10919#issuecomment-1214464756. - // We should declare the `precise` and `aggressive` arguments - // require the `package` argument in the clap. - if opts.aggressive && opts.to_update.is_empty() { - ws.config().shell().warn( - "aggressive is only supported with \"--package \", \ - this will become a hard error in a future release.", - )?; - } - - if opts.precise.is_some() && opts.to_update.is_empty() { - ws.config().shell().warn( - "precise is only supported with \"--package \", \ - this will become a hard error in a future release.", - )?; - } - if opts.aggressive && opts.precise.is_some() { anyhow::bail!("cannot specify both aggressive and precise simultaneously") } From 71e4dbd4967ff088a328bf29502cccf4834414dd Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 8 Nov 2022 09:11:41 +0800 Subject: [PATCH 2/3] Update tests Signed-off-by: hi-rustin --- tests/testsuite/update.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 22ab372b77a..f6e31d01739 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -453,11 +453,15 @@ fn update_precise_without_package() { Package::new("serde", "0.3.0").publish(); p.cargo("update --precise 0.3.0") + .with_status(1) .with_stderr( "\ -[WARNING] precise is only supported with \"--package \", this will become a hard error in a future release. -[UPDATING] `[..]` index -[UPDATING] serde v0.2.0 -> v0.2.1 +[ERROR] The following required arguments were not provided: + --package [] + +Usage: cargo[EXE] update --package [] --precise + +For more information try '--help' ", ) .run(); @@ -525,11 +529,15 @@ fn update_aggressive_without_package() { Package::new("serde", "0.2.1").publish(); p.cargo("update --aggressive") + .with_status(1) .with_stderr( "\ -[WARNING] aggressive is only supported with \"--package \", this will become a hard error in a future release. -[UPDATING] `[..]` index -[UPDATING] serde v0.2.0 -> v0.2.1 +[ERROR] The following required arguments were not provided: + --package [] + +Usage: cargo[EXE] update --package [] --aggressive + +For more information try '--help' ", ) .run(); From c51f8ad083b5ed524dbc17a159aab35f8e2f8292 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 30 Nov 2022 09:08:03 +0800 Subject: [PATCH 3/3] Remove warning for aggressive flag without -p flag Signed-off-by: hi-rustin --- src/bin/cargo/commands/update.rs | 11 ++--- tests/testsuite/update.rs | 79 -------------------------------- 2 files changed, 4 insertions(+), 86 deletions(-) diff --git a/src/bin/cargo/commands/update.rs b/src/bin/cargo/commands/update.rs index 15921e51cb2..da33e8d308d 100644 --- a/src/bin/cargo/commands/update.rs +++ b/src/bin/cargo/commands/update.rs @@ -9,13 +9,10 @@ pub fn cli() -> Command { .arg_quiet() .arg(flag("workspace", "Only update the workspace packages").short('w')) .arg_package_spec_simple("Package to update") - .arg( - flag( - "aggressive", - "Force updating all dependencies of SPEC as well when used with -p", - ) - .requires("package"), - ) + .arg(flag( + "aggressive", + "Force updating all dependencies of SPEC as well when used with -p", + )) .arg_dry_run("Don't actually write the lockfile") .arg( opt( diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index f6e31d01739..1eef64ea3d4 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -427,46 +427,6 @@ fn update_precise_do_not_force_update_deps() { .run(); } -#[cargo_test] -fn update_precise_without_package() { - Package::new("serde", "0.2.0").publish(); - - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [dependencies] - serde = "0.2" - "#, - ) - .file("src/lib.rs", "") - .build(); - - p.cargo("build").run(); - - Package::new("serde", "0.2.1").publish(); - Package::new("serde", "0.3.0").publish(); - - p.cargo("update --precise 0.3.0") - .with_status(1) - .with_stderr( - "\ -[ERROR] The following required arguments were not provided: - --package [] - -Usage: cargo[EXE] update --package [] --precise - -For more information try '--help' -", - ) - .run(); -} - #[cargo_test] fn update_aggressive() { Package::new("log", "0.1.0").publish(); @@ -504,45 +464,6 @@ fn update_aggressive() { .run(); } -#[cargo_test] -fn update_aggressive_without_package() { - Package::new("serde", "0.2.0").publish(); - - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "bar" - version = "0.0.1" - authors = [] - - [dependencies] - serde = "0.2" - "#, - ) - .file("src/lib.rs", "") - .build(); - - p.cargo("build").run(); - - Package::new("serde", "0.2.1").publish(); - - p.cargo("update --aggressive") - .with_status(1) - .with_stderr( - "\ -[ERROR] The following required arguments were not provided: - --package [] - -Usage: cargo[EXE] update --package [] --aggressive - -For more information try '--help' -", - ) - .run(); -} - // cargo update should respect its arguments even without a lockfile. // See issue "Running cargo update without a Cargo.lock ignores arguments" // at .