Skip to content

Commit 3fd7580

Browse files
committed
remove unnecessary specialiized FilterRule::try_collect method
1 parent f4da514 commit 3fd7580

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/cargo/ops/cargo_compile/compile_filter.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ impl FilterRule {
8787
}
8888
}
8989

90-
pub fn try_collect(&self) -> Option<Vec<String>> {
91-
match *self {
92-
FilterRule::All => None,
93-
FilterRule::Just(ref targets) => Some(targets.clone()),
94-
}
95-
}
96-
9790
/// Checks if any specified target name contains glob patterns.
9891
pub(crate) fn contains_glob_patterns(&self) -> bool {
9992
match self {

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ use std::rc::Rc;
77
use std::task::Poll;
88

99
use anyhow::{bail, format_err, Context as _};
10+
use ops::FilterRule;
1011
use serde::{Deserialize, Serialize};
1112
use toml_edit::easy as toml;
1213

1314
use crate::core::compiler::Freshness;
15+
use crate::core::Target;
1416
use crate::core::{Dependency, FeatureValue, Package, PackageId, QueryKind, Source, SourceId};
1517
use crate::ops::{self, CompileFilter, CompileOptions};
1618
use crate::sources::PathSource;
@@ -690,20 +692,17 @@ pub fn exe_names(pkg: &Package, filter: &ops::CompileFilter) -> BTreeSet<String>
690692
ref examples,
691693
..
692694
} => {
693-
let all_bins: Vec<String> = bins.try_collect().unwrap_or_else(|| {
694-
pkg.targets()
695+
let collect = |rule: &_, f: fn(&Target) -> _| match rule {
696+
FilterRule::All => pkg
697+
.targets()
695698
.iter()
696-
.filter(|t| t.is_bin())
697-
.map(|t| t.name().to_string())
698-
.collect()
699-
});
700-
let all_examples: Vec<String> = examples.try_collect().unwrap_or_else(|| {
701-
pkg.targets()
702-
.iter()
703-
.filter(|t| t.is_exe_example())
704-
.map(|t| t.name().to_string())
705-
.collect()
706-
});
699+
.filter(|t| f(t))
700+
.map(|t| t.name().into())
701+
.collect(),
702+
FilterRule::Just(targets) => targets.clone(),
703+
};
704+
let all_bins = collect(bins, Target::is_bin);
705+
let all_examples = collect(examples, Target::is_exe_example);
707706

708707
all_bins
709708
.iter()

0 commit comments

Comments
 (0)