Skip to content

Commit ff2e6f1

Browse files
committed
Auto merge of #53444 - varkor:lib_features-conditional, r=<try>
[WIP] Only fetch lib_features when there are unknown feature attributes An attempt to win back some of the performance lost in #52644 (comment). cc @nnethercote
2 parents bf1e461 + 00ddfc8 commit ff2e6f1

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/librustc/middle/lib_features.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use ty::TyCtxt;
1818
use syntax::symbol::Symbol;
1919
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
20-
use syntax_pos::{Span, DUMMY_SP};
20+
use syntax_pos::Span;
2121
use hir::intravisit::{self, NestedVisitorMap, Visitor};
2222
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
2323
use errors::DiagnosticId;
@@ -152,11 +152,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LibFeatureCollector<'a, 'tcx> {
152152

153153
pub fn collect<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> LibFeatures {
154154
let mut collector = LibFeatureCollector::new(tcx);
155-
for &cnum in tcx.crates().iter() {
156-
for &(feature, since) in tcx.defined_lib_features(cnum).iter() {
157-
collector.collect_feature(feature, since, DUMMY_SP);
158-
}
159-
}
160155
intravisit::walk_crate(&mut collector, tcx.hir.krate());
161156
collector.lib_features
162157
}

src/librustc/middle/stability.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,34 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
846846
remaining_lib_features.remove(&Symbol::intern("libc"));
847847
remaining_lib_features.remove(&Symbol::intern("test"));
848848

849-
for (feature, stable) in tcx.lib_features().to_vec() {
850-
if let Some(since) = stable {
851-
if let Some(span) = remaining_lib_features.get(&feature) {
852-
// Warn if the user has enabled an already-stable lib feature.
853-
unnecessary_stable_feature_lint(tcx, *span, feature, since);
849+
let check_features =
850+
|remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &Vec<_>| {
851+
for &(feature, since) in defined_features {
852+
if let Some(since) = since {
853+
if let Some(span) = remaining_lib_features.get(&feature) {
854+
// Warn if the user has enabled an already-stable lib feature.
855+
unnecessary_stable_feature_lint(tcx, *span, feature, since);
856+
}
857+
}
858+
remaining_lib_features.remove(&feature);
859+
if remaining_lib_features.is_empty() {
860+
break;
861+
}
862+
}
863+
};
864+
865+
// We always collect the lib features declared in the current crate, even if there are
866+
// no unknown features, because the collection also does feature attribute validation.
867+
let local_defined_features = tcx.lib_features().to_vec();
868+
if !remaining_lib_features.is_empty() {
869+
check_features(&mut remaining_lib_features, &local_defined_features);
870+
871+
for &cnum in &*tcx.crates() {
872+
if remaining_lib_features.is_empty() {
873+
break;
854874
}
875+
check_features(&mut remaining_lib_features, &tcx.defined_lib_features(cnum));
855876
}
856-
remaining_lib_features.remove(&feature);
857877
}
858878

859879
for (feature, span) in remaining_lib_features {

0 commit comments

Comments
 (0)