1
Fork 0

Introduce Enabled{Lang,Lib}Feature

Instead of passing around random n-tuples of e.g. `(gate_name, attr_sp,
since)`.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-10-24 23:53:08 +08:00
parent 5ae4d75eff
commit 3528149f73
7 changed files with 101 additions and 51 deletions

View file

@ -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};
@ -937,25 +937,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.
@ -987,7 +987,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>,
@ -1057,7 +1057,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() {