Skip to content

Commit f4ac82a

Browse files
committed
Rename crate: to dep:
1 parent 8ff130b commit f4ac82a

File tree

11 files changed

+129
-124
lines changed

11 files changed

+129
-124
lines changed

src/bin/cargo/cli.rs

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

src/cargo/core/resolver/dep_cache.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ pub fn resolve_features<'b>(
342342
}
343343

344344
// This is a special case for command-line `--features
345-
// crate_name/feat_name` where `crate_name` does not exist. All other
345+
// dep_name/feat_name` where `dep_name` does not exist. All other
346346
// validation is done either in `build_requirements` or
347347
// `build_feature_map`.
348348
for dep_name in reqs.deps.keys() {
@@ -374,9 +374,9 @@ 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.has_crate_prefix() {
377+
if fv.has_dep_prefix() {
378378
return Err(ActivateError::Fatal(anyhow::format_err!(
379-
"feature value `{}` is not allowed to use explicit `crate:` syntax",
379+
"feature value `{}` is not allowed to use explicit `dep:` syntax",
380380
fv
381381
)));
382382
}
@@ -438,16 +438,16 @@ impl Requirements<'_> {
438438
self.features
439439
}
440440

441-
fn require_crate_feature(
441+
fn require_dep_feature(
442442
&mut self,
443443
package: InternedString,
444444
feat: InternedString,
445-
crate_prefix: bool,
445+
dep_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 !crate_prefix
450+
if !dep_prefix
451451
&& self
452452
.summary
453453
.dependencies()
@@ -489,12 +489,12 @@ impl Requirements<'_> {
489489
fn require_value(&mut self, fv: &FeatureValue) -> Result<(), RequirementError> {
490490
match fv {
491491
FeatureValue::Feature(feat) => self.require_feature(*feat)?,
492-
FeatureValue::Crate { dep_name } => self.require_dependency(*dep_name),
493-
FeatureValue::CrateFeature {
492+
FeatureValue::Dep { dep_name } => self.require_dependency(*dep_name),
493+
FeatureValue::DepFeature {
494494
dep_name,
495495
dep_feature,
496-
crate_prefix,
497-
} => self.require_crate_feature(*dep_name, *dep_feature, *crate_prefix)?,
496+
dep_prefix,
497+
} => self.require_dep_feature(*dep_name, *dep_feature, *dep_prefix)?,
498498
};
499499
Ok(())
500500
}
@@ -526,7 +526,7 @@ impl RequirementError {
526526
match parent {
527527
None => ActivateError::Fatal(anyhow::format_err!(
528528
"Package `{}` does not have feature `{}`. It has an optional dependency \
529-
with that name, but that dependency uses the \"crate:\" \
529+
with that name, but that dependency uses the \"dep:\" \
530530
syntax in the features table, so it does not have an implicit feature with that name.",
531531
summary.package_id(),
532532
feat
@@ -559,7 +559,7 @@ impl RequirementError {
559559
dep_name
560560
)),
561561
// This code path currently isn't used, since `foo/bar`
562-
// and `crate:` syntax is not allowed in a dependency.
562+
// and `dep:` syntax is not allowed in a dependency.
563563
Some(p) => ActivateError::Conflict(
564564
p,
565565
ConflictReason::MissingFeatures(dep_name.to_string()),

src/cargo/core/resolver/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub(super) fn activation_error(
170170
msg.push_str("` does not have these features.\n");
171171
msg.push_str(
172172
" It has an optional dependency with that name, \
173-
but but that dependency uses the \"crate:\" \
173+
but but that dependency uses the \"dep:\" \
174174
syntax in the features table, so it does not have an \
175175
implicit feature with that name.\n",
176176
);

src/cargo/core/resolver/features.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
412412
// For example, consider we've already processed our dependencies,
413413
// and another package comes along and enables one of our optional
414414
// dependencies, it will do so immediately in the
415-
// `FeatureValue::CrateFeature` branch, and then immediately
415+
// `FeatureValue::DepFeature` branch, and then immediately
416416
// recurse into that optional dependency. This also holds true for
417417
// features that enable other features.
418418
return Ok(());
@@ -443,7 +443,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
443443
FeatureValue::Feature(f) => {
444444
self.activate_rec(pkg_id, *f, for_host)?;
445445
}
446-
FeatureValue::Crate { dep_name } => {
446+
FeatureValue::Dep { dep_name } => {
447447
// Mark this dependency as activated.
448448
self.activated_dependencies
449449
.entry((pkg_id, self.opts.decouple_host_deps && for_host))
@@ -460,10 +460,10 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
460460
}
461461
}
462462
}
463-
FeatureValue::CrateFeature {
463+
FeatureValue::DepFeature {
464464
dep_name,
465465
dep_feature,
466-
crate_prefix,
466+
dep_prefix,
467467
} => {
468468
// Activate a feature within a dependency.
469469
for (dep_pkg_id, deps) in self.deps(pkg_id, for_host) {
@@ -472,12 +472,12 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
472472
continue;
473473
}
474474
if dep.is_optional() {
475-
// Activate the crate on self.
476-
let fv = FeatureValue::Crate {
475+
// Activate the dependency on self.
476+
let fv = FeatureValue::Dep {
477477
dep_name: *dep_name,
478478
};
479479
self.activate_fv(pkg_id, &fv, for_host)?;
480-
if !crate_prefix {
480+
if !dep_prefix {
481481
// To retain compatibility with old behavior,
482482
// this also enables a feature of the same
483483
// name.

src/cargo/core/resolver/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub enum ConflictReason {
297297
RequiredDependencyAsFeature(InternedString),
298298

299299
/// A dependency listed a feature for an optional dependency, but that
300-
/// optional dependency is "hidden" using namespaced `crate:` syntax.
300+
/// optional dependency is "hidden" using namespaced `dep:` syntax.
301301
NonImplicitDependencyAsFeature(InternedString),
302302

303303
// TODO: needs more info for `activation_error`

src/cargo/core/summary.rs

+41-36
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Summary {
8888
if !namespaced_features {
8989
if self.inner.has_namespaced_features {
9090
bail!(
91-
"namespaced features with the `crate:` prefix are only allowed on \
91+
"namespaced features with the `dep:` prefix are only allowed on \
9292
the nightly channel and requires the `-Z namespaced-features` flag on the command-line"
9393
);
9494
}
@@ -158,7 +158,7 @@ impl Hash for Summary {
158158
/// and creates FeatureValues for each feature.
159159
///
160160
/// The returned `bool` indicates whether or not the `[features]` table
161-
/// included a `crate:` prefixed namespaced feature (used for gating on
161+
/// included a `dep:` prefixed namespaced feature (used for gating on
162162
/// nightly).
163163
fn build_feature_map(
164164
features: &BTreeMap<InternedString, Vec<InternedString>>,
@@ -183,18 +183,18 @@ fn build_feature_map(
183183
(*feature, fvs)
184184
})
185185
.collect();
186-
let has_namespaced_features = map.values().flatten().any(|fv| fv.has_crate_prefix());
186+
let has_namespaced_features = map.values().flatten().any(|fv| fv.has_dep_prefix());
187187

188188
// Add implicit features for optional dependencies if they weren't
189189
// explicitly listed anywhere.
190190
let explicitly_listed: HashSet<_> = map
191191
.values()
192192
.flatten()
193193
.filter_map(|fv| match fv {
194-
Crate { dep_name }
195-
| CrateFeature {
194+
Dep { dep_name }
195+
| DepFeature {
196196
dep_name,
197-
crate_prefix: true,
197+
dep_prefix: true,
198198
..
199199
} => Some(*dep_name),
200200
_ => None,
@@ -209,25 +209,25 @@ fn build_feature_map(
209209
{
210210
continue;
211211
}
212-
let fv = Crate {
212+
let fv = Dep {
213213
dep_name: dep_name_in_toml,
214214
};
215215
map.insert(dep_name_in_toml, vec![fv]);
216216
}
217217

218218
// Validate features are listed properly.
219219
for (feature, fvs) in &map {
220-
if feature.starts_with("crate:") {
220+
if feature.starts_with("dep:") {
221221
bail!(
222-
"feature named `{}` is not allowed to start with `crate:`",
222+
"feature named `{}` is not allowed to start with `dep:`",
223223
feature
224224
);
225225
}
226226
for fv in fvs {
227227
// Find data for the referenced dependency...
228228
let dep_data = {
229229
match fv {
230-
Feature(dep_name) | Crate { dep_name, .. } | CrateFeature { dep_name, .. } => {
230+
Feature(dep_name) | Dep { dep_name, .. } | DepFeature { dep_name, .. } => {
231231
dep_map.get(dep_name)
232232
}
233233
}
@@ -253,7 +253,7 @@ fn build_feature_map(
253253
bail!(
254254
"feature `{}` includes `{}`, but `{}` is an \
255255
optional dependency without an implicit feature\n\
256-
Use `crate:{}` to enable the dependency.",
256+
Use `dep:{}` to enable the dependency.",
257257
feature,
258258
fv,
259259
f,
@@ -268,7 +268,7 @@ fn build_feature_map(
268268
}
269269
}
270270
}
271-
Crate { dep_name } => {
271+
Dep { dep_name } => {
272272
if !is_any_dep {
273273
bail!(
274274
"feature `{}` includes `{}`, but `{}` is not listed as a dependency",
@@ -288,7 +288,7 @@ fn build_feature_map(
288288
);
289289
}
290290
}
291-
CrateFeature { dep_name, .. } => {
291+
DepFeature { dep_name, .. } => {
292292
// Validation of the feature name will be performed in the resolver.
293293
if !is_any_dep {
294294
bail!(
@@ -308,7 +308,7 @@ fn build_feature_map(
308308
.values()
309309
.flatten()
310310
.filter_map(|fv| match fv {
311-
Crate { dep_name } | CrateFeature { dep_name, .. } => Some(dep_name),
311+
Dep { dep_name } | DepFeature { dep_name, .. } => Some(dep_name),
312312
_ => None,
313313
})
314314
.collect();
@@ -318,7 +318,7 @@ fn build_feature_map(
318318
{
319319
bail!(
320320
"optional dependency `{}` is not included in any feature\n\
321-
Make sure that `crate:{}` is included in one of features in the [features] table.",
321+
Make sure that `dep:{}` is included in one of features in the [features] table.",
322322
dep.name_in_toml(),
323323
dep.name_in_toml(),
324324
);
@@ -332,15 +332,15 @@ fn build_feature_map(
332332
pub enum FeatureValue {
333333
/// A feature enabling another feature.
334334
Feature(InternedString),
335-
/// A feature enabling a dependency with `crate:dep_name` syntax.
336-
Crate { dep_name: InternedString },
335+
/// A feature enabling a dependency with `dep:dep_name` syntax.
336+
Dep { dep_name: InternedString },
337337
/// A feature enabling a feature on a dependency with `crate_name/feat_name` syntax.
338-
CrateFeature {
338+
DepFeature {
339339
dep_name: InternedString,
340340
dep_feature: InternedString,
341-
/// If this is true, then the feature used the `crate:` prefix, which
341+
/// If this is true, then the feature used the `dep:` prefix, which
342342
/// prevents enabling the feature named `dep_name`.
343-
crate_prefix: bool,
343+
dep_prefix: bool,
344344
},
345345
}
346346

@@ -350,27 +350,32 @@ impl FeatureValue {
350350
Some(pos) => {
351351
let (dep, dep_feat) = feature.split_at(pos);
352352
let dep_feat = &dep_feat[1..];
353-
let (dep, crate_prefix) = if let Some(dep) = dep.strip_prefix("crate:") {
353+
let (dep, dep_prefix) = if let Some(dep) = dep.strip_prefix("dep:") {
354354
(dep, true)
355355
} else {
356356
(dep, false)
357357
};
358-
FeatureValue::CrateFeature {
358+
FeatureValue::DepFeature {
359359
dep_name: InternedString::new(dep),
360360
dep_feature: InternedString::new(dep_feat),
361-
crate_prefix,
361+
dep_prefix,
362+
}
363+
}
364+
None => {
365+
if let Some(dep_name) = feature.strip_prefix("dep:") {
366+
FeatureValue::Dep {
367+
dep_name: InternedString::new(dep_name),
368+
}
369+
} else {
370+
FeatureValue::Feature(feature)
362371
}
363372
}
364-
None if feature.starts_with("crate:") => FeatureValue::Crate {
365-
dep_name: InternedString::new(&feature[6..]),
366-
},
367-
None => FeatureValue::Feature(feature),
368373
}
369374
}
370375

371-
/// Returns `true` if this feature explicitly used `crate:` syntax.
372-
pub fn has_crate_prefix(&self) -> bool {
373-
matches!(self, FeatureValue::Crate{..} | FeatureValue::CrateFeature{crate_prefix:true, ..})
376+
/// Returns `true` if this feature explicitly used `dep:` syntax.
377+
pub fn has_dep_prefix(&self) -> bool {
378+
matches!(self, FeatureValue::Dep{..} | FeatureValue::DepFeature{dep_prefix:true, ..})
374379
}
375380
}
376381

@@ -379,16 +384,16 @@ impl fmt::Display for FeatureValue {
379384
use self::FeatureValue::*;
380385
match self {
381386
Feature(feat) => write!(f, "{}", feat),
382-
Crate { dep_name } => write!(f, "crate:{}", dep_name),
383-
CrateFeature {
387+
Dep { dep_name } => write!(f, "dep:{}", dep_name),
388+
DepFeature {
384389
dep_name,
385390
dep_feature,
386-
crate_prefix: true,
387-
} => write!(f, "crate:{}/{}", dep_name, dep_feature),
388-
CrateFeature {
391+
dep_prefix: true,
392+
} => write!(f, "dep:{}/{}", dep_name, dep_feature),
393+
DepFeature {
389394
dep_name,
390395
dep_feature,
391-
crate_prefix: false,
396+
dep_prefix: false,
392397
} => write!(f, "{}/{}", dep_name, dep_feature),
393398
}
394399
}

src/cargo/ops/cargo_compile.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1071,22 +1071,22 @@ fn validate_required_features(
10711071
))?;
10721072
}
10731073
}
1074-
FeatureValue::Crate { .. }
1075-
| FeatureValue::CrateFeature {
1076-
crate_prefix: true, ..
1074+
FeatureValue::Dep { .. }
1075+
| FeatureValue::DepFeature {
1076+
dep_prefix: true, ..
10771077
} => {
10781078
anyhow::bail!(
10791079
"invalid feature `{}` in required-features of target `{}`: \
1080-
`crate:` prefixed feature values are not allowed in required-features",
1080+
`dep:` prefixed feature values are not allowed in required-features",
10811081
fv,
10821082
target_name
10831083
);
10841084
}
10851085
// Handling of dependent_crate/dependent_crate_feature syntax
1086-
FeatureValue::CrateFeature {
1086+
FeatureValue::DepFeature {
10871087
dep_name,
10881088
dep_feature,
1089-
crate_prefix: false,
1089+
dep_prefix: false,
10901090
} => {
10911091
match resolve
10921092
.deps(summary.package_id())

0 commit comments

Comments
 (0)