Skip to content

Commit 1fd81a5

Browse files
committed
Auto merge of #5512 - Eh2406:simplify_FeatureValue, r=alexcrichton
simplify build_requirements use InternedString's ability to be a &'static str to appease the borrow checker This "slight workaround" was added in #5270. So @djc does this still look correct and an improvement?
2 parents 13c258e + ea053e3 commit 1fd81a5

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,7 @@ impl Context {
170170
let deps = s.dependencies();
171171
let deps = deps.iter().filter(|d| d.is_transitive() || dev_deps);
172172

173-
// Requested features stored in the Method are stored as string references, but we want to
174-
// transform them into FeatureValues here. In order to pass the borrow checker with
175-
// storage of the FeatureValues that outlives the Requirements object, we do the
176-
// transformation here, and pass the FeatureValues to build_requirements().
177-
let values = if let Method::Required {
178-
all_features: false,
179-
features: requested,
180-
..
181-
} = *method
182-
{
183-
requested
184-
.iter()
185-
.map(|&f| FeatureValue::new(f, s))
186-
.collect::<Vec<FeatureValue>>()
187-
} else {
188-
vec![]
189-
};
190-
let reqs = build_requirements(s, method, &values)?;
173+
let reqs = build_requirements(s, method)?;
191174
let mut ret = Vec::new();
192175
let mut used_features = HashSet::new();
193176
let default_dep = (false, Vec::new());
@@ -303,13 +286,10 @@ impl Context {
303286
/// dependency features in a Requirements object, returning it to the resolver.
304287
fn build_requirements<'a, 'b: 'a>(
305288
s: &'a Summary,
306-
method: &'b Method,
307-
requested: &'a [FeatureValue],
289+
method: &'b Method
308290
) -> CargoResult<Requirements<'a>> {
309291
let mut reqs = Requirements::new(s);
310-
for fv in requested.iter() {
311-
reqs.require_value(fv)?;
312-
}
292+
313293
match *method {
314294
Method::Everything
315295
| Method::Required {
@@ -322,7 +302,15 @@ fn build_requirements<'a, 'b: 'a>(
322302
reqs.require_dependency(dep.name().as_str());
323303
}
324304
}
325-
_ => {} // Explicitly requested features are handled through `requested`
305+
Method::Required {
306+
all_features: false,
307+
features: requested,
308+
..
309+
} => {
310+
for &f in requested.iter() {
311+
reqs.require_value(&FeatureValue::new(f, s))?;
312+
}
313+
}
326314
}
327315
match *method {
328316
Method::Everything
@@ -413,12 +401,12 @@ impl<'r> Requirements<'r> {
413401
Ok(())
414402
}
415403

416-
fn require_value(&mut self, fv: &'r FeatureValue) -> CargoResult<()> {
417-
match *fv {
418-
FeatureValue::Feature(ref feat) => self.require_feature(feat),
419-
FeatureValue::Crate(ref dep) => Ok(self.require_dependency(dep)),
420-
FeatureValue::CrateFeature(ref dep, dep_feat) => {
421-
Ok(self.require_crate_feature(dep, dep_feat))
404+
fn require_value<'f>(&mut self, fv: &'f FeatureValue) -> CargoResult<()> {
405+
match fv {
406+
FeatureValue::Feature(feat) => self.require_feature(feat.as_str()),
407+
FeatureValue::Crate(dep) => Ok(self.require_dependency(dep.as_str())),
408+
FeatureValue::CrateFeature(dep, dep_feat) => {
409+
Ok(self.require_crate_feature(dep.as_str(), *dep_feat))
422410
}
423411
}
424412
}

0 commit comments

Comments
 (0)