Skip to content

Commit

Permalink
fix(cargo-update): once warn once for --precise <yanked>
Browse files Browse the repository at this point in the history
This also tweaks the error message a bit.
  • Loading branch information
weihanglo committed Jan 29, 2024
1 parent bc5da43 commit caeaaa5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
21 changes: 14 additions & 7 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ pub struct RegistrySource<'cfg> {
/// Otherwise, the resolver would think that those entries no longer
/// exist, and it would trigger updates to unrelated packages.
yanked_whitelist: HashSet<PackageId>,
/// Yanked versions that have already been selected during queries.
///
/// As of this writing, this is for not emitting the `--precise <yanked>`
/// warning twice, with the assumption of (`dep.package_name()` + `--precise`
/// version) being sufficient to uniquely identify the same query result.
selected_precise_yanked: HashSet<(InternedString, semver::Version)>,
}

/// The [`config.json`] file stored in the index.
Expand Down Expand Up @@ -531,6 +537,7 @@ impl<'cfg> RegistrySource<'cfg> {
index: index::RegistryIndex::new(source_id, ops.index_path(), config),
yanked_whitelist: yanked_whitelist.clone(),
ops,
selected_precise_yanked: HashSet::new(),
}
}

Expand Down Expand Up @@ -812,13 +819,13 @@ impl<'cfg> Source for RegistrySource<'cfg> {
let version = req
.precise_version()
.expect("--precise <yanked-version> in use");
let source = self.source_id();
let mut shell = self.config.shell();
shell.warn(format_args!(
"yanked package `{name}@{version}` is selected by the `--precise` flag from {source}",
))?;
shell.note("it is not recommended to depend on a yanked version")?;
shell.note("if possible, try other SemVer-compatbile versions")?;
if self.selected_precise_yanked.insert((name, version.clone())) {
let mut shell = self.config.shell();
shell.warn(format_args!(
"selected package `{name}@{version}` was yanked by the author"
))?;
shell.note("if possible, try a compatible non-yanked version")?;
}
}
if called {
return Poll::Ready(Ok(()));
Expand Down
13 changes: 4 additions & 9 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,8 @@ Caused by:
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[WARNING] yanked package `[email protected]` is selected by the `--precise` flag from registry `dummy-registry`
[NOTE] it is not recommended to depend on a yanked version
[NOTE] if possible, try other SemVer-compatbile versions
[WARNING] selected package `[email protected]` was yanked by the author
[NOTE] if possible, try a compatible non-yanked version
[UPDATING] bar v0.1.0 -> v0.1.1
",
)
Expand Down Expand Up @@ -1463,12 +1462,8 @@ fn precise_yanked_multiple_presence() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[WARNING] yanked package `[email protected]` is selected by the `--precise` flag from registry `dummy-registry`
[NOTE] it is not recommended to depend on a yanked version
[NOTE] if possible, try other SemVer-compatbile versions
[WARNING] yanked package `[email protected]` is selected by the `--precise` flag from registry `dummy-registry`
[NOTE] it is not recommended to depend on a yanked version
[NOTE] if possible, try other SemVer-compatbile versions
[WARNING] selected package `[email protected]` was yanked by the author
[NOTE] if possible, try a compatible non-yanked version
[UPDATING] bar v0.1.0 -> v0.1.1
",
)
Expand Down

0 comments on commit caeaaa5

Please sign in to comment.