@@ -20,7 +20,7 @@ use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry,
2020use crate :: util:: errors:: CargoResult ;
2121
2222use crate :: core:: resolver:: types:: { ConflictReason , DepInfo , FeaturesSet } ;
23- use crate :: core:: resolver:: { ActivateResult , Method } ;
23+ use crate :: core:: resolver:: { ActivateResult , ResolveOpts } ;
2424
2525pub struct RegistryQueryer < ' a > {
2626 pub registry : & ' a mut ( dyn Registry + ' a ) ,
@@ -34,7 +34,7 @@ pub struct RegistryQueryer<'a> {
3434 registry_cache : HashMap < Dependency , Rc < Vec < Summary > > > ,
3535 /// a cache of `Dependency`s that are required for a `Summary`
3636 summary_cache : HashMap <
37- ( Option < PackageId > , Summary , Method ) ,
37+ ( Option < PackageId > , Summary , ResolveOpts ) ,
3838 Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > ,
3939 > ,
4040 /// all the cases we ended up using a supplied replacement
@@ -192,28 +192,28 @@ impl<'a> RegistryQueryer<'a> {
192192 }
193193
194194 /// 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`
196196 /// the candidates that will fulfil each of these dependencies, as it is the
197197 /// next obvious question.
198198 pub fn build_deps (
199199 & mut self ,
200200 parent : Option < PackageId > ,
201201 candidate : & Summary ,
202- method : & Method ,
202+ opts : & ResolveOpts ,
203203 ) -> ActivateResult < Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > > {
204204 // if we have calculated a result before, then we can just return it,
205205 // as it is a "pure" query of its arguments.
206206 if let Some ( out) = self
207207 . summary_cache
208- . get ( & ( parent, candidate. clone ( ) , method . clone ( ) ) )
208+ . get ( & ( parent, candidate. clone ( ) , opts . clone ( ) ) )
209209 . cloned ( )
210210 {
211211 return Ok ( out) ;
212212 }
213213 // First, figure out our set of dependencies based on the requested set
214214 // of features. This also calculates what features we're going to enable
215215 // for our own dependencies.
216- let ( used_features, deps) = resolve_features ( parent, candidate, method ) ?;
216+ let ( used_features, deps) = resolve_features ( parent, candidate, opts ) ?;
217217
218218 // Next, transform all dependencies into a list of possible candidates
219219 // which can satisfy that dependency.
@@ -236,7 +236,7 @@ impl<'a> RegistryQueryer<'a> {
236236 // If we succeed we add the result to the cache so we can use it again next time.
237237 // We dont cache the failure cases as they dont impl Clone.
238238 self . summary_cache
239- . insert ( ( parent, candidate. clone ( ) , method . clone ( ) ) , out. clone ( ) ) ;
239+ . insert ( ( parent, candidate. clone ( ) , opts . clone ( ) ) , out. clone ( ) ) ;
240240
241241 Ok ( out)
242242 }
@@ -247,18 +247,13 @@ impl<'a> RegistryQueryer<'a> {
247247pub fn resolve_features < ' b > (
248248 parent : Option < PackageId > ,
249249 s : & ' b Summary ,
250- method : & ' b Method ,
250+ opts : & ' b ResolveOpts ,
251251) -> 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-
257252 // First, filter by dev-dependencies.
258253 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 ) ;
260255
261- let reqs = build_requirements ( s, method ) ?;
256+ let reqs = build_requirements ( s, opts ) ?;
262257 let mut ret = Vec :: new ( ) ;
263258 let mut used_features = HashSet :: new ( ) ;
264259 let default_dep = ( false , BTreeSet :: new ( ) ) ;
@@ -336,52 +331,34 @@ pub fn resolve_features<'b>(
336331 Ok ( ( reqs. into_used ( ) , ret) )
337332}
338333
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
340335/// recurses to find all requested features, dependencies and requested
341336/// dependency features in a `Requirements` object, returning it to the resolver.
342337fn build_requirements < ' a , ' b : ' a > (
343338 s : & ' a Summary ,
344- method : & ' b Method ,
339+ opts : & ' b ResolveOpts ,
345340) -> CargoResult < Requirements < ' a > > {
346341 let mut reqs = Requirements :: new ( s) ;
347342
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) ?;
359346 }
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) ) ?;
368353 }
369354 }
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" ) ) ?;
379359 }
380- Method :: Required {
381- uses_default_features : false ,
382- ..
383- } => { }
384360 }
361+
385362 Ok ( reqs)
386363}
387364
0 commit comments