diff options
author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-10-03 21:10:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-03 21:10:33 +0200 |
commit | 9e477c4386c35dbc59ce70f532cdd05288e1926f (patch) | |
tree | 4a910db1de359f0a088199888a36a91df705e186 | |
parent | 0d0b695b9f6bbf83794c382effce7a54a0b61eda (diff) | |
parent | a5c9030271d48456ffefca83a416f0ee863ba965 (diff) | |
download | rust-9e477c4386c35dbc59ce70f532cdd05288e1926f.tar.gz rust-9e477c4386c35dbc59ce70f532cdd05288e1926f.zip |
Rollup merge of #147277 - fee1-dead-contrib:featiter, r=Zalathar
Extract common logic for iterating over features Two places doing the same thing is enough to motivate me to extract this to a method :)
-rw-r--r-- | compiler/rustc_ast_passes/src/feature_gate.rs | 6 | ||||
-rw-r--r-- | compiler/rustc_feature/src/unstable.rs | 10 | ||||
-rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 8 |
3 files changed, 13 insertions, 11 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 608ccfefeb6..b8a29a9a08f 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -622,11 +622,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate) } fn check_incompatible_features(sess: &Session, features: &Features) { - let enabled_lang_features = - features.enabled_lang_features().iter().map(|feat| (feat.gate_name, feat.attr_sp)); - let enabled_lib_features = - features.enabled_lib_features().iter().map(|feat| (feat.gate_name, feat.attr_sp)); - let enabled_features = enabled_lang_features.chain(enabled_lib_features); + let enabled_features = features.enabled_features_iter_stable_order(); for (f1, f2) in rustc_feature::INCOMPATIBLE_FEATURES .iter() diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index e63f29a9570..8397cd294e0 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -93,6 +93,16 @@ impl Features { &self.enabled_features } + /// Returns a iterator of enabled features in stable order. + pub fn enabled_features_iter_stable_order( + &self, + ) -> impl Iterator<Item = (Symbol, Span)> + Clone { + self.enabled_lang_features + .iter() + .map(|feat| (feat.gate_name, feat.attr_sp)) + .chain(self.enabled_lib_features.iter().map(|feat| (feat.gate_name, feat.attr_sp))) + } + /// Is the given feature enabled (via `#[feature(...)]`)? pub fn enabled(&self, feature: Symbol) -> bool { self.enabled_features.contains(&feature) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 75a0f89321b..8a525eb11f7 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2331,13 +2331,9 @@ declare_lint_pass!( impl EarlyLintPass for IncompleteInternalFeatures { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) { let features = cx.builder.features(); - let lang_features = - features.enabled_lang_features().iter().map(|feat| (feat.gate_name, feat.attr_sp)); - let lib_features = - features.enabled_lib_features().iter().map(|feat| (feat.gate_name, feat.attr_sp)); - lang_features - .chain(lib_features) + features + .enabled_features_iter_stable_order() .filter(|(name, _)| features.incomplete(*name) || features.internal(*name)) .for_each(|(name, span)| { if features.incomplete(name) { |