@@ -319,8 +319,30 @@ impl ResolvedFeatures {
319
319
pkg_id : PackageId ,
320
320
features_for : FeaturesFor ,
321
321
) -> Vec < InternedString > {
322
- self . activated_features_int ( pkg_id, features_for)
323
- . expect ( "activated_features for invalid package" )
322
+ if let Some ( res) = self . activated_features_unverified ( pkg_id, features_for) {
323
+ res
324
+ } else {
325
+ panic ! (
326
+ "did not find features for ({pkg_id:?}, {features_for:?}) within activated_features:\n {:#?}" ,
327
+ self . activated_features. keys( )
328
+ )
329
+ }
330
+ }
331
+
332
+ /// Variant of `activated_features` that returns `None` if this is
333
+ /// not a valid pkg_id/is_build combination. Used in places which do
334
+ /// not know which packages are activated (like `cargo clean`).
335
+ pub fn activated_features_unverified (
336
+ & self ,
337
+ pkg_id : PackageId ,
338
+ features_for : FeaturesFor ,
339
+ ) -> Option < Vec < InternedString > > {
340
+ let fk = features_for. apply_opts ( & self . opts ) ;
341
+ if let Some ( fs) = self . activated_features . get ( & ( pkg_id, fk) ) {
342
+ Some ( fs. iter ( ) . cloned ( ) . collect ( ) )
343
+ } else {
344
+ None
345
+ }
324
346
}
325
347
326
348
/// Returns if the given dependency should be included.
@@ -340,30 +362,6 @@ impl ResolvedFeatures {
340
362
. unwrap_or ( false )
341
363
}
342
364
343
- /// Variant of `activated_features` that returns `None` if this is
344
- /// not a valid pkg_id/is_build combination. Used in places which do
345
- /// not know which packages are activated (like `cargo clean`).
346
- pub fn activated_features_unverified (
347
- & self ,
348
- pkg_id : PackageId ,
349
- features_for : FeaturesFor ,
350
- ) -> Option < Vec < InternedString > > {
351
- self . activated_features_int ( pkg_id, features_for) . ok ( )
352
- }
353
-
354
- fn activated_features_int (
355
- & self ,
356
- pkg_id : PackageId ,
357
- features_for : FeaturesFor ,
358
- ) -> CargoResult < Vec < InternedString > > {
359
- let fk = features_for. apply_opts ( & self . opts ) ;
360
- if let Some ( fs) = self . activated_features . get ( & ( pkg_id, fk) ) {
361
- Ok ( fs. iter ( ) . cloned ( ) . collect ( ) )
362
- } else {
363
- bail ! ( "features did not find {:?} {:?}" , pkg_id, fk)
364
- }
365
- }
366
-
367
365
/// Compares the result against the original resolver behavior.
368
366
///
369
367
/// Used by `cargo fix --edition` to display any differences.
0 commit comments