Rename crate: to dep:

This commit is contained in:
Eric Huss 2020-10-25 12:51:27 -07:00
parent 8ff130bb28
commit f4ac82a0f5
11 changed files with 129 additions and 124 deletions

View File

@ -42,7 +42,7 @@ Available unstable (nightly-only) flags:
-Z timings -- Display concurrency information -Z timings -- Display concurrency information
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config -Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
-Z terminal-width -- Provide a terminal width to rustc for error truncation -Z terminal-width -- Provide a terminal width to rustc for error truncation
-Z namespaced-features -- Allow features with `crate:` prefix -Z namespaced-features -- Allow features with `dep:` prefix
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'" Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
); );

View File

@ -342,7 +342,7 @@ pub fn resolve_features<'b>(
} }
// This is a special case for command-line `--features // This is a special case for command-line `--features
// crate_name/feat_name` where `crate_name` does not exist. All other // dep_name/feat_name` where `dep_name` does not exist. All other
// validation is done either in `build_requirements` or // validation is done either in `build_requirements` or
// `build_feature_map`. // `build_feature_map`.
for dep_name in reqs.deps.keys() { for dep_name in reqs.deps.keys() {
@ -374,9 +374,9 @@ fn build_requirements<'a, 'b: 'a>(
} else { } else {
for &f in opts.features.features.iter() { for &f in opts.features.features.iter() {
let fv = FeatureValue::new(f); let fv = FeatureValue::new(f);
if fv.has_crate_prefix() { if fv.has_dep_prefix() {
return Err(ActivateError::Fatal(anyhow::format_err!( return Err(ActivateError::Fatal(anyhow::format_err!(
"feature value `{}` is not allowed to use explicit `crate:` syntax", "feature value `{}` is not allowed to use explicit `dep:` syntax",
fv fv
))); )));
} }
@ -438,16 +438,16 @@ impl Requirements<'_> {
self.features self.features
} }
fn require_crate_feature( fn require_dep_feature(
&mut self, &mut self,
package: InternedString, package: InternedString,
feat: InternedString, feat: InternedString,
crate_prefix: bool, dep_prefix: bool,
) -> Result<(), RequirementError> { ) -> Result<(), RequirementError> {
// If `package` is indeed an optional dependency then we activate the // If `package` is indeed an optional dependency then we activate the
// feature named `package`, but otherwise if `package` is a required // feature named `package`, but otherwise if `package` is a required
// dependency then there's no feature associated with it. // dependency then there's no feature associated with it.
if !crate_prefix if !dep_prefix
&& self && self
.summary .summary
.dependencies() .dependencies()
@ -489,12 +489,12 @@ impl Requirements<'_> {
fn require_value(&mut self, fv: &FeatureValue) -> Result<(), RequirementError> { fn require_value(&mut self, fv: &FeatureValue) -> Result<(), RequirementError> {
match fv { match fv {
FeatureValue::Feature(feat) => self.require_feature(*feat)?, FeatureValue::Feature(feat) => self.require_feature(*feat)?,
FeatureValue::Crate { dep_name } => self.require_dependency(*dep_name), FeatureValue::Dep { dep_name } => self.require_dependency(*dep_name),
FeatureValue::CrateFeature { FeatureValue::DepFeature {
dep_name, dep_name,
dep_feature, dep_feature,
crate_prefix, dep_prefix,
} => self.require_crate_feature(*dep_name, *dep_feature, *crate_prefix)?, } => self.require_dep_feature(*dep_name, *dep_feature, *dep_prefix)?,
}; };
Ok(()) Ok(())
} }
@ -526,7 +526,7 @@ impl RequirementError {
match parent { match parent {
None => ActivateError::Fatal(anyhow::format_err!( None => ActivateError::Fatal(anyhow::format_err!(
"Package `{}` does not have feature `{}`. It has an optional dependency \ "Package `{}` does not have feature `{}`. It has an optional dependency \
with that name, but that dependency uses the \"crate:\" \ with that name, but that dependency uses the \"dep:\" \
syntax in the features table, so it does not have an implicit feature with that name.", syntax in the features table, so it does not have an implicit feature with that name.",
summary.package_id(), summary.package_id(),
feat feat
@ -559,7 +559,7 @@ impl RequirementError {
dep_name dep_name
)), )),
// This code path currently isn't used, since `foo/bar` // This code path currently isn't used, since `foo/bar`
// and `crate:` syntax is not allowed in a dependency. // and `dep:` syntax is not allowed in a dependency.
Some(p) => ActivateError::Conflict( Some(p) => ActivateError::Conflict(
p, p,
ConflictReason::MissingFeatures(dep_name.to_string()), ConflictReason::MissingFeatures(dep_name.to_string()),

View File

@ -170,7 +170,7 @@ pub(super) fn activation_error(
msg.push_str("` does not have these features.\n"); msg.push_str("` does not have these features.\n");
msg.push_str( msg.push_str(
" It has an optional dependency with that name, \ " It has an optional dependency with that name, \
but but that dependency uses the \"crate:\" \ but but that dependency uses the \"dep:\" \
syntax in the features table, so it does not have an \ syntax in the features table, so it does not have an \
implicit feature with that name.\n", implicit feature with that name.\n",
); );

View File

@ -412,7 +412,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
// For example, consider we've already processed our dependencies, // For example, consider we've already processed our dependencies,
// and another package comes along and enables one of our optional // and another package comes along and enables one of our optional
// dependencies, it will do so immediately in the // dependencies, it will do so immediately in the
// `FeatureValue::CrateFeature` branch, and then immediately // `FeatureValue::DepFeature` branch, and then immediately
// recurse into that optional dependency. This also holds true for // recurse into that optional dependency. This also holds true for
// features that enable other features. // features that enable other features.
return Ok(()); return Ok(());
@ -443,7 +443,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
FeatureValue::Feature(f) => { FeatureValue::Feature(f) => {
self.activate_rec(pkg_id, *f, for_host)?; self.activate_rec(pkg_id, *f, for_host)?;
} }
FeatureValue::Crate { dep_name } => { FeatureValue::Dep { dep_name } => {
// Mark this dependency as activated. // Mark this dependency as activated.
self.activated_dependencies self.activated_dependencies
.entry((pkg_id, self.opts.decouple_host_deps && for_host)) .entry((pkg_id, self.opts.decouple_host_deps && for_host))
@ -460,10 +460,10 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
} }
} }
} }
FeatureValue::CrateFeature { FeatureValue::DepFeature {
dep_name, dep_name,
dep_feature, dep_feature,
crate_prefix, dep_prefix,
} => { } => {
// Activate a feature within a dependency. // Activate a feature within a dependency.
for (dep_pkg_id, deps) in self.deps(pkg_id, for_host) { for (dep_pkg_id, deps) in self.deps(pkg_id, for_host) {
@ -472,12 +472,12 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
continue; continue;
} }
if dep.is_optional() { if dep.is_optional() {
// Activate the crate on self. // Activate the dependency on self.
let fv = FeatureValue::Crate { let fv = FeatureValue::Dep {
dep_name: *dep_name, dep_name: *dep_name,
}; };
self.activate_fv(pkg_id, &fv, for_host)?; self.activate_fv(pkg_id, &fv, for_host)?;
if !crate_prefix { if !dep_prefix {
// To retain compatibility with old behavior, // To retain compatibility with old behavior,
// this also enables a feature of the same // this also enables a feature of the same
// name. // name.

View File

@ -297,7 +297,7 @@ pub enum ConflictReason {
RequiredDependencyAsFeature(InternedString), RequiredDependencyAsFeature(InternedString),
/// A dependency listed a feature for an optional dependency, but that /// A dependency listed a feature for an optional dependency, but that
/// optional dependency is "hidden" using namespaced `crate:` syntax. /// optional dependency is "hidden" using namespaced `dep:` syntax.
NonImplicitDependencyAsFeature(InternedString), NonImplicitDependencyAsFeature(InternedString),
// TODO: needs more info for `activation_error` // TODO: needs more info for `activation_error`

View File

@ -88,7 +88,7 @@ impl Summary {
if !namespaced_features { if !namespaced_features {
if self.inner.has_namespaced_features { if self.inner.has_namespaced_features {
bail!( bail!(
"namespaced features with the `crate:` prefix are only allowed on \ "namespaced features with the `dep:` prefix are only allowed on \
the nightly channel and requires the `-Z namespaced-features` flag on the command-line" the nightly channel and requires the `-Z namespaced-features` flag on the command-line"
); );
} }
@ -158,7 +158,7 @@ impl Hash for Summary {
/// and creates FeatureValues for each feature. /// and creates FeatureValues for each feature.
/// ///
/// The returned `bool` indicates whether or not the `[features]` table /// The returned `bool` indicates whether or not the `[features]` table
/// included a `crate:` prefixed namespaced feature (used for gating on /// included a `dep:` prefixed namespaced feature (used for gating on
/// nightly). /// nightly).
fn build_feature_map( fn build_feature_map(
features: &BTreeMap<InternedString, Vec<InternedString>>, features: &BTreeMap<InternedString, Vec<InternedString>>,
@ -183,7 +183,7 @@ fn build_feature_map(
(*feature, fvs) (*feature, fvs)
}) })
.collect(); .collect();
let has_namespaced_features = map.values().flatten().any(|fv| fv.has_crate_prefix()); let has_namespaced_features = map.values().flatten().any(|fv| fv.has_dep_prefix());
// Add implicit features for optional dependencies if they weren't // Add implicit features for optional dependencies if they weren't
// explicitly listed anywhere. // explicitly listed anywhere.
@ -191,10 +191,10 @@ fn build_feature_map(
.values() .values()
.flatten() .flatten()
.filter_map(|fv| match fv { .filter_map(|fv| match fv {
Crate { dep_name } Dep { dep_name }
| CrateFeature { | DepFeature {
dep_name, dep_name,
crate_prefix: true, dep_prefix: true,
.. ..
} => Some(*dep_name), } => Some(*dep_name),
_ => None, _ => None,
@ -209,7 +209,7 @@ fn build_feature_map(
{ {
continue; continue;
} }
let fv = Crate { let fv = Dep {
dep_name: dep_name_in_toml, dep_name: dep_name_in_toml,
}; };
map.insert(dep_name_in_toml, vec![fv]); map.insert(dep_name_in_toml, vec![fv]);
@ -217,9 +217,9 @@ fn build_feature_map(
// Validate features are listed properly. // Validate features are listed properly.
for (feature, fvs) in &map { for (feature, fvs) in &map {
if feature.starts_with("crate:") { if feature.starts_with("dep:") {
bail!( bail!(
"feature named `{}` is not allowed to start with `crate:`", "feature named `{}` is not allowed to start with `dep:`",
feature feature
); );
} }
@ -227,7 +227,7 @@ fn build_feature_map(
// Find data for the referenced dependency... // Find data for the referenced dependency...
let dep_data = { let dep_data = {
match fv { match fv {
Feature(dep_name) | Crate { dep_name, .. } | CrateFeature { dep_name, .. } => { Feature(dep_name) | Dep { dep_name, .. } | DepFeature { dep_name, .. } => {
dep_map.get(dep_name) dep_map.get(dep_name)
} }
} }
@ -253,7 +253,7 @@ fn build_feature_map(
bail!( bail!(
"feature `{}` includes `{}`, but `{}` is an \ "feature `{}` includes `{}`, but `{}` is an \
optional dependency without an implicit feature\n\ optional dependency without an implicit feature\n\
Use `crate:{}` to enable the dependency.", Use `dep:{}` to enable the dependency.",
feature, feature,
fv, fv,
f, f,
@ -268,7 +268,7 @@ fn build_feature_map(
} }
} }
} }
Crate { dep_name } => { Dep { dep_name } => {
if !is_any_dep { if !is_any_dep {
bail!( bail!(
"feature `{}` includes `{}`, but `{}` is not listed as a dependency", "feature `{}` includes `{}`, but `{}` is not listed as a dependency",
@ -288,7 +288,7 @@ fn build_feature_map(
); );
} }
} }
CrateFeature { dep_name, .. } => { DepFeature { dep_name, .. } => {
// Validation of the feature name will be performed in the resolver. // Validation of the feature name will be performed in the resolver.
if !is_any_dep { if !is_any_dep {
bail!( bail!(
@ -308,7 +308,7 @@ fn build_feature_map(
.values() .values()
.flatten() .flatten()
.filter_map(|fv| match fv { .filter_map(|fv| match fv {
Crate { dep_name } | CrateFeature { dep_name, .. } => Some(dep_name), Dep { dep_name } | DepFeature { dep_name, .. } => Some(dep_name),
_ => None, _ => None,
}) })
.collect(); .collect();
@ -318,7 +318,7 @@ fn build_feature_map(
{ {
bail!( bail!(
"optional dependency `{}` is not included in any feature\n\ "optional dependency `{}` is not included in any feature\n\
Make sure that `crate:{}` is included in one of features in the [features] table.", Make sure that `dep:{}` is included in one of features in the [features] table.",
dep.name_in_toml(), dep.name_in_toml(),
dep.name_in_toml(), dep.name_in_toml(),
); );
@ -332,15 +332,15 @@ fn build_feature_map(
pub enum FeatureValue { pub enum FeatureValue {
/// A feature enabling another feature. /// A feature enabling another feature.
Feature(InternedString), Feature(InternedString),
/// A feature enabling a dependency with `crate:dep_name` syntax. /// A feature enabling a dependency with `dep:dep_name` syntax.
Crate { dep_name: InternedString }, Dep { dep_name: InternedString },
/// A feature enabling a feature on a dependency with `crate_name/feat_name` syntax. /// A feature enabling a feature on a dependency with `crate_name/feat_name` syntax.
CrateFeature { DepFeature {
dep_name: InternedString, dep_name: InternedString,
dep_feature: InternedString, dep_feature: InternedString,
/// If this is true, then the feature used the `crate:` prefix, which /// If this is true, then the feature used the `dep:` prefix, which
/// prevents enabling the feature named `dep_name`. /// prevents enabling the feature named `dep_name`.
crate_prefix: bool, dep_prefix: bool,
}, },
} }
@ -350,27 +350,32 @@ impl FeatureValue {
Some(pos) => { Some(pos) => {
let (dep, dep_feat) = feature.split_at(pos); let (dep, dep_feat) = feature.split_at(pos);
let dep_feat = &dep_feat[1..]; let dep_feat = &dep_feat[1..];
let (dep, crate_prefix) = if let Some(dep) = dep.strip_prefix("crate:") { let (dep, dep_prefix) = if let Some(dep) = dep.strip_prefix("dep:") {
(dep, true) (dep, true)
} else { } else {
(dep, false) (dep, false)
}; };
FeatureValue::CrateFeature { FeatureValue::DepFeature {
dep_name: InternedString::new(dep), dep_name: InternedString::new(dep),
dep_feature: InternedString::new(dep_feat), dep_feature: InternedString::new(dep_feat),
crate_prefix, dep_prefix,
}
}
None => {
if let Some(dep_name) = feature.strip_prefix("dep:") {
FeatureValue::Dep {
dep_name: InternedString::new(dep_name),
}
} else {
FeatureValue::Feature(feature)
} }
} }
None if feature.starts_with("crate:") => FeatureValue::Crate {
dep_name: InternedString::new(&feature[6..]),
},
None => FeatureValue::Feature(feature),
} }
} }
/// Returns `true` if this feature explicitly used `crate:` syntax. /// Returns `true` if this feature explicitly used `dep:` syntax.
pub fn has_crate_prefix(&self) -> bool { pub fn has_dep_prefix(&self) -> bool {
matches!(self, FeatureValue::Crate{..} | FeatureValue::CrateFeature{crate_prefix:true, ..}) matches!(self, FeatureValue::Dep{..} | FeatureValue::DepFeature{dep_prefix:true, ..})
} }
} }
@ -379,16 +384,16 @@ impl fmt::Display for FeatureValue {
use self::FeatureValue::*; use self::FeatureValue::*;
match self { match self {
Feature(feat) => write!(f, "{}", feat), Feature(feat) => write!(f, "{}", feat),
Crate { dep_name } => write!(f, "crate:{}", dep_name), Dep { dep_name } => write!(f, "dep:{}", dep_name),
CrateFeature { DepFeature {
dep_name, dep_name,
dep_feature, dep_feature,
crate_prefix: true, dep_prefix: true,
} => write!(f, "crate:{}/{}", dep_name, dep_feature), } => write!(f, "dep:{}/{}", dep_name, dep_feature),
CrateFeature { DepFeature {
dep_name, dep_name,
dep_feature, dep_feature,
crate_prefix: false, dep_prefix: false,
} => write!(f, "{}/{}", dep_name, dep_feature), } => write!(f, "{}/{}", dep_name, dep_feature),
} }
} }

View File

@ -1071,22 +1071,22 @@ fn validate_required_features(
))?; ))?;
} }
} }
FeatureValue::Crate { .. } FeatureValue::Dep { .. }
| FeatureValue::CrateFeature { | FeatureValue::DepFeature {
crate_prefix: true, .. dep_prefix: true, ..
} => { } => {
anyhow::bail!( anyhow::bail!(
"invalid feature `{}` in required-features of target `{}`: \ "invalid feature `{}` in required-features of target `{}`: \
`crate:` prefixed feature values are not allowed in required-features", `dep:` prefixed feature values are not allowed in required-features",
fv, fv,
target_name target_name
); );
} }
// Handling of dependent_crate/dependent_crate_feature syntax // Handling of dependent_crate/dependent_crate_feature syntax
FeatureValue::CrateFeature { FeatureValue::DepFeature {
dep_name, dep_name,
dep_feature, dep_feature,
crate_prefix: false, dep_prefix: false,
} => { } => {
match resolve match resolve
.deps(summary.package_id()) .deps(summary.package_id())

View File

@ -563,11 +563,11 @@ fn add_feature_rec(
package_index, package_index,
); );
} }
FeatureValue::Crate { .. } => {} FeatureValue::Dep { .. } => {}
FeatureValue::CrateFeature { FeatureValue::DepFeature {
dep_name, dep_name,
dep_feature, dep_feature,
crate_prefix, dep_prefix,
} => { } => {
let dep_indexes = match graph.dep_name_map[&package_index].get(dep_name) { let dep_indexes = match graph.dep_name_map[&package_index].get(dep_name) {
Some(indexes) => indexes.clone(), Some(indexes) => indexes.clone(),
@ -585,7 +585,7 @@ fn add_feature_rec(
}; };
for (dep_index, is_optional) in dep_indexes { for (dep_index, is_optional) in dep_indexes {
let dep_pkg_id = graph.package_id_for_index(dep_index); let dep_pkg_id = graph.package_id_for_index(dep_index);
if is_optional && !crate_prefix { if is_optional && !dep_prefix {
// Activate the optional dep on self. // Activate the optional dep on self.
add_feature( add_feature(
graph, graph,

View File

@ -20,7 +20,7 @@ use std::mem;
use std::path::Path; use std::path::Path;
use std::str; use std::str;
fn make_crate_prefix(name: &str) -> String { fn make_dep_prefix(name: &str) -> String {
match name.len() { match name.len() {
1 => String::from("1"), 1 => String::from("1"),
2 => String::from("2"), 2 => String::from("2"),
@ -274,7 +274,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
{ {
write!(url, "/{}/{}/download", CRATE_TEMPLATE, VERSION_TEMPLATE).unwrap(); write!(url, "/{}/{}/download", CRATE_TEMPLATE, VERSION_TEMPLATE).unwrap();
} }
let prefix = make_crate_prefix(&*pkg.name()); let prefix = make_dep_prefix(&*pkg.name());
let url = url let url = url
.replace(CRATE_TEMPLATE, &*pkg.name()) .replace(CRATE_TEMPLATE, &*pkg.name())
.replace(VERSION_TEMPLATE, &pkg.version().to_string()) .replace(VERSION_TEMPLATE, &pkg.version().to_string())
@ -341,15 +341,15 @@ impl<'cfg> Drop for RemoteRegistry<'cfg> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::make_crate_prefix; use super::make_dep_prefix;
#[test] #[test]
fn crate_prefix() { fn dep_prefix() {
assert_eq!(make_crate_prefix("a"), "1"); assert_eq!(make_dep_prefix("a"), "1");
assert_eq!(make_crate_prefix("ab"), "2"); assert_eq!(make_dep_prefix("ab"), "2");
assert_eq!(make_crate_prefix("abc"), "3/a"); assert_eq!(make_dep_prefix("abc"), "3/a");
assert_eq!(make_crate_prefix("Abc"), "3/A"); assert_eq!(make_dep_prefix("Abc"), "3/A");
assert_eq!(make_crate_prefix("AbCd"), "Ab/Cd"); assert_eq!(make_dep_prefix("AbCd"), "Ab/Cd");
assert_eq!(make_crate_prefix("aBcDe"), "aB/cD"); assert_eq!(make_dep_prefix("aBcDe"), "aB/cD");
} }
} }

View File

@ -196,11 +196,11 @@ specified:
* Features may now be defined with the same name as a dependency. * Features may now be defined with the same name as a dependency.
* Optional dependencies can be explicitly enabled in the `[features]` table * Optional dependencies can be explicitly enabled in the `[features]` table
with the `crate:` prefix, which enables the dependency without enabling a with the `dep:` prefix, which enables the dependency without enabling a
feature of the same name. feature of the same name.
By default, an optional dependency `foo` will define a feature `foo = By default, an optional dependency `foo` will define a feature `foo =
["crate:foo"]` *unless* `crate:foo` is mentioned in any other feature, or the ["dep:foo"]` *unless* `dep:foo` is mentioned in any other feature, or the
`foo` feature is already defined. This helps prevent unnecessary boilerplate `foo` feature is already defined. This helps prevent unnecessary boilerplate
of listing every optional dependency, but still allows you to override the of listing every optional dependency, but still allows you to override the
implicit feature. implicit feature.
@ -223,7 +223,7 @@ regex = { version = "1.4.1", optional = true }
lazy_static = { version = "1.4.0", optional = true } lazy_static = { version = "1.4.0", optional = true }
[features] [features]
regex = ["crate:regex", "crate:lazy_static"] regex = ["dep:regex", "dep:lazy_static"]
``` ```
In this example, the "regex" feature enables both `regex` and `lazy_static`. In this example, the "regex" feature enables both `regex` and `lazy_static`.
@ -240,7 +240,7 @@ num-bigint = "0.2"
serde = {version = "1.0", optional = true } serde = {version = "1.0", optional = true }
[features] [features]
serde = ["crate:serde", "bigdecimal/serde", "chrono/serde", "num-bigint/serde"] serde = ["dep:serde", "bigdecimal/serde", "chrono/serde", "num-bigint/serde"]
``` ```
In this case, `serde` is a natural name to use for a feature, because it is In this case, `serde` is a natural name to use for a feature, because it is

View File

@ -5,7 +5,7 @@ use cargo_test_support::registry::{Dependency, Package};
#[cargo_test] #[cargo_test]
fn gated() { fn gated() {
// Need namespaced-features to use `crate:` syntax. // Need namespaced-features to use `dep:` syntax.
Package::new("bar", "1.0.0").publish(); Package::new("bar", "1.0.0").publish();
let p = project() let p = project()
.file( .file(
@ -19,7 +19,7 @@ fn gated() {
bar = { version = "1.0", optional = true } bar = { version = "1.0", optional = true }
[features] [features]
foo = ["crate:bar"] foo = ["dep:bar"]
"#, "#,
) )
.file("src/lib.rs", "") .file("src/lib.rs", "")
@ -32,7 +32,7 @@ fn gated() {
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml` [ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
Caused by: Caused by:
namespaced features with the `crate:` prefix are only allowed on the nightly channel \ namespaced features with the `dep:` prefix are only allowed on the nightly channel \
and requires the `-Z namespaced-features` flag on the command-line and requires the `-Z namespaced-features` flag on the command-line
", ",
) )
@ -41,11 +41,11 @@ Caused by:
#[cargo_test] #[cargo_test]
fn dependency_gate_ignored() { fn dependency_gate_ignored() {
// Dependencies with `crate:` features are ignored in the registry if not on nightly. // Dependencies with `dep:` features are ignored in the registry if not on nightly.
Package::new("baz", "1.0.0").publish(); Package::new("baz", "1.0.0").publish();
Package::new("bar", "1.0.0") Package::new("bar", "1.0.0")
.add_dep(Dependency::new("baz", "1.0").optional(true)) .add_dep(Dependency::new("baz", "1.0").optional(true))
.feature("feat", &["crate:baz"]) .feature("feat", &["dep:baz"])
.publish(); .publish();
let p = project() let p = project()
.file( .file(
@ -98,11 +98,11 @@ required by package `foo v0.1.0 ([..]/foo)`
#[cargo_test] #[cargo_test]
fn dependency_with_crate_syntax() { fn dependency_with_crate_syntax() {
// Registry dependency uses crate: syntax. // Registry dependency uses dep: syntax.
Package::new("baz", "1.0.0").publish(); Package::new("baz", "1.0.0").publish();
Package::new("bar", "1.0.0") Package::new("bar", "1.0.0")
.add_dep(Dependency::new("baz", "1.0").optional(true)) .add_dep(Dependency::new("baz", "1.0").optional(true))
.feature("feat", &["crate:baz"]) .feature("feat", &["dep:baz"])
.publish(); .publish();
let p = project() let p = project()
.file( .file(
@ -171,7 +171,7 @@ Caused by:
#[cargo_test] #[cargo_test]
fn namespaced_invalid_dependency() { fn namespaced_invalid_dependency() {
// Specifies a crate:name that doesn't exist. // Specifies a dep:name that doesn't exist.
let p = project() let p = project()
.file( .file(
"Cargo.toml", "Cargo.toml",
@ -181,7 +181,7 @@ fn namespaced_invalid_dependency() {
version = "0.0.1" version = "0.0.1"
[features] [features]
bar = ["crate:baz"] bar = ["dep:baz"]
"#, "#,
) )
.file("src/main.rs", "") .file("src/main.rs", "")
@ -195,7 +195,7 @@ fn namespaced_invalid_dependency() {
[ERROR] failed to parse manifest at `[..]` [ERROR] failed to parse manifest at `[..]`
Caused by: Caused by:
feature `bar` includes `crate:baz`, but `baz` is not listed as a dependency feature `bar` includes `dep:baz`, but `baz` is not listed as a dependency
", ",
) )
.run(); .run();
@ -203,7 +203,7 @@ Caused by:
#[cargo_test] #[cargo_test]
fn namespaced_non_optional_dependency() { fn namespaced_non_optional_dependency() {
// Specifies a crate:name for a dependency that is not optional. // Specifies a dep:name for a dependency that is not optional.
let p = project() let p = project()
.file( .file(
"Cargo.toml", "Cargo.toml",
@ -213,7 +213,7 @@ fn namespaced_non_optional_dependency() {
version = "0.0.1" version = "0.0.1"
[features] [features]
bar = ["crate:baz"] bar = ["dep:baz"]
[dependencies] [dependencies]
baz = "0.1" baz = "0.1"
@ -230,7 +230,7 @@ fn namespaced_non_optional_dependency() {
[ERROR] failed to parse manifest at `[..]` [ERROR] failed to parse manifest at `[..]`
Caused by: Caused by:
feature `bar` includes `crate:baz`, but `baz` is not an optional dependency feature `bar` includes `dep:baz`, but `baz` is not an optional dependency
A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition. A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition.
", ",
) )
@ -315,7 +315,7 @@ fn namespaced_shadowed_dep() {
Caused by: Caused by:
optional dependency `baz` is not included in any feature optional dependency `baz` is not included in any feature
Make sure that `crate:baz` is included in one of features in the [features] table. Make sure that `dep:baz` is included in one of features in the [features] table.
", ",
) )
.run(); .run();
@ -394,7 +394,7 @@ fn namespaced_same_name() {
version = "0.0.1" version = "0.0.1"
[features] [features]
baz = ["crate:baz"] baz = ["dep:baz"]
[dependencies] [dependencies]
baz = { version = "0.1", optional = true } baz = { version = "0.1", optional = true }
@ -441,7 +441,7 @@ fn namespaced_same_name() {
#[cargo_test] #[cargo_test]
fn no_implicit_feature() { fn no_implicit_feature() {
// Using `crate:` will not create an implicit feature. // Using `dep:` will not create an implicit feature.
Package::new("regex", "1.0.0").publish(); Package::new("regex", "1.0.0").publish();
Package::new("lazy_static", "1.0.0").publish(); Package::new("lazy_static", "1.0.0").publish();
@ -458,7 +458,7 @@ fn no_implicit_feature() {
lazy_static = { version = "1.0", optional = true } lazy_static = { version = "1.0", optional = true }
[features] [features]
regex = ["crate:regex", "crate:lazy_static"] regex = ["dep:regex", "dep:lazy_static"]
"#, "#,
) )
.file( .file(
@ -507,7 +507,7 @@ fn no_implicit_feature() {
.with_stderr( .with_stderr(
"\ "\
[ERROR] Package `foo v0.1.0 [..]` does not have feature `lazy_static`. \ [ERROR] Package `foo v0.1.0 [..]` does not have feature `lazy_static`. \
It has an optional dependency with that name, but that dependency uses the \"crate:\" \ It has an optional dependency with that name, but that dependency uses the \"dep:\" \
syntax in the features table, so it does not have an implicit feature with that name. syntax in the features table, so it does not have an implicit feature with that name.
", ",
) )
@ -517,7 +517,7 @@ syntax in the features table, so it does not have an implicit feature with that
#[cargo_test] #[cargo_test]
fn crate_feature_explicit() { fn crate_feature_explicit() {
// crate:name/feature syntax shouldn't set implicit feature. // dep:name/feature syntax shouldn't set implicit feature.
Package::new("bar", "1.0.0") Package::new("bar", "1.0.0")
.file( .file(
"src/lib.rs", "src/lib.rs",
@ -540,7 +540,7 @@ fn crate_feature_explicit() {
bar = {version = "1.0", optional=true} bar = {version = "1.0", optional=true}
[features] [features]
f1 = ["crate:bar/feat"] f1 = ["dep:bar/feat"]
"#, "#,
) )
.file( .file(
@ -572,7 +572,7 @@ fn crate_feature_explicit() {
#[cargo_test] #[cargo_test]
fn crate_syntax_bad_name() { fn crate_syntax_bad_name() {
// "crate:bar" = [] // "dep:bar" = []
Package::new("bar", "1.0.0").publish(); Package::new("bar", "1.0.0").publish();
let p = project() let p = project()
.file( .file(
@ -586,13 +586,13 @@ fn crate_syntax_bad_name() {
bar = { version="1.0", optional=true } bar = { version="1.0", optional=true }
[features] [features]
"crate:bar" = [] "dep:bar" = []
"#, "#,
) )
.file("src/lib.rs", "") .file("src/lib.rs", "")
.build(); .build();
p.cargo("check -Z namespaced-features --features crate:bar") p.cargo("check -Z namespaced-features --features dep:bar")
.masquerade_as_nightly_cargo() .masquerade_as_nightly_cargo()
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
@ -600,7 +600,7 @@ fn crate_syntax_bad_name() {
[ERROR] failed to parse manifest at [..]/foo/Cargo.toml` [ERROR] failed to parse manifest at [..]/foo/Cargo.toml`
Caused by: Caused by:
feature named `crate:bar` is not allowed to start with `crate:` feature named `dep:bar` is not allowed to start with `dep:`
", ",
) )
.run(); .run();
@ -608,7 +608,7 @@ Caused by:
#[cargo_test] #[cargo_test]
fn crate_syntax_in_dep() { fn crate_syntax_in_dep() {
// features = ["crate:baz"] // features = ["dep:baz"]
Package::new("baz", "1.0.0").publish(); Package::new("baz", "1.0.0").publish();
Package::new("bar", "1.0.0") Package::new("bar", "1.0.0")
.add_dep(Dependency::new("baz", "1.0").optional(true)) .add_dep(Dependency::new("baz", "1.0").optional(true))
@ -622,7 +622,7 @@ fn crate_syntax_in_dep() {
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
bar = { version = "1.0", features = ["crate:baz"] } bar = { version = "1.0", features = ["dep:baz"] }
"#, "#,
) )
.file("src/lib.rs", "") .file("src/lib.rs", "")
@ -634,7 +634,7 @@ fn crate_syntax_in_dep() {
.with_stderr( .with_stderr(
"\ "\
[UPDATING] [..] [UPDATING] [..]
[ERROR] feature value `crate:baz` is not allowed to use explicit `crate:` syntax [ERROR] feature value `dep:baz` is not allowed to use explicit `dep:` syntax
", ",
) )
.run(); .run();
@ -642,7 +642,7 @@ fn crate_syntax_in_dep() {
#[cargo_test] #[cargo_test]
fn crate_syntax_cli() { fn crate_syntax_cli() {
// --features crate:bar // --features dep:bar
Package::new("bar", "1.0.0").publish(); Package::new("bar", "1.0.0").publish();
let p = project() let p = project()
.file( .file(
@ -659,13 +659,13 @@ fn crate_syntax_cli() {
.file("src/lib.rs", "") .file("src/lib.rs", "")
.build(); .build();
p.cargo("check -Z namespaced-features --features crate:bar") p.cargo("check -Z namespaced-features --features dep:bar")
.masquerade_as_nightly_cargo() .masquerade_as_nightly_cargo()
.with_status(101) .with_status(101)
.with_stderr( .with_stderr(
"\ "\
[UPDATING] [..] [UPDATING] [..]
[ERROR] feature value `crate:bar` is not allowed to use explicit `crate:` syntax [ERROR] feature value `dep:bar` is not allowed to use explicit `dep:` syntax
", ",
) )
.run(); .run();
@ -673,7 +673,7 @@ fn crate_syntax_cli() {
#[cargo_test] #[cargo_test]
fn crate_required_features() { fn crate_required_features() {
// required-features = ["crate:bar"] // required-features = ["dep:bar"]
Package::new("bar", "1.0.0").publish(); Package::new("bar", "1.0.0").publish();
let p = project() let p = project()
.file( .file(
@ -688,7 +688,7 @@ fn crate_required_features() {
[[bin]] [[bin]]
name = "foo" name = "foo"
required-features = ["crate:bar"] required-features = ["dep:bar"]
"#, "#,
) )
.file("src/main.rs", "fn main() {}") .file("src/main.rs", "fn main() {}")
@ -700,8 +700,8 @@ fn crate_required_features() {
.with_stderr( .with_stderr(
"\ "\
[UPDATING] [..] [UPDATING] [..]
[ERROR] invalid feature `crate:bar` in required-features of target `foo`: \ [ERROR] invalid feature `dep:bar` in required-features of target `foo`: \
`crate:` prefixed feature values are not allowed in required-features `dep:` prefixed feature values are not allowed in required-features
", ",
) )
.run(); .run();
@ -709,7 +709,7 @@ fn crate_required_features() {
#[cargo_test] #[cargo_test]
fn json_exposed() { fn json_exposed() {
// Checks that the implicit crate: values are exposed in JSON. // Checks that the implicit dep: values are exposed in JSON.
Package::new("bar", "1.0.0").publish(); Package::new("bar", "1.0.0").publish();
let p = project() let p = project()
.file( .file(
@ -745,7 +745,7 @@ fn json_exposed() {
"dependencies": "{...}", "dependencies": "{...}",
"targets": "{...}", "targets": "{...}",
"features": { "features": {
"bar": ["crate:bar"] "bar": ["dep:bar"]
}, },
"manifest_path": "[..]foo/Cargo.toml", "manifest_path": "[..]foo/Cargo.toml",
"metadata": null, "metadata": null,
@ -798,7 +798,7 @@ fn crate_feature_with_explicit() {
[features] [features]
f1 = ["bar/bar_feat"] f1 = ["bar/bar_feat"]
bar = ["crate:bar", "f2"] bar = ["dep:bar", "f2"]
f2 = [] f2 = []
"#, "#,
) )
@ -846,7 +846,7 @@ fn optional_explicit_without_crate() {
bar = { version = "1.0", optional = true } bar = { version = "1.0", optional = true }
[features] [features]
feat1 = ["crate:bar"] feat1 = ["dep:bar"]
feat2 = ["bar"] feat2 = ["bar"]
"#, "#,
) )
@ -862,7 +862,7 @@ fn optional_explicit_without_crate() {
Caused by: Caused by:
feature `feat2` includes `bar`, but `bar` is an optional dependency without an implicit feature feature `feat2` includes `bar`, but `bar` is an optional dependency without an implicit feature
Use `crate:bar` to enable the dependency. Use `dep:bar` to enable the dependency.
", ",
) )
.run(); .run();
@ -873,7 +873,7 @@ fn tree() {
Package::new("baz", "1.0.0").publish(); Package::new("baz", "1.0.0").publish();
Package::new("bar", "1.0.0") Package::new("bar", "1.0.0")
.add_dep(Dependency::new("baz", "1.0").optional(true)) .add_dep(Dependency::new("baz", "1.0").optional(true))
.feature("feat1", &["crate:baz"]) .feature("feat1", &["dep:baz"])
.feature("feat2", &[]) .feature("feat2", &[])
.publish(); .publish();
let p = project() let p = project()
@ -889,8 +889,8 @@ fn tree() {
[features] [features]
a = ["bar/feat2"] a = ["bar/feat2"]
b = ["crate:bar/feat2"] b = ["dep:bar/feat2"]
bar = ["crate:bar"] bar = ["dep:bar"]
"#, "#,
) )
.file("src/lib.rs", "") .file("src/lib.rs", "")