Skip to content

Commit 7b9069e

Browse files
committed
Auto merge of #11349 - hi-rustin:rustin-patch-error-cli, r=weihanglo
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)`
2 parents d28c9b8 + c51f8ad commit 7b9069e

File tree

3 files changed

+2
-91
lines changed

3 files changed

+2
-91
lines changed

src/bin/cargo/commands/update.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub fn cli() -> Command {
1919
"precise",
2020
"Update a single dependency to exactly PRECISE when used with -p",
2121
)
22-
.value_name("PRECISE"),
22+
.value_name("PRECISE")
23+
.requires("package"),
2324
)
2425
.arg_manifest_path()
2526
.after_help("Run `cargo help update` for more detailed information.\n")

src/cargo/ops/cargo_generate_lockfile.rs

-19
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,6 @@ pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> {
3636
}
3737

3838
pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> {
39-
// Currently this is only a warning, but after a transition period this will become
40-
// a hard error.
41-
// See https://github.com/rust-lang/cargo/issues/10919#issuecomment-1214464756.
42-
// We should declare the `precise` and `aggressive` arguments
43-
// require the `package` argument in the clap.
44-
if opts.aggressive && opts.to_update.is_empty() {
45-
ws.config().shell().warn(
46-
"aggressive is only supported with \"--package <SPEC>\", \
47-
this will become a hard error in a future release.",
48-
)?;
49-
}
50-
51-
if opts.precise.is_some() && opts.to_update.is_empty() {
52-
ws.config().shell().warn(
53-
"precise is only supported with \"--package <SPEC>\", \
54-
this will become a hard error in a future release.",
55-
)?;
56-
}
57-
5839
if opts.aggressive && opts.precise.is_some() {
5940
anyhow::bail!("cannot specify both aggressive and precise simultaneously")
6041
}

tests/testsuite/update.rs

-71
Original file line numberDiff line numberDiff line change
@@ -427,42 +427,6 @@ fn update_precise_do_not_force_update_deps() {
427427
.run();
428428
}
429429

430-
#[cargo_test]
431-
fn update_precise_without_package() {
432-
Package::new("serde", "0.2.0").publish();
433-
434-
let p = project()
435-
.file(
436-
"Cargo.toml",
437-
r#"
438-
[package]
439-
name = "bar"
440-
version = "0.0.1"
441-
authors = []
442-
443-
[dependencies]
444-
serde = "0.2"
445-
"#,
446-
)
447-
.file("src/lib.rs", "")
448-
.build();
449-
450-
p.cargo("build").run();
451-
452-
Package::new("serde", "0.2.1").publish();
453-
Package::new("serde", "0.3.0").publish();
454-
455-
p.cargo("update --precise 0.3.0")
456-
.with_stderr(
457-
"\
458-
[WARNING] precise is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
459-
[UPDATING] `[..]` index
460-
[UPDATING] serde v0.2.0 -> v0.2.1
461-
",
462-
)
463-
.run();
464-
}
465-
466430
#[cargo_test]
467431
fn update_aggressive() {
468432
Package::new("log", "0.1.0").publish();
@@ -500,41 +464,6 @@ fn update_aggressive() {
500464
.run();
501465
}
502466

503-
#[cargo_test]
504-
fn update_aggressive_without_package() {
505-
Package::new("serde", "0.2.0").publish();
506-
507-
let p = project()
508-
.file(
509-
"Cargo.toml",
510-
r#"
511-
[package]
512-
name = "bar"
513-
version = "0.0.1"
514-
authors = []
515-
516-
[dependencies]
517-
serde = "0.2"
518-
"#,
519-
)
520-
.file("src/lib.rs", "")
521-
.build();
522-
523-
p.cargo("build").run();
524-
525-
Package::new("serde", "0.2.1").publish();
526-
527-
p.cargo("update --aggressive")
528-
.with_stderr(
529-
"\
530-
[WARNING] aggressive is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
531-
[UPDATING] `[..]` index
532-
[UPDATING] serde v0.2.0 -> v0.2.1
533-
",
534-
)
535-
.run();
536-
}
537-
538467
// cargo update should respect its arguments even without a lockfile.
539468
// See issue "Running cargo update without a Cargo.lock ignores arguments"
540469
// at <https://github.com/rust-lang/cargo/issues/6872>.

0 commit comments

Comments
 (0)