Skip to content

Commit 301010a

Browse files
committed
chore(implicit_features): Cleanup getting dep features
1 parent 9855e50 commit 301010a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/cargo/util/lints.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,28 +170,23 @@ pub fn check_implicit_features(
170170
}
171171

172172
let manifest = pkg.manifest();
173-
let user_defined_features = manifest.resolved_toml().features();
174-
let features = user_defined_features.map_or(HashSet::new(), |f| {
175-
f.keys().map(|k| InternedString::new(&k)).collect()
176-
});
177-
// Add implicit features for optional dependencies if they weren't
178-
// explicitly listed anywhere.
179-
let explicitly_listed = user_defined_features.map_or(HashSet::new(), |f| {
180-
f.values()
181-
.flatten()
182-
.filter_map(|v| match FeatureValue::new(v.into()) {
183-
Dep { dep_name } => Some(dep_name),
184-
_ => None,
185-
})
186-
.collect()
187-
});
173+
let activated_opt_deps = manifest
174+
.resolved_toml()
175+
.features()
176+
.map(|map| {
177+
map.values()
178+
.flatten()
179+
.filter_map(|f| match FeatureValue::new(InternedString::new(f)) {
180+
Dep { dep_name } => Some(dep_name.as_str()),
181+
_ => None,
182+
})
183+
.collect::<HashSet<_>>()
184+
})
185+
.unwrap_or_default();
188186

189187
for dep in manifest.dependencies() {
190188
let dep_name_in_toml = dep.name_in_toml();
191-
if !dep.is_optional()
192-
|| features.contains(&dep_name_in_toml)
193-
|| explicitly_listed.contains(&dep_name_in_toml)
194-
{
189+
if !dep.is_optional() || activated_opt_deps.contains(dep_name_in_toml.as_str()) {
195190
continue;
196191
}
197192
if lint_level == LintLevel::Forbid || lint_level == LintLevel::Deny {

0 commit comments

Comments
 (0)