Skip to content

Commit caeaaa5

Browse files
committed
fix(cargo-update): once warn once for --precise <yanked>
This also tweaks the error message a bit.
1 parent bc5da43 commit caeaaa5

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/cargo/sources/registry/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ pub struct RegistrySource<'cfg> {
261261
/// Otherwise, the resolver would think that those entries no longer
262262
/// exist, and it would trigger updates to unrelated packages.
263263
yanked_whitelist: HashSet<PackageId>,
264+
/// Yanked versions that have already been selected during queries.
265+
///
266+
/// As of this writing, this is for not emitting the `--precise <yanked>`
267+
/// warning twice, with the assumption of (`dep.package_name()` + `--precise`
268+
/// version) being sufficient to uniquely identify the same query result.
269+
selected_precise_yanked: HashSet<(InternedString, semver::Version)>,
264270
}
265271

266272
/// The [`config.json`] file stored in the index.
@@ -531,6 +537,7 @@ impl<'cfg> RegistrySource<'cfg> {
531537
index: index::RegistryIndex::new(source_id, ops.index_path(), config),
532538
yanked_whitelist: yanked_whitelist.clone(),
533539
ops,
540+
selected_precise_yanked: HashSet::new(),
534541
}
535542
}
536543

@@ -812,13 +819,13 @@ impl<'cfg> Source for RegistrySource<'cfg> {
812819
let version = req
813820
.precise_version()
814821
.expect("--precise <yanked-version> in use");
815-
let source = self.source_id();
816-
let mut shell = self.config.shell();
817-
shell.warn(format_args!(
818-
"yanked package `{name}@{version}` is selected by the `--precise` flag from {source}",
819-
))?;
820-
shell.note("it is not recommended to depend on a yanked version")?;
821-
shell.note("if possible, try other SemVer-compatbile versions")?;
822+
if self.selected_precise_yanked.insert((name, version.clone())) {
823+
let mut shell = self.config.shell();
824+
shell.warn(format_args!(
825+
"selected package `{name}@{version}` was yanked by the author"
826+
))?;
827+
shell.note("if possible, try a compatible non-yanked version")?;
828+
}
822829
}
823830
if called {
824831
return Poll::Ready(Ok(()));

tests/testsuite/update.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,9 +1419,8 @@ Caused by:
14191419
.with_stderr(
14201420
"\
14211421
[UPDATING] `dummy-registry` index
1422-
[WARNING] yanked package `bar@0.1.1` is selected by the `--precise` flag from registry `dummy-registry`
1423-
[NOTE] it is not recommended to depend on a yanked version
1424-
[NOTE] if possible, try other SemVer-compatbile versions
1422+
[WARNING] selected package `bar@0.1.1` was yanked by the author
1423+
[NOTE] if possible, try a compatible non-yanked version
14251424
[UPDATING] bar v0.1.0 -> v0.1.1
14261425
",
14271426
)
@@ -1463,12 +1462,8 @@ fn precise_yanked_multiple_presence() {
14631462
.with_stderr(
14641463
"\
14651464
[UPDATING] `dummy-registry` index
1466-
[WARNING] yanked package `bar@0.1.1` is selected by the `--precise` flag from registry `dummy-registry`
1467-
[NOTE] it is not recommended to depend on a yanked version
1468-
[NOTE] if possible, try other SemVer-compatbile versions
1469-
[WARNING] yanked package `bar@0.1.1` is selected by the `--precise` flag from registry `dummy-registry`
1470-
[NOTE] it is not recommended to depend on a yanked version
1471-
[NOTE] if possible, try other SemVer-compatbile versions
1465+
[WARNING] selected package `bar@0.1.1` was yanked by the author
1466+
[NOTE] if possible, try a compatible non-yanked version
14721467
[UPDATING] bar v0.1.0 -> v0.1.1
14731468
",
14741469
)

0 commit comments

Comments
 (0)