Skip to content

Commit cdb15d6

Browse files
committed
Added QueryKind::Normalized, and used it in cargo-add
1 parent b454b9f commit cdb15d6

File tree

6 files changed

+9
-2
lines changed

6 files changed

+9
-2
lines changed

crates/resolver-tests/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn resolve_with_config_raw(
112112
let matched = match kind {
113113
QueryKind::Exact => dep.matches(summary),
114114
QueryKind::Fuzzy => true,
115+
QueryKind::Normalized => true,
115116
};
116117
if matched {
117118
self.used.insert(summary.package_id());

src/cargo/ops/cargo_add/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ fn select_package(
707707
MaybeWorkspace::Other(query) => {
708708
let possibilities = loop {
709709
// Exact to avoid returning all for path/git
710-
match registry.query_vec(&query, QueryKind::Exact) {
710+
match registry.query_vec(&query, QueryKind::Normalized) {
711711
std::task::Poll::Ready(res) => {
712712
break res?;
713713
}
@@ -934,7 +934,7 @@ fn populate_available_features(
934934
}
935935

936936
let possibilities = loop {
937-
match registry.query_vec(&query, QueryKind::Exact) {
937+
match registry.query_vec(&query, QueryKind::Normalized) {
938938
std::task::Poll::Ready(res) => {
939939
break res?;
940940
}

src/cargo/sources/directory.rs

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl<'cfg> Source for DirectorySource<'cfg> {
109109
let matches = packages.filter(|pkg| match kind {
110110
QueryKind::Exact => dep.matches(pkg.summary()),
111111
QueryKind::Fuzzy => true,
112+
QueryKind::Normalized => dep.matches(pkg.summary()),
112113
});
113114
for summary in matches.map(|pkg| pkg.summary().clone()) {
114115
f(IndexSummary::Candidate(summary));

src/cargo/sources/path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ impl<'cfg> Source for PathSource<'cfg> {
555555
let matched = match kind {
556556
QueryKind::Exact => dep.matches(s),
557557
QueryKind::Fuzzy => true,
558+
QueryKind::Normalized => dep.matches(s),
558559
};
559560
if matched {
560561
f(IndexSummary::Candidate(s.clone()))

src/cargo/sources/registry/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ impl<'cfg> Source for RegistrySource<'cfg> {
782782
let matched = match kind {
783783
QueryKind::Exact => dep.matches(s.as_summary()),
784784
QueryKind::Fuzzy => true,
785+
QueryKind::Normalized => true,
785786
};
786787
// Next filter out all yanked packages. Some yanked packages may
787788
// leak through if they're in a whitelist (aka if they were

src/cargo/sources/source.rs

+3
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ pub enum QueryKind {
180180
/// whereas an `Registry` source may return dependencies that have the same
181181
/// canonicalization.
182182
Fuzzy,
183+
/// Match a denpendency in all ways and will normalize the package name.
184+
/// Each source defines what normalizing means.
185+
Normalized,
183186
}
184187

185188
/// A download status that represents if a [`Package`] has already been

0 commit comments

Comments
 (0)