Skip to content

Commit 7ec959e

Browse files
authored
fix(resolver): Don't report all versions as rejected (#14921)
### What does this PR try to resolve? When I copy/pasted the alternative-names code in #14897, I didn't notice that the wildcard dependency was used. This includes a rename of the variable to make it stand out more. I also renamed `AlternativeVersions` because there is another check we do that better matches that name, so I renamed it to `RejectedVersions`. ### How should we test and review this PR? This does not have a test yet because overly-constrictive dep specs have higher precedence atm (which is what I was working on when I found this). ### Additional information
2 parents ad5b493 + 3aab145 commit 7ec959e

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

crates/resolver-tests/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn resolve_with_global_context_raw(
143143
for summary in self.list.iter() {
144144
let matched = match kind {
145145
QueryKind::Exact => dep.matches(summary),
146-
QueryKind::AlternativeVersions => dep.matches(summary),
146+
QueryKind::RejectedVersions => dep.matches(summary),
147147
QueryKind::AlternativeNames => true,
148148
QueryKind::Normalized => true,
149149
};

src/cargo/core/resolver/errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ pub(super) fn activation_error(
222222
// Maybe the user mistyped the ver_req? Like `dep="2"` when `dep="0.2"`
223223
// was meant. So we re-query the registry with `dep="*"` so we can
224224
// list a few versions that were actually found.
225-
let mut new_dep = dep.clone();
226-
new_dep.set_version_req(OptVersionReq::Any);
225+
let mut wild_dep = dep.clone();
226+
wild_dep.set_version_req(OptVersionReq::Any);
227227

228228
let candidates = loop {
229-
match registry.query_vec(&new_dep, QueryKind::Exact) {
229+
match registry.query_vec(&wild_dep, QueryKind::Exact) {
230230
Poll::Ready(Ok(candidates)) => break candidates,
231231
Poll::Ready(Err(e)) => return to_resolve_err(e),
232232
Poll::Pending => match registry.block_until_ready() {
@@ -305,7 +305,7 @@ pub(super) fn activation_error(
305305
} else {
306306
// Maybe something is wrong with the available versions
307307
let mut version_candidates = loop {
308-
match registry.query_vec(&new_dep, QueryKind::AlternativeVersions) {
308+
match registry.query_vec(&dep, QueryKind::RejectedVersions) {
309309
Poll::Ready(Ok(candidates)) => break candidates,
310310
Poll::Ready(Err(e)) => return to_resolve_err(e),
311311
Poll::Pending => match registry.block_until_ready() {
@@ -319,7 +319,7 @@ pub(super) fn activation_error(
319319
// Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing`
320320
// was meant. So we try asking the registry for a `fuzzy` search for suggestions.
321321
let name_candidates = loop {
322-
match registry.query_vec(&new_dep, QueryKind::AlternativeNames) {
322+
match registry.query_vec(&wild_dep, QueryKind::AlternativeNames) {
323323
Poll::Ready(Ok(candidates)) => break candidates,
324324
Poll::Ready(Err(e)) => return to_resolve_err(e),
325325
Poll::Pending => match registry.block_until_ready() {
@@ -336,7 +336,7 @@ pub(super) fn activation_error(
336336
name_candidates.dedup_by(|a, b| a.name() == b.name());
337337
let mut name_candidates: Vec<_> = name_candidates
338338
.iter()
339-
.filter_map(|n| Some((edit_distance(&*new_dep.package_name(), &*n.name(), 3)?, n)))
339+
.filter_map(|n| Some((edit_distance(&*wild_dep.package_name(), &*n.name(), 3)?, n)))
340340
.collect();
341341
name_candidates.sort_by_key(|o| o.0);
342342

src/cargo/sources/directory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'gctx> Source for DirectorySource<'gctx> {
108108
}
109109
let packages = self.packages.values().map(|p| &p.0);
110110
let matches = packages.filter(|pkg| match kind {
111-
QueryKind::Exact | QueryKind::AlternativeVersions => dep.matches(pkg.summary()),
111+
QueryKind::Exact | QueryKind::RejectedVersions => dep.matches(pkg.summary()),
112112
QueryKind::AlternativeNames => true,
113113
QueryKind::Normalized => dep.matches(pkg.summary()),
114114
});

src/cargo/sources/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'gctx> Source for PathSource<'gctx> {
145145
self.load()?;
146146
if let Some(s) = self.package.as_ref().map(|p| p.summary()) {
147147
let matched = match kind {
148-
QueryKind::Exact | QueryKind::AlternativeVersions => dep.matches(s),
148+
QueryKind::Exact | QueryKind::RejectedVersions => dep.matches(s),
149149
QueryKind::AlternativeNames => true,
150150
QueryKind::Normalized => dep.matches(s),
151151
};
@@ -332,7 +332,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
332332
.map(|p| p.summary())
333333
{
334334
let matched = match kind {
335-
QueryKind::Exact | QueryKind::AlternativeVersions => dep.matches(s),
335+
QueryKind::Exact | QueryKind::RejectedVersions => dep.matches(s),
336336
QueryKind::AlternativeNames => true,
337337
QueryKind::Normalized => dep.matches(s),
338338
};

src/cargo/sources/registry/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ impl<'gctx> Source for RegistrySource<'gctx> {
799799
.index
800800
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
801801
let matched = match kind {
802-
QueryKind::Exact | QueryKind::AlternativeVersions => {
802+
QueryKind::Exact | QueryKind::RejectedVersions => {
803803
if req.is_precise() && self.gctx.cli_unstable().unstable_options {
804804
dep.matches_prerelease(s.as_summary())
805805
} else {
@@ -816,7 +816,7 @@ impl<'gctx> Source for RegistrySource<'gctx> {
816816
// leak through if they're in a whitelist (aka if they were
817817
// previously in `Cargo.lock`
818818
match s {
819-
s @ _ if kind == QueryKind::AlternativeVersions => callback(s),
819+
s @ _ if kind == QueryKind::RejectedVersions => callback(s),
820820
s @ IndexSummary::Candidate(_) => callback(s),
821821
s @ IndexSummary::Yanked(_) => {
822822
if self.yanked_whitelist.contains(&s.package_id()) {

src/cargo/sources/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub enum QueryKind {
184184
///
185185
/// Path/Git sources may return all dependencies that are at that URI,
186186
/// whereas an `Registry` source may return dependencies that are yanked or invalid.
187-
AlternativeVersions,
187+
RejectedVersions,
188188
/// A query for packages close to the given dependency requirement.
189189
///
190190
/// Each source gets to define what `close` means for it.

0 commit comments

Comments
 (0)