@@ -20,7 +20,7 @@ use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry,
20
20
use crate :: util:: errors:: CargoResult ;
21
21
22
22
use crate :: core:: resolver:: types:: { ConflictReason , DepInfo , FeaturesSet } ;
23
- use crate :: core:: resolver:: { ActivateResult , Method } ;
23
+ use crate :: core:: resolver:: { ActivateResult , ResolveOpts } ;
24
24
25
25
pub struct RegistryQueryer < ' a > {
26
26
pub registry : & ' a mut ( dyn Registry + ' a ) ,
@@ -34,7 +34,7 @@ pub struct RegistryQueryer<'a> {
34
34
registry_cache : HashMap < Dependency , Rc < Vec < Summary > > > ,
35
35
/// a cache of `Dependency`s that are required for a `Summary`
36
36
summary_cache : HashMap <
37
- ( Option < PackageId > , Summary , Method ) ,
37
+ ( Option < PackageId > , Summary , ResolveOpts ) ,
38
38
Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > ,
39
39
> ,
40
40
/// all the cases we ended up using a supplied replacement
@@ -192,28 +192,28 @@ impl<'a> RegistryQueryer<'a> {
192
192
}
193
193
194
194
/// Find out what dependencies will be added by activating `candidate`,
195
- /// with features described in `method `. Then look up in the `registry`
195
+ /// with features described in `opts `. Then look up in the `registry`
196
196
/// the candidates that will fulfil each of these dependencies, as it is the
197
197
/// next obvious question.
198
198
pub fn build_deps (
199
199
& mut self ,
200
200
parent : Option < PackageId > ,
201
201
candidate : & Summary ,
202
- method : & Method ,
202
+ opts : & ResolveOpts ,
203
203
) -> ActivateResult < Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > > {
204
204
// if we have calculated a result before, then we can just return it,
205
205
// as it is a "pure" query of its arguments.
206
206
if let Some ( out) = self
207
207
. summary_cache
208
- . get ( & ( parent, candidate. clone ( ) , method . clone ( ) ) )
208
+ . get ( & ( parent, candidate. clone ( ) , opts . clone ( ) ) )
209
209
. cloned ( )
210
210
{
211
211
return Ok ( out) ;
212
212
}
213
213
// First, figure out our set of dependencies based on the requested set
214
214
// of features. This also calculates what features we're going to enable
215
215
// for our own dependencies.
216
- let ( used_features, deps) = resolve_features ( parent, candidate, method ) ?;
216
+ let ( used_features, deps) = resolve_features ( parent, candidate, opts ) ?;
217
217
218
218
// Next, transform all dependencies into a list of possible candidates
219
219
// which can satisfy that dependency.
@@ -236,7 +236,7 @@ impl<'a> RegistryQueryer<'a> {
236
236
// If we succeed we add the result to the cache so we can use it again next time.
237
237
// We dont cache the failure cases as they dont impl Clone.
238
238
self . summary_cache
239
- . insert ( ( parent, candidate. clone ( ) , method . clone ( ) ) , out. clone ( ) ) ;
239
+ . insert ( ( parent, candidate. clone ( ) , opts . clone ( ) ) , out. clone ( ) ) ;
240
240
241
241
Ok ( out)
242
242
}
@@ -247,18 +247,13 @@ impl<'a> RegistryQueryer<'a> {
247
247
pub fn resolve_features < ' b > (
248
248
parent : Option < PackageId > ,
249
249
s : & ' b Summary ,
250
- method : & ' b Method ,
250
+ opts : & ' b ResolveOpts ,
251
251
) -> ActivateResult < ( HashSet < InternedString > , Vec < ( Dependency , FeaturesSet ) > ) > {
252
- let dev_deps = match * method {
253
- Method :: Everything => true ,
254
- Method :: Required { dev_deps, .. } => dev_deps,
255
- } ;
256
-
257
252
// First, filter by dev-dependencies.
258
253
let deps = s. dependencies ( ) ;
259
- let deps = deps. iter ( ) . filter ( |d| d. is_transitive ( ) || dev_deps) ;
254
+ let deps = deps. iter ( ) . filter ( |d| d. is_transitive ( ) || opts . dev_deps ) ;
260
255
261
- let reqs = build_requirements ( s, method ) ?;
256
+ let reqs = build_requirements ( s, opts ) ?;
262
257
let mut ret = Vec :: new ( ) ;
263
258
let mut used_features = HashSet :: new ( ) ;
264
259
let default_dep = ( false , BTreeSet :: new ( ) ) ;
@@ -336,52 +331,34 @@ pub fn resolve_features<'b>(
336
331
Ok ( ( reqs. into_used ( ) , ret) )
337
332
}
338
333
339
- /// Takes requested features for a single package from the input `Method ` and
334
+ /// Takes requested features for a single package from the input `ResolveOpts ` and
340
335
/// recurses to find all requested features, dependencies and requested
341
336
/// dependency features in a `Requirements` object, returning it to the resolver.
342
337
fn build_requirements < ' a , ' b : ' a > (
343
338
s : & ' a Summary ,
344
- method : & ' b Method ,
339
+ opts : & ' b ResolveOpts ,
345
340
) -> CargoResult < Requirements < ' a > > {
346
341
let mut reqs = Requirements :: new ( s) ;
347
342
348
- match method {
349
- Method :: Everything
350
- | Method :: Required {
351
- all_features : true , ..
352
- } => {
353
- for key in s. features ( ) . keys ( ) {
354
- reqs. require_feature ( * key) ?;
355
- }
356
- for dep in s. dependencies ( ) . iter ( ) . filter ( |d| d. is_optional ( ) ) {
357
- reqs. require_dependency ( dep. name_in_toml ( ) ) ;
358
- }
343
+ if opts. all_features {
344
+ for key in s. features ( ) . keys ( ) {
345
+ reqs. require_feature ( * key) ?;
359
346
}
360
- Method :: Required {
361
- all_features : false ,
362
- features : requested,
363
- ..
364
- } => {
365
- for & f in requested. iter ( ) {
366
- reqs. require_value ( & FeatureValue :: new ( f, s) ) ?;
367
- }
347
+ for dep in s. dependencies ( ) . iter ( ) . filter ( |d| d. is_optional ( ) ) {
348
+ reqs. require_dependency ( dep. name_in_toml ( ) ) ;
349
+ }
350
+ } else {
351
+ for & f in opts. features . iter ( ) {
352
+ reqs. require_value ( & FeatureValue :: new ( f, s) ) ?;
368
353
}
369
354
}
370
- match * method {
371
- Method :: Everything
372
- | Method :: Required {
373
- uses_default_features : true ,
374
- ..
375
- } => {
376
- if s. features ( ) . contains_key ( "default" ) {
377
- reqs. require_feature ( InternedString :: new ( "default" ) ) ?;
378
- }
355
+
356
+ if opts. uses_default_features {
357
+ if s. features ( ) . contains_key ( "default" ) {
358
+ reqs. require_feature ( InternedString :: new ( "default" ) ) ?;
379
359
}
380
- Method :: Required {
381
- uses_default_features : false ,
382
- ..
383
- } => { }
384
360
}
361
+
385
362
Ok ( reqs)
386
363
}
387
364
0 commit comments