Skip to content

Commit 9e1b457

Browse files
committed
Auto merge of #10988 - hi-rustin:rustin-patch-warn, r=epage
Warning when precise or aggressive without -p flag ### What does this PR try to resolve? ref #10919. Warning when precise or aggressive without -p flag. It will be a hard error in future. ### How should we test and review this PR? - Unit test.
2 parents 9809f8f + a58489d commit 9e1b457

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ 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+
3958
if opts.aggressive && opts.precise.is_some() {
4059
anyhow::bail!("cannot specify both aggressive and precise simultaneously")
4160
}

tests/testsuite/update.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,77 @@ fn update_precise() {
392392
.run();
393393
}
394394

395+
#[cargo_test]
396+
fn update_precise_without_package() {
397+
Package::new("serde", "0.2.0").publish();
398+
399+
let p = project()
400+
.file(
401+
"Cargo.toml",
402+
r#"
403+
[package]
404+
name = "bar"
405+
version = "0.0.1"
406+
authors = []
407+
408+
[dependencies]
409+
serde = "0.2"
410+
"#,
411+
)
412+
.file("src/lib.rs", "")
413+
.build();
414+
415+
p.cargo("build").run();
416+
417+
Package::new("serde", "0.2.1").publish();
418+
Package::new("serde", "0.3.0").publish();
419+
420+
p.cargo("update --precise 0.3.0")
421+
.with_stderr(
422+
"\
423+
[WARNING] precise is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
424+
[UPDATING] `[..]` index
425+
[UPDATING] serde v0.2.0 -> v0.2.1
426+
",
427+
)
428+
.run();
429+
}
430+
431+
#[cargo_test]
432+
fn update_aggressive_without_package() {
433+
Package::new("serde", "0.2.0").publish();
434+
435+
let p = project()
436+
.file(
437+
"Cargo.toml",
438+
r#"
439+
[package]
440+
name = "bar"
441+
version = "0.0.1"
442+
authors = []
443+
444+
[dependencies]
445+
serde = "0.2"
446+
"#,
447+
)
448+
.file("src/lib.rs", "")
449+
.build();
450+
451+
p.cargo("build").run();
452+
453+
Package::new("serde", "0.2.1").publish();
454+
455+
p.cargo("update --aggressive")
456+
.with_stderr(
457+
"\
458+
[WARNING] aggressive 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+
395466
// cargo update should respect its arguments even without a lockfile.
396467
// See issue "Running cargo update without a Cargo.lock ignores arguments"
397468
// at <https://github.com/rust-lang/cargo/issues/6872>.

0 commit comments

Comments
 (0)