Skip to content

Commit 2df8e65

Browse files
committed
Simplify implied_target_features.
Currently its argument is an iterator, but in practice it's always a singleton.
1 parent 1df93fd commit 2df8e65

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
4848
for feature in sess.opts.cg.target_feature.split(',') {
4949
if let Some(feature) = feature.strip_prefix('+') {
5050
all_rust_features.extend(
51-
UnordSet::from(sess.target.implied_target_features(std::iter::once(feature)))
51+
UnordSet::from(sess.target.implied_target_features(feature))
5252
.to_sorted_stable_ord()
5353
.iter()
5454
.map(|&&s| (true, s)),

compiler/rustc_codegen_llvm/src/llvm_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
360360
#[allow(rustc::potential_query_instability)]
361361
features.extend(
362362
sess.target
363-
.implied_target_features(std::iter::once(feature.as_str()))
363+
.implied_target_features(feature.as_str())
364364
.iter()
365365
.map(|s| Symbol::intern(s)),
366366
);
@@ -373,7 +373,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
373373
features.retain(|f| {
374374
if sess
375375
.target
376-
.implied_target_features(std::iter::once(f.as_str()))
376+
.implied_target_features(f.as_str())
377377
.contains(&feature.as_str())
378378
{
379379
// If `f` if implies `feature`, then `!feature` implies `!f`, so we have to
@@ -681,7 +681,7 @@ pub(crate) fn global_llvm_features(
681681
for feature in sess.opts.cg.target_feature.split(',') {
682682
if let Some(feature) = feature.strip_prefix('+') {
683683
all_rust_features.extend(
684-
UnordSet::from(sess.target.implied_target_features(std::iter::once(feature)))
684+
UnordSet::from(sess.target.implied_target_features(feature))
685685
.to_sorted_stable_ord()
686686
.iter()
687687
.map(|&&s| (true, s)),

compiler/rustc_codegen_ssa/src/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub(crate) fn provide(providers: &mut Providers) {
190190
},
191191
implied_target_features: |tcx, feature: Symbol| {
192192
let feature = feature.as_str();
193-
UnordSet::from(tcx.sess.target.implied_target_features(std::iter::once(feature)))
193+
UnordSet::from(tcx.sess.target.implied_target_features(feature))
194194
.into_sorted_stable_ord()
195195
.into_iter()
196196
.map(|s| Symbol::intern(s))

compiler/rustc_target/src/target_features.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -768,17 +768,15 @@ impl Target {
768768
}
769769
}
770770

771-
pub fn implied_target_features<'a>(
772-
&self,
773-
base_features: impl Iterator<Item = &'a str>,
774-
) -> FxHashSet<&'a str> {
771+
// Note: the returned set includes `base_feature`.
772+
pub fn implied_target_features<'a>(&self, base_feature: &'a str) -> FxHashSet<&'a str> {
775773
let implied_features =
776774
self.rust_target_features().iter().map(|(f, _, i)| (f, i)).collect::<FxHashMap<_, _>>();
777775

778-
// implied target features have their own implied target features, so we traverse the
779-
// map until there are no more features to add
776+
// Implied target features have their own implied target features, so we traverse the
777+
// map until there are no more features to add.
780778
let mut features = FxHashSet::default();
781-
let mut new_features = base_features.collect::<Vec<&str>>();
779+
let mut new_features = vec![base_feature];
782780
while let Some(new_feature) = new_features.pop() {
783781
if features.insert(new_feature) {
784782
if let Some(implied_features) = implied_features.get(&new_feature) {

0 commit comments

Comments
 (0)