Rollup merge of #132114 - jieyouxu:features-bundle, r=fee1-dead
Use `Enabled{Lang,Lib}Feature` instead of n-tuples Instead of passing around e.g. `(gate_name, attr_span, stable_since)` 3-tuples for enabled lang features or `(gate_name, attr_span)` 2-tuples for enabled lib features, use `Enabled{Lang,Lib}Feature` structs with named fields. Also did some minor code-golfing of involved iterator chains to hopefully make them easier to follow. Follow-up to https://github.com/rust-lang/rust/pull/132098#issuecomment-2434523431 cc `@RalfJung.`
This commit is contained in:
commit
8207d89b5e
7 changed files with 101 additions and 51 deletions
|
@ -10,7 +10,7 @@ use rustc_attr::{
|
|||
};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::unord::{ExtendUnord, UnordMap, UnordSet};
|
||||
use rustc_feature::ACCEPTED_LANG_FEATURES;
|
||||
use rustc_feature::{ACCEPTED_LANG_FEATURES, EnabledLangFeature, EnabledLibFeature};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalModDefId};
|
||||
|
@ -994,25 +994,25 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
|
||||
let enabled_lang_features = tcx.features().enabled_lang_features();
|
||||
let mut lang_features = UnordSet::default();
|
||||
for &(feature, span, since) in enabled_lang_features {
|
||||
if let Some(since) = since {
|
||||
for EnabledLangFeature { gate_name, attr_sp, stable_since } in enabled_lang_features {
|
||||
if let Some(version) = stable_since {
|
||||
// Warn if the user has enabled an already-stable lang feature.
|
||||
unnecessary_stable_feature_lint(tcx, span, feature, since);
|
||||
unnecessary_stable_feature_lint(tcx, *attr_sp, *gate_name, *version);
|
||||
}
|
||||
if !lang_features.insert(feature) {
|
||||
if !lang_features.insert(gate_name) {
|
||||
// Warn if the user enables a lang feature multiple times.
|
||||
tcx.dcx().emit_err(errors::DuplicateFeatureErr { span, feature });
|
||||
tcx.dcx().emit_err(errors::DuplicateFeatureErr { span: *attr_sp, feature: *gate_name });
|
||||
}
|
||||
}
|
||||
|
||||
let enabled_lib_features = tcx.features().enabled_lib_features();
|
||||
let mut remaining_lib_features = FxIndexMap::default();
|
||||
for (feature, span) in enabled_lib_features {
|
||||
if remaining_lib_features.contains_key(&feature) {
|
||||
for EnabledLibFeature { gate_name, attr_sp } in enabled_lib_features {
|
||||
if remaining_lib_features.contains_key(gate_name) {
|
||||
// Warn if the user enables a lib feature multiple times.
|
||||
tcx.dcx().emit_err(errors::DuplicateFeatureErr { span: *span, feature: *feature });
|
||||
tcx.dcx().emit_err(errors::DuplicateFeatureErr { span: *attr_sp, feature: *gate_name });
|
||||
}
|
||||
remaining_lib_features.insert(feature, *span);
|
||||
remaining_lib_features.insert(*gate_name, *attr_sp);
|
||||
}
|
||||
// `stdbuild` has special handling for `libc`, so we need to
|
||||
// recognise the feature when building std.
|
||||
|
@ -1044,7 +1044,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
/// time, less loading from metadata is performed and thus compiler performance is improved.
|
||||
fn check_features<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
remaining_lib_features: &mut FxIndexMap<&Symbol, Span>,
|
||||
remaining_lib_features: &mut FxIndexMap<Symbol, Span>,
|
||||
remaining_implications: &mut UnordMap<Symbol, Symbol>,
|
||||
defined_features: &LibFeatures,
|
||||
all_implications: &UnordMap<Symbol, Symbol>,
|
||||
|
@ -1114,7 +1114,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
}
|
||||
|
||||
for (feature, span) in remaining_lib_features {
|
||||
tcx.dcx().emit_err(errors::UnknownFeature { span, feature: *feature });
|
||||
tcx.dcx().emit_err(errors::UnknownFeature { span, feature });
|
||||
}
|
||||
|
||||
for (&implied_by, &feature) in remaining_implications.to_sorted_stable_ord() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue