Skip to content

Commit 8ff130b

Browse files
committed
Rename "explicit" to "crate_prefix".
1 parent c8a3db8 commit 8ff130b

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

src/cargo/core/resolver/dep_cache.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ fn build_requirements<'a, 'b: 'a>(
374374
} else {
375375
for &f in opts.features.features.iter() {
376376
let fv = FeatureValue::new(f);
377-
if fv.is_explicit_crate() {
377+
if fv.has_crate_prefix() {
378378
return Err(ActivateError::Fatal(anyhow::format_err!(
379379
"feature value `{}` is not allowed to use explicit `crate:` syntax",
380380
fv
@@ -442,12 +442,12 @@ impl Requirements<'_> {
442442
&mut self,
443443
package: InternedString,
444444
feat: InternedString,
445-
explicit: bool,
445+
crate_prefix: bool,
446446
) -> Result<(), RequirementError> {
447447
// If `package` is indeed an optional dependency then we activate the
448448
// feature named `package`, but otherwise if `package` is a required
449449
// dependency then there's no feature associated with it.
450-
if !explicit
450+
if !crate_prefix
451451
&& self
452452
.summary
453453
.dependencies()
@@ -493,8 +493,8 @@ impl Requirements<'_> {
493493
FeatureValue::CrateFeature {
494494
dep_name,
495495
dep_feature,
496-
explicit,
497-
} => self.require_crate_feature(*dep_name, *dep_feature, *explicit)?,
496+
crate_prefix,
497+
} => self.require_crate_feature(*dep_name, *dep_feature, *crate_prefix)?,
498498
};
499499
Ok(())
500500
}

src/cargo/core/resolver/features.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
463463
FeatureValue::CrateFeature {
464464
dep_name,
465465
dep_feature,
466-
explicit,
466+
crate_prefix,
467467
} => {
468468
// Activate a feature within a dependency.
469469
for (dep_pkg_id, deps) in self.deps(pkg_id, for_host) {
@@ -477,7 +477,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
477477
dep_name: *dep_name,
478478
};
479479
self.activate_fv(pkg_id, &fv, for_host)?;
480-
if !explicit {
480+
if !crate_prefix {
481481
// To retain compatibility with old behavior,
482482
// this also enables a feature of the same
483483
// name.

src/cargo/core/summary.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn build_feature_map(
183183
(*feature, fvs)
184184
})
185185
.collect();
186-
let has_namespaced_features = map.values().flatten().any(|fv| fv.is_explicit_crate());
186+
let has_namespaced_features = map.values().flatten().any(|fv| fv.has_crate_prefix());
187187

188188
// Add implicit features for optional dependencies if they weren't
189189
// explicitly listed anywhere.
@@ -194,7 +194,7 @@ fn build_feature_map(
194194
Crate { dep_name }
195195
| CrateFeature {
196196
dep_name,
197-
explicit: true,
197+
crate_prefix: true,
198198
..
199199
} => Some(*dep_name),
200200
_ => None,
@@ -340,7 +340,7 @@ pub enum FeatureValue {
340340
dep_feature: InternedString,
341341
/// If this is true, then the feature used the `crate:` prefix, which
342342
/// prevents enabling the feature named `dep_name`.
343-
explicit: bool,
343+
crate_prefix: bool,
344344
},
345345
}
346346

@@ -350,15 +350,15 @@ impl FeatureValue {
350350
Some(pos) => {
351351
let (dep, dep_feat) = feature.split_at(pos);
352352
let dep_feat = &dep_feat[1..];
353-
let (dep, explicit) = if let Some(dep) = dep.strip_prefix("crate:") {
353+
let (dep, crate_prefix) = if let Some(dep) = dep.strip_prefix("crate:") {
354354
(dep, true)
355355
} else {
356356
(dep, false)
357357
};
358358
FeatureValue::CrateFeature {
359359
dep_name: InternedString::new(dep),
360360
dep_feature: InternedString::new(dep_feat),
361-
explicit,
361+
crate_prefix,
362362
}
363363
}
364364
None if feature.starts_with("crate:") => FeatureValue::Crate {
@@ -369,8 +369,8 @@ impl FeatureValue {
369369
}
370370

371371
/// Returns `true` if this feature explicitly used `crate:` syntax.
372-
pub fn is_explicit_crate(&self) -> bool {
373-
matches!(self, FeatureValue::Crate{..} | FeatureValue::CrateFeature{explicit:true, ..})
372+
pub fn has_crate_prefix(&self) -> bool {
373+
matches!(self, FeatureValue::Crate{..} | FeatureValue::CrateFeature{crate_prefix:true, ..})
374374
}
375375
}
376376

@@ -383,12 +383,12 @@ impl fmt::Display for FeatureValue {
383383
CrateFeature {
384384
dep_name,
385385
dep_feature,
386-
explicit: true,
386+
crate_prefix: true,
387387
} => write!(f, "crate:{}/{}", dep_name, dep_feature),
388388
CrateFeature {
389389
dep_name,
390390
dep_feature,
391-
explicit: false,
391+
crate_prefix: false,
392392
} => write!(f, "{}/{}", dep_name, dep_feature),
393393
}
394394
}

src/cargo/ops/cargo_compile.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,13 @@ fn validate_required_features(
10711071
))?;
10721072
}
10731073
}
1074-
FeatureValue::Crate { .. } | FeatureValue::CrateFeature { explicit: true, .. } => {
1074+
FeatureValue::Crate { .. }
1075+
| FeatureValue::CrateFeature {
1076+
crate_prefix: true, ..
1077+
} => {
10751078
anyhow::bail!(
10761079
"invalid feature `{}` in required-features of target `{}`: \
1077-
explicit `crate:` feature values are not allowed in required-features",
1080+
`crate:` prefixed feature values are not allowed in required-features",
10781081
fv,
10791082
target_name
10801083
);
@@ -1083,7 +1086,7 @@ fn validate_required_features(
10831086
FeatureValue::CrateFeature {
10841087
dep_name,
10851088
dep_feature,
1086-
explicit: false,
1089+
crate_prefix: false,
10871090
} => {
10881091
match resolve
10891092
.deps(summary.package_id())

src/cargo/ops/tree/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ fn add_feature_rec(
567567
FeatureValue::CrateFeature {
568568
dep_name,
569569
dep_feature,
570-
explicit,
570+
crate_prefix,
571571
} => {
572572
let dep_indexes = match graph.dep_name_map[&package_index].get(dep_name) {
573573
Some(indexes) => indexes.clone(),
@@ -585,7 +585,7 @@ fn add_feature_rec(
585585
};
586586
for (dep_index, is_optional) in dep_indexes {
587587
let dep_pkg_id = graph.package_id_for_index(dep_index);
588-
if is_optional && !explicit {
588+
if is_optional && !crate_prefix {
589589
// Activate the optional dep on self.
590590
add_feature(
591591
graph,

tests/testsuite/features_namespaced.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ fn crate_required_features() {
701701
"\
702702
[UPDATING] [..]
703703
[ERROR] invalid feature `crate:bar` in required-features of target `foo`: \
704-
explicit `crate:` feature values are not allowed in required-features
704+
`crate:` prefixed feature values are not allowed in required-features
705705
",
706706
)
707707
.run();

0 commit comments

Comments
 (0)