Skip to content

Commit

Permalink
Rename "explicit" to "crate_prefix".
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 23, 2020
1 parent c8a3db8 commit 8ff130b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/cargo/core/resolver/dep_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn build_requirements<'a, 'b: 'a>(
} else {
for &f in opts.features.features.iter() {
let fv = FeatureValue::new(f);
if fv.is_explicit_crate() {
if fv.has_crate_prefix() {
return Err(ActivateError::Fatal(anyhow::format_err!(
"feature value `{}` is not allowed to use explicit `crate:` syntax",
fv
Expand Down Expand Up @@ -442,12 +442,12 @@ impl Requirements<'_> {
&mut self,
package: InternedString,
feat: InternedString,
explicit: bool,
crate_prefix: bool,
) -> Result<(), RequirementError> {
// If `package` is indeed an optional dependency then we activate the
// feature named `package`, but otherwise if `package` is a required
// dependency then there's no feature associated with it.
if !explicit
if !crate_prefix
&& self
.summary
.dependencies()
Expand Down Expand Up @@ -493,8 +493,8 @@ impl Requirements<'_> {
FeatureValue::CrateFeature {
dep_name,
dep_feature,
explicit,
} => self.require_crate_feature(*dep_name, *dep_feature, *explicit)?,
crate_prefix,
} => self.require_crate_feature(*dep_name, *dep_feature, *crate_prefix)?,
};
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/resolver/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
FeatureValue::CrateFeature {
dep_name,
dep_feature,
explicit,
crate_prefix,
} => {
// Activate a feature within a dependency.
for (dep_pkg_id, deps) in self.deps(pkg_id, for_host) {
Expand All @@ -477,7 +477,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
dep_name: *dep_name,
};
self.activate_fv(pkg_id, &fv, for_host)?;
if !explicit {
if !crate_prefix {
// To retain compatibility with old behavior,
// this also enables a feature of the same
// name.
Expand Down
18 changes: 9 additions & 9 deletions src/cargo/core/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn build_feature_map(
(*feature, fvs)
})
.collect();
let has_namespaced_features = map.values().flatten().any(|fv| fv.is_explicit_crate());
let has_namespaced_features = map.values().flatten().any(|fv| fv.has_crate_prefix());

// Add implicit features for optional dependencies if they weren't
// explicitly listed anywhere.
Expand All @@ -194,7 +194,7 @@ fn build_feature_map(
Crate { dep_name }
| CrateFeature {
dep_name,
explicit: true,
crate_prefix: true,
..
} => Some(*dep_name),
_ => None,
Expand Down Expand Up @@ -340,7 +340,7 @@ pub enum FeatureValue {
dep_feature: InternedString,
/// If this is true, then the feature used the `crate:` prefix, which
/// prevents enabling the feature named `dep_name`.
explicit: bool,
crate_prefix: bool,
},
}

Expand All @@ -350,15 +350,15 @@ impl FeatureValue {
Some(pos) => {
let (dep, dep_feat) = feature.split_at(pos);
let dep_feat = &dep_feat[1..];
let (dep, explicit) = if let Some(dep) = dep.strip_prefix("crate:") {
let (dep, crate_prefix) = if let Some(dep) = dep.strip_prefix("crate:") {
(dep, true)
} else {
(dep, false)
};
FeatureValue::CrateFeature {
dep_name: InternedString::new(dep),
dep_feature: InternedString::new(dep_feat),
explicit,
crate_prefix,
}
}
None if feature.starts_with("crate:") => FeatureValue::Crate {
Expand All @@ -369,8 +369,8 @@ impl FeatureValue {
}

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

Expand All @@ -383,12 +383,12 @@ impl fmt::Display for FeatureValue {
CrateFeature {
dep_name,
dep_feature,
explicit: true,
crate_prefix: true,
} => write!(f, "crate:{}/{}", dep_name, dep_feature),
CrateFeature {
dep_name,
dep_feature,
explicit: false,
crate_prefix: false,
} => write!(f, "{}/{}", dep_name, dep_feature),
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,13 @@ fn validate_required_features(
))?;
}
}
FeatureValue::Crate { .. } | FeatureValue::CrateFeature { explicit: true, .. } => {
FeatureValue::Crate { .. }
| FeatureValue::CrateFeature {
crate_prefix: true, ..
} => {
anyhow::bail!(
"invalid feature `{}` in required-features of target `{}`: \
explicit `crate:` feature values are not allowed in required-features",
`crate:` prefixed feature values are not allowed in required-features",
fv,
target_name
);
Expand All @@ -1083,7 +1086,7 @@ fn validate_required_features(
FeatureValue::CrateFeature {
dep_name,
dep_feature,
explicit: false,
crate_prefix: false,
} => {
match resolve
.deps(summary.package_id())
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/tree/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ fn add_feature_rec(
FeatureValue::CrateFeature {
dep_name,
dep_feature,
explicit,
crate_prefix,
} => {
let dep_indexes = match graph.dep_name_map[&package_index].get(dep_name) {
Some(indexes) => indexes.clone(),
Expand All @@ -585,7 +585,7 @@ fn add_feature_rec(
};
for (dep_index, is_optional) in dep_indexes {
let dep_pkg_id = graph.package_id_for_index(dep_index);
if is_optional && !explicit {
if is_optional && !crate_prefix {
// Activate the optional dep on self.
add_feature(
graph,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ fn crate_required_features() {
"\
[UPDATING] [..]
[ERROR] invalid feature `crate:bar` in required-features of target `foo`: \
explicit `crate:` feature values are not allowed in required-features
`crate:` prefixed feature values are not allowed in required-features
",
)
.run();
Expand Down

0 comments on commit 8ff130b

Please sign in to comment.