Skip to content

Commit bcfdf9f

Browse files
committed
New namespaced features implementation.
1 parent dca0b11 commit bcfdf9f

File tree

24 files changed

+1503
-589
lines changed

24 files changed

+1503
-589
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ enum MatchKind {
12181218

12191219
/// Compares a line with an expected pattern.
12201220
/// - Use `[..]` as a wildcard to match 0 or more characters on the same line
1221-
/// (similar to `.*` in a regex).
1221+
/// (similar to `.*` in a regex). It is non-greedy.
12221222
/// - Use `[EXE]` to optionally add `.exe` on Windows (empty string on other
12231223
/// platforms).
12241224
/// - There is a wide range of macros (such as `[COMPILING]` or `[WARNING]`)

crates/resolver-tests/src/lib.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,7 @@ pub fn resolve_with_config_raw(
170170
list: registry,
171171
used: HashSet::new(),
172172
};
173-
let summary = Summary::new(
174-
pkg_id("root"),
175-
deps,
176-
&BTreeMap::<String, Vec<String>>::new(),
177-
None::<&String>,
178-
false,
179-
)
180-
.unwrap();
173+
let summary = Summary::new(pkg_id("root"), deps, &BTreeMap::new(), None::<&String>).unwrap();
181174
let opts = ResolveOpts::everything();
182175
let start = Instant::now();
183176
let resolve = resolver::resolve(
@@ -571,14 +564,7 @@ pub fn pkg_dep<T: ToPkgId>(name: T, dep: Vec<Dependency>) -> Summary {
571564
} else {
572565
None
573566
};
574-
Summary::new(
575-
name.to_pkgid(),
576-
dep,
577-
&BTreeMap::<String, Vec<String>>::new(),
578-
link,
579-
false,
580-
)
581-
.unwrap()
567+
Summary::new(name.to_pkgid(), dep, &BTreeMap::new(), link).unwrap()
582568
}
583569

584570
pub fn pkg_id(name: &str) -> PackageId {
@@ -599,14 +585,7 @@ pub fn pkg_loc(name: &str, loc: &str) -> Summary {
599585
} else {
600586
None
601587
};
602-
Summary::new(
603-
pkg_id_loc(name, loc),
604-
Vec::new(),
605-
&BTreeMap::<String, Vec<String>>::new(),
606-
link,
607-
false,
608-
)
609-
.unwrap()
588+
Summary::new(pkg_id_loc(name, loc), Vec::new(), &BTreeMap::new(), link).unwrap()
610589
}
611590

612591
pub fn remove_dep(sum: &Summary, ind: usize) -> Summary {
@@ -616,9 +595,8 @@ pub fn remove_dep(sum: &Summary, ind: usize) -> Summary {
616595
Summary::new(
617596
sum.package_id(),
618597
deps,
619-
&BTreeMap::<String, Vec<String>>::new(),
598+
&BTreeMap::new(),
620599
sum.links().map(|a| a.as_str()),
621-
sum.namespaced_features(),
622600
)
623601
.unwrap()
624602
}

crates/resolver-tests/tests/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ proptest! {
228228
}
229229

230230
#[test]
231+
#[should_panic(expected = "pub dep")] // The error handling is not yet implemented.
231232
fn pub_fail() {
232233
let input = vec![
233234
pkg!(("a", "0.0.4")),

src/bin/cargo/cli.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ pub fn main(config: &mut Config) -> CliResult {
3535
"
3636
Available unstable (nightly-only) flags:
3737
38-
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
39-
-Z minimal-versions -- Install minimal dependency versions instead of maximum
40-
-Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
41-
-Z unstable-options -- Allow the usage of unstable options
42-
-Z timings -- Display concurrency information
43-
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
44-
-Z terminal-width -- Provide a terminal width to rustc for error truncation
38+
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
39+
-Z minimal-versions -- Install minimal dependency versions instead of maximum
40+
-Z no-index-update -- Do not update the registry, avoids a network request for benchmarking
41+
-Z unstable-options -- Allow the usage of unstable options
42+
-Z timings -- Display concurrency information
43+
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
44+
-Z terminal-width -- Provide a terminal width to rustc for error truncation
45+
-Z namespaced-features -- Allow features with `crate:` prefix
4546
4647
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
4748
);

src/cargo/core/compiler/unit_dependencies.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,16 @@ impl<'a, 'cfg> State<'a, 'cfg> {
713713
features.activated_features(pkg_id, features_for)
714714
}
715715

716+
fn is_dep_activated(
717+
&self,
718+
pkg_id: PackageId,
719+
features_for: FeaturesFor,
720+
dep_name: InternedString,
721+
) -> bool {
722+
self.features()
723+
.is_dep_activated(pkg_id, features_for, dep_name)
724+
}
725+
716726
fn get(&self, id: PackageId) -> &'a Package {
717727
self.package_set
718728
.get_one(id)
@@ -738,9 +748,7 @@ impl<'a, 'cfg> State<'a, 'cfg> {
738748
// did not enable it, don't include it.
739749
if dep.is_optional() {
740750
let features_for = unit_for.map_to_features_for();
741-
742-
let feats = self.activated_features(pkg_id, features_for);
743-
if !feats.contains(&dep.name_in_toml()) {
751+
if !self.is_dep_activated(pkg_id, features_for, dep.name_in_toml()) {
744752
return false;
745753
}
746754
}

src/cargo/core/features.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ features! {
197197
// Overriding profiles for dependencies.
198198
[stable] profile_overrides: bool,
199199

200-
// Separating the namespaces for features and dependencies
201-
[unstable] namespaced_features: bool,
202-
203200
// "default-run" manifest option,
204201
[stable] default_run: bool,
205202

@@ -360,6 +357,7 @@ pub struct CliUnstable {
360357
pub multitarget: bool,
361358
pub rustdoc_map: bool,
362359
pub terminal_width: Option<Option<usize>>,
360+
pub namespaced_features: bool,
363361
}
364362

365363
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
@@ -465,6 +463,7 @@ impl CliUnstable {
465463
"multitarget" => self.multitarget = parse_empty(k, v)?,
466464
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
467465
"terminal-width" => self.terminal_width = Some(parse_usize_opt(v)?),
466+
"namespaced-features" => self.namespaced_features = parse_empty(k, v)?,
468467
_ => bail!("unknown `-Z` flag specified: {}", k),
469468
}
470469

src/cargo/core/package.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cell::{Cell, Ref, RefCell, RefMut};
22
use std::cmp::Ordering;
3-
use std::collections::{BTreeSet, HashMap, HashSet};
3+
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
44
use std::fmt;
55
use std::hash;
66
use std::mem;
@@ -23,7 +23,7 @@ use crate::core::dependency::DepKind;
2323
use crate::core::resolver::{HasDevUnits, Resolve};
2424
use crate::core::source::MaybePackage;
2525
use crate::core::{Dependency, Manifest, PackageId, SourceId, Target};
26-
use crate::core::{FeatureMap, SourceMap, Summary, Workspace};
26+
use crate::core::{SourceMap, Summary, Workspace};
2727
use crate::ops;
2828
use crate::util::config::PackageCacheLock;
2929
use crate::util::errors::{CargoResult, CargoResultExt, HttpNot200};
@@ -87,7 +87,7 @@ struct SerializedPackage<'a> {
8787
source: SourceId,
8888
dependencies: &'a [Dependency],
8989
targets: Vec<&'a Target>,
90-
features: &'a FeatureMap,
90+
features: &'a BTreeMap<InternedString, Vec<InternedString>>,
9191
manifest_path: &'a Path,
9292
metadata: Option<&'a toml::Value>,
9393
publish: Option<&'a Vec<String>>,
@@ -131,6 +131,12 @@ impl ser::Serialize for Package {
131131
.iter()
132132
.filter(|t| t.src_path().is_path())
133133
.collect();
134+
let empty_feats = BTreeMap::new();
135+
let features = self
136+
.manifest()
137+
.original()
138+
.features()
139+
.unwrap_or(&empty_feats);
134140

135141
SerializedPackage {
136142
name: &*package_id.name(),
@@ -142,7 +148,7 @@ impl ser::Serialize for Package {
142148
source: summary.source_id(),
143149
dependencies: summary.dependencies(),
144150
targets,
145-
features: summary.features(),
151+
features,
146152
manifest_path: self.manifest_path(),
147153
metadata: self.manifest().custom_metadata(),
148154
authors,

0 commit comments

Comments
 (0)