Skip to content

Commit f616aaf

Browse files
committed
fix(resolver): Make features singular; we only track one
1 parent 3fd3656 commit f616aaf

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

src/cargo/core/resolver/dep_cache.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,7 @@ impl RequirementError {
530530
closest
531531
))
532532
}
533-
Some(p) => {
534-
ActivateError::Conflict(p, ConflictReason::MissingFeatures(feat))
535-
}
533+
Some(p) => ActivateError::Conflict(p, ConflictReason::MissingFeature(feat)),
536534
};
537535
}
538536
if deps.iter().any(|dep| dep.is_optional()) {
@@ -595,9 +593,7 @@ help: a depednency with that name exists but it is required dependency and only
595593
)),
596594
// This code path currently isn't used, since `foo/bar`
597595
// and `dep:` syntax is not allowed in a dependency.
598-
Some(p) => {
599-
ActivateError::Conflict(p, ConflictReason::MissingFeatures(dep_name))
600-
}
596+
Some(p) => ActivateError::Conflict(p, ConflictReason::MissingFeature(dep_name)),
601597
}
602598
}
603599
RequirementError::Cycle(feat) => ActivateError::Fatal(anyhow::format_err!(

src/cargo/core/resolver/errors.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub(super) fn activation_error(
137137
has_semver = true;
138138
}
139139
ConflictReason::Links(link) => {
140-
msg.push_str("\n\nthe package `");
140+
msg.push_str("\n\npackage `");
141141
msg.push_str(&*dep.package_name());
142142
msg.push_str("` links to the native library `");
143143
msg.push_str(link);
@@ -150,46 +150,46 @@ pub(super) fn activation_error(
150150
msg.push_str(link);
151151
msg.push_str("\"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.");
152152
}
153-
ConflictReason::MissingFeatures(features) => {
154-
msg.push_str("\n\nthe package `");
153+
ConflictReason::MissingFeature(feature) => {
154+
msg.push_str("\n\npackage `");
155155
msg.push_str(&*p.name());
156156
msg.push_str("` depends on `");
157157
msg.push_str(&*dep.package_name());
158-
msg.push_str("`, with features: `");
159-
msg.push_str(features);
158+
msg.push_str("` with feature `");
159+
msg.push_str(feature);
160160
msg.push_str("` but `");
161161
msg.push_str(&*dep.package_name());
162-
msg.push_str("` does not have these features.\n");
162+
msg.push_str("` does not have that feature.\n");
163163
// p == parent so the full path is redundant.
164164
}
165-
ConflictReason::RequiredDependencyAsFeature(features) => {
166-
msg.push_str("\n\nthe package `");
165+
ConflictReason::RequiredDependencyAsFeature(feature) => {
166+
msg.push_str("\n\npackage `");
167167
msg.push_str(&*p.name());
168168
msg.push_str("` depends on `");
169169
msg.push_str(&*dep.package_name());
170-
msg.push_str("`, with features: `");
171-
msg.push_str(features);
170+
msg.push_str("` with feature `");
171+
msg.push_str(feature);
172172
msg.push_str("` but `");
173173
msg.push_str(&*dep.package_name());
174-
msg.push_str("` does not have these features.\n");
174+
msg.push_str("` does not have that feature.\n");
175175
msg.push_str(
176-
" It has a required dependency with that name, \
176+
" A required dependency with that name exists, \
177177
but only optional dependencies can be used as features.\n",
178178
);
179179
// p == parent so the full path is redundant.
180180
}
181-
ConflictReason::NonImplicitDependencyAsFeature(features) => {
182-
msg.push_str("\n\nthe package `");
181+
ConflictReason::NonImplicitDependencyAsFeature(feature) => {
182+
msg.push_str("\n\npackage `");
183183
msg.push_str(&*p.name());
184184
msg.push_str("` depends on `");
185185
msg.push_str(&*dep.package_name());
186-
msg.push_str("`, with features: `");
187-
msg.push_str(features);
186+
msg.push_str("` with feature `");
187+
msg.push_str(feature);
188188
msg.push_str("` but `");
189189
msg.push_str(&*dep.package_name());
190-
msg.push_str("` does not have these features.\n");
190+
msg.push_str("` does not have that feature.\n");
191191
msg.push_str(
192-
" It has an optional dependency with that name, \
192+
" An optional dependency with that name exists, \
193193
but that dependency uses the \"dep:\" \
194194
syntax in the features table, so it does not have an \
195195
implicit feature with that name.\n",

src/cargo/core/resolver/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ pub enum ConflictReason {
339339
/// we're only allowed one per dependency graph.
340340
Links(InternedString),
341341

342-
/// A dependency listed features that weren't actually available on the
342+
/// A dependency listed a feature that wasn't actually available on the
343343
/// candidate. For example we tried to activate feature `foo` but the
344344
/// candidate we're activating didn't actually have the feature `foo`.
345-
MissingFeatures(InternedString),
345+
MissingFeature(InternedString),
346346

347347
/// A dependency listed a feature that ended up being a required dependency.
348348
/// For example we tried to activate feature `foo` but the
@@ -360,8 +360,8 @@ impl ConflictReason {
360360
matches!(self, ConflictReason::Links(_))
361361
}
362362

363-
pub fn is_missing_features(&self) -> bool {
364-
matches!(self, ConflictReason::MissingFeatures(_))
363+
pub fn is_missing_feature(&self) -> bool {
364+
matches!(self, ConflictReason::MissingFeature(_))
365365
}
366366

367367
pub fn is_required_dependency_as_features(&self) -> bool {

tests/testsuite/build_script.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ fn links_duplicates() {
10321032
... required by package `foo v0.5.0 ([ROOT]/foo)`
10331033
versions that meet the requirements `*` are: 0.5.0
10341034
1035-
the package `a-sys` links to the native library `a`, but it conflicts with a previous package which links to `a` as well:
1035+
package `a-sys` links to the native library `a`, but it conflicts with a previous package which links to `a` as well:
10361036
package `foo v0.5.0 ([ROOT]/foo)`
10371037
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "a"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
10381038
@@ -1159,7 +1159,7 @@ fn links_duplicates_deep_dependency() {
11591159
... which satisfies path dependency `a` of package `foo v0.5.0 ([ROOT]/foo)`
11601160
versions that meet the requirements `*` are: 0.5.0
11611161
1162-
the package `a-sys` links to the native library `a`, but it conflicts with a previous package which links to `a` as well:
1162+
package `a-sys` links to the native library `a`, but it conflicts with a previous package which links to `a` as well:
11631163
package `foo v0.5.0 ([ROOT]/foo)`
11641164
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "a"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
11651165
@@ -4767,7 +4767,7 @@ fn links_duplicates_with_cycle() {
47674767
... required by package `foo v0.5.0 ([ROOT]/foo)`
47684768
versions that meet the requirements `*` are: 0.5.0
47694769
4770-
the package `a` links to the native library `a`, but it conflicts with a previous package which links to `a` as well:
4770+
package `a` links to the native library `a`, but it conflicts with a previous package which links to `a` as well:
47714771
package `foo v0.5.0 ([ROOT]/foo)`
47724772
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "a"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
47734773

tests/testsuite/features.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn dependency_activates_missing_feature() {
219219
... required by package `foo v0.0.1 ([ROOT]/foo)`
220220
versions that meet the requirements `*` are: 0.0.1
221221
222-
the package `foo` depends on `bar`, with features: `bar` but `bar` does not have these features.
222+
package `foo` depends on `bar` with feature `bar` but `bar` does not have that feature.
223223
224224
225225
failed to select a version for `bar` which could resolve this conflict
@@ -279,7 +279,7 @@ fn dependency_activates_typoed_feature() {
279279
... required by package `foo v0.0.1 ([ROOT]/foo)`
280280
versions that meet the requirements `*` are: 0.0.1
281281
282-
the package `foo` depends on `bar`, with features: `bar` but `bar` does not have these features.
282+
package `foo` depends on `bar` with feature `bar` but `bar` does not have that feature.
283283
284284
285285
failed to select a version for `bar` which could resolve this conflict
@@ -499,8 +499,8 @@ fn dependency_activates_required_dependency() {
499499
... required by package `foo v0.0.1 ([ROOT]/foo)`
500500
versions that meet the requirements `*` are: 0.0.1
501501
502-
the package `foo` depends on `bar`, with features: `baz` but `bar` does not have these features.
503-
It has a required dependency with that name, but only optional dependencies can be used as features.
502+
package `foo` depends on `bar` with feature `baz` but `bar` does not have that feature.
503+
A required dependency with that name exists, but only optional dependencies can be used as features.
504504
505505
506506
failed to select a version for `bar` which could resolve this conflict

tests/testsuite/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4007,7 +4007,7 @@ fn cyclical_dep_with_missing_feature() {
40074007
... required by package `foo v0.1.0 ([ROOT]/foo)`
40084008
versions that meet the requirements `*` are: 0.1.0
40094009
4010-
the package `foo` depends on `foo`, with features: `missing` but `foo` does not have these features.
4010+
package `foo` depends on `foo` with feature `missing` but `foo` does not have that feature.
40114011
40124012
40134013
failed to select a version for `foo` which could resolve this conflict

0 commit comments

Comments
 (0)