Skip to content

Commit

Permalink
Auto merge of #1310 - tanadeau:use-struct-variant, r=alexcrichton
Browse files Browse the repository at this point in the history
Minor code cleanup for readability and usability for `Method` enum.
  • Loading branch information
bors committed Feb 16, 2015
2 parents d938f4a + 3f57587 commit e7393a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
29 changes: 17 additions & 12 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub struct Resolve {
#[derive(Copy)]
pub enum Method<'a> {
Everything,
Required(/* dev_deps = */ bool,
/* features = */ &'a [String],
/* uses_default_features = */ bool,
/* target_platform = */ Option<&'a str>),
Required{ dev_deps: bool,
features: &'a [String],
uses_default_features: bool,
target_platform: Option<&'a str>},
}

impl Resolve {
Expand Down Expand Up @@ -170,7 +170,7 @@ fn activate(mut cx: Box<Context>,

// Extracting the platform request.
let platform = match method {
Method::Required(_, _, _, platform) => platform,
Method::Required{target_platform: platform, ..} => platform,
Method::Everything => None,
};

Expand Down Expand Up @@ -230,7 +230,7 @@ fn flag_activated(cx: &mut Context,
}
debug!("checking if {} is already activated", summary.package_id());
let features = match *method {
Method::Required(_, features, _, _) => features,
Method::Required{features, ..} => features,
Method::Everything => return false,
};
match cx.resolve.features(id) {
Expand All @@ -247,8 +247,12 @@ fn activate_deps<'a>(cx: Box<Context>,
cur: usize) -> CargoResult<CargoResult<Box<Context>>> {
if cur == deps.len() { return Ok(Ok(cx)) }
let (dep, ref candidates, ref features) = deps[cur];
let method = Method::Required(false, &features,
dep.uses_default_features(), platform);

let method = Method::Required{
dev_deps: false,
features: &features,
uses_default_features: dep.uses_default_features(),
target_platform: platform};

let key = (dep.name().to_string(), dep.source_id().clone());
let prev_active = cx.activations.get(&key)
Expand Down Expand Up @@ -424,7 +428,7 @@ fn resolve_features<'a>(cx: &mut Context, parent: &'a Summary,
(&'a Dependency, Vec<String>)>> {
let dev_deps = match method {
Method::Everything => true,
Method::Required(dev_deps, _, _, _) => dev_deps,
Method::Required{dev_deps, ..} => dev_deps,
};

// First, filter by dev-dependencies
Expand All @@ -434,7 +438,7 @@ fn resolve_features<'a>(cx: &mut Context, parent: &'a Summary,
// Second, ignoring dependencies that should not be compiled for this platform
let deps = deps.filter(|d| {
match method {
Method::Required(_, _, _, Some(ref platform)) => {
Method::Required{target_platform: Some(ref platform), ..} => {
d.is_active_for_platform(platform)
},
_ => true
Expand Down Expand Up @@ -514,14 +518,15 @@ fn build_features(s: &Summary, method: Method)
&mut visited));
}
}
Method::Required(_, requested_features, _, _) => {
Method::Required{features: requested_features, ..} => {
for feat in requested_features.iter() {
try!(add_feature(s, feat, &mut deps, &mut used, &mut visited));
}
}
}
match method {
Method::Everything | Method::Required(_, _, true, _) => {
Method::Everything |
Method::Required{uses_default_features: true, ..} => {
if s.features().get("default").is_some() &&
!visited.contains("default") {
try!(add_feature(s, "default", &mut deps, &mut used,
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
try!(registry.add_overrides(override_ids));

let platform = target.as_ref().map(|e| e.as_slice()).or(Some(rustc_host.as_slice()));
let method = Method::Required(dev_deps, &features,
!no_default_features, platform);

let method = Method::Required{
dev_deps: dev_deps,
features: &features,
uses_default_features: !no_default_features,
target_platform: platform};

let resolved_with_overrides =
try!(ops::resolve_with_previous(&mut registry, package, method,
Some(&resolve), None));
Expand Down

0 comments on commit e7393a0

Please sign in to comment.