Skip to content

Commit 921f3df

Browse files
committed
Simplify implied_target_features.
Currently its argument is an iterator, but in practice it's always a singleton.
1 parent 4a5c717 commit 921f3df

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
357357
#[allow(rustc::potential_query_instability)]
358358
features.extend(
359359
sess.target
360-
.implied_target_features(std::iter::once(feature.as_str()))
360+
.implied_target_features(feature.as_str())
361361
.iter()
362362
.map(|s| Symbol::intern(s)),
363363
);
@@ -370,7 +370,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
370370
features.retain(|f| {
371371
if sess
372372
.target
373-
.implied_target_features(std::iter::once(f.as_str()))
373+
.implied_target_features(f.as_str())
374374
.contains(&feature.as_str())
375375
{
376376
// If `f` if implies `feature`, then `!feature` implies `!f`, so we have to
@@ -678,7 +678,7 @@ pub(crate) fn global_llvm_features(
678678
for feature in sess.opts.cg.target_feature.split(',') {
679679
if let Some(feature) = feature.strip_prefix('+') {
680680
all_rust_features.extend(
681-
UnordSet::from(sess.target.implied_target_features(std::iter::once(feature)))
681+
UnordSet::from(sess.target.implied_target_features(feature))
682682
.to_sorted_stable_ord()
683683
.iter()
684684
.map(|&&s| (true, s)),

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub(crate) fn provide(providers: &mut Providers) {
158158
},
159159
implied_target_features: |tcx, feature: Symbol| {
160160
let feature = feature.as_str();
161-
UnordSet::from(tcx.sess.target.implied_target_features(std::iter::once(feature)))
161+
UnordSet::from(tcx.sess.target.implied_target_features(feature))
162162
.into_sorted_stable_ord()
163163
.into_iter()
164164
.map(|s| Symbol::intern(s))

compiler/rustc_target/src/target_features.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,17 +762,15 @@ impl Target {
762762
}
763763
}
764764

765-
pub fn implied_target_features<'a>(
766-
&self,
767-
base_features: impl Iterator<Item = &'a str>,
768-
) -> FxHashSet<&'a str> {
765+
// Note: the returned set includes `base_feature`.
766+
pub fn implied_target_features<'a>(&self, base_feature: &'a str) -> FxHashSet<&'a str> {
769767
let implied_features =
770768
self.rust_target_features().iter().map(|(f, _, i)| (f, i)).collect::<FxHashMap<_, _>>();
771769

772-
// implied target features have their own implied target features, so we traverse the
773-
// map until there are no more features to add
770+
// Implied target features have their own implied target features, so we traverse the
771+
// map until there are no more features to add.
774772
let mut features = FxHashSet::default();
775-
let mut new_features = base_features.collect::<Vec<&str>>();
773+
let mut new_features = vec![base_feature];
776774
while let Some(new_feature) = new_features.pop() {
777775
if features.insert(new_feature) {
778776
if let Some(implied_features) = implied_features.get(&new_feature) {

0 commit comments

Comments
 (0)