Skip to content

Commit

Permalink
Auto merge of #11349 - hi-rustin:rustin-patch-error-cli, r=weihanglo
Browse files Browse the repository at this point in the history
Error when precise without -p flag

### What does this PR try to resolve?

close #10919

Follow up #10988, see #10919 (comment)

### How should we test and review this PR?

You can manually build and test it. You can try `cargo update --precise xxx` without -p flag.

### Additional information
It has already been released on stable. `rustc 1.65.0 (897e37553 2022-11-02)`
  • Loading branch information
bors committed Nov 30, 2022
2 parents d28c9b8 + c51f8ad commit 7b9069e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 91 deletions.
3 changes: 2 additions & 1 deletion src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub fn cli() -> Command {
"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")
Expand Down
19 changes: 0 additions & 19 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SPEC>\", \
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 <SPEC>\", \
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")
}
Expand Down
71 changes: 0 additions & 71 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,42 +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_stderr(
"\
[WARNING] precise is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
[UPDATING] `[..]` index
[UPDATING] serde v0.2.0 -> v0.2.1
",
)
.run();
}

#[cargo_test]
fn update_aggressive() {
Package::new("log", "0.1.0").publish();
Expand Down Expand Up @@ -500,41 +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_stderr(
"\
[WARNING] aggressive is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
[UPDATING] `[..]` index
[UPDATING] serde v0.2.0 -> v0.2.1
",
)
.run();
}

// cargo update should respect its arguments even without a lockfile.
// See issue "Running cargo update without a Cargo.lock ignores arguments"
// at <https://github.com/rust-lang/cargo/issues/6872>.
Expand Down

0 comments on commit 7b9069e

Please sign in to comment.