@@ -151,16 +151,37 @@ impl RequestedFeatures {
151
151
impl ResolvedFeatures {
152
152
/// Returns the list of features that are enabled for the given package.
153
153
pub fn activated_features ( & self , pkg_id : PackageId , is_build : bool ) -> Vec < InternedString > {
154
+ self . activated_features_int ( pkg_id, is_build, true )
155
+ }
156
+
157
+ /// Variant of `activated_features` that returns an empty Vec if this is
158
+ /// not a valid pkg_id/is_build combination. Used by `cargo clean` which
159
+ /// doesn't know the exact set.
160
+ pub fn activated_features_unverified (
161
+ & self ,
162
+ pkg_id : PackageId ,
163
+ is_build : bool ,
164
+ ) -> Vec < InternedString > {
165
+ self . activated_features_int ( pkg_id, is_build, false )
166
+ }
167
+
168
+ fn activated_features_int (
169
+ & self ,
170
+ pkg_id : PackageId ,
171
+ is_build : bool ,
172
+ verify : bool ,
173
+ ) -> Vec < InternedString > {
154
174
if let Some ( legacy) = & self . legacy {
155
175
legacy. get ( & pkg_id) . map_or_else ( Vec :: new, |v| v. clone ( ) )
156
176
} else {
157
177
let is_build = self . opts . decouple_build_deps && is_build;
158
- // TODO: Remove panic, return empty set.
159
- let fs = self
160
- . activated_features
161
- . get ( & ( pkg_id, is_build) )
162
- . unwrap_or_else ( || panic ! ( "features did not find {:?} {:?}" , pkg_id, is_build) ) ;
163
- fs. iter ( ) . cloned ( ) . collect ( )
178
+ if let Some ( fs) = self . activated_features . get ( & ( pkg_id, is_build) ) {
179
+ fs. iter ( ) . cloned ( ) . collect ( )
180
+ } else if verify {
181
+ panic ! ( "features did not find {:?} {:?}" , pkg_id, is_build)
182
+ } else {
183
+ Vec :: new ( )
184
+ }
164
185
}
165
186
}
166
187
}
@@ -436,9 +457,8 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
436
457
. dep_platform_activated ( dep, CompileKind :: Host ) ;
437
458
}
438
459
// Not a build dependency, and not for a build script, so must be Target.
439
- return self
440
- . target_data
441
- . dep_platform_activated ( dep, self . requested_target ) ;
460
+ self . target_data
461
+ . dep_platform_activated ( dep, self . requested_target )
442
462
} ;
443
463
self . resolve
444
464
. deps ( pkg_id)
0 commit comments