Skip to content

Commit a07cb23

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

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
@@ -359,7 +359,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
359359
#[allow(rustc::potential_query_instability)]
360360
features.extend(
361361
sess.target
362-
.implied_target_features(std::iter::once(feature.as_str()))
362+
.implied_target_features(feature.as_str())
363363
.iter()
364364
.map(|s| Symbol::intern(s)),
365365
);
@@ -372,7 +372,7 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
372372
features.retain(|f| {
373373
if sess
374374
.target
375-
.implied_target_features(std::iter::once(f.as_str()))
375+
.implied_target_features(f.as_str())
376376
.contains(&feature.as_str())
377377
{
378378
// If `f` if implies `feature`, then `!feature` implies `!f`, so we have to
@@ -680,7 +680,7 @@ pub(crate) fn global_llvm_features(
680680
for feature in sess.opts.cg.target_feature.split(',') {
681681
if let Some(feature) = feature.strip_prefix('+') {
682682
all_rust_features.extend(
683-
UnordSet::from(sess.target.implied_target_features(std::iter::once(feature)))
683+
UnordSet::from(sess.target.implied_target_features(feature))
684684
.to_sorted_stable_ord()
685685
.iter()
686686
.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
@@ -767,17 +767,15 @@ impl Target {
767767
}
768768
}
769769

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

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

0 commit comments

Comments
 (0)