File tree Expand file tree Collapse file tree 4 files changed +13
-16
lines changed Expand file tree Collapse file tree 4 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ fn get_features(
165165 if let Some ( Feature { since, .. } ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
166166 let since = Some ( Symbol :: intern ( since) ) ;
167167 features. declared_lang_features . push ( ( name, mi. span ( ) , since) ) ;
168+ features. active_features . insert ( name) ;
168169 continue ;
169170 }
170171
@@ -185,10 +186,12 @@ fn get_features(
185186 if let Some ( f) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. name ) {
186187 f. set ( & mut features, mi. span ( ) ) ;
187188 features. declared_lang_features . push ( ( name, mi. span ( ) , None ) ) ;
189+ features. active_features . insert ( name) ;
188190 continue ;
189191 }
190192
191193 features. declared_lib_features . push ( ( name, mi. span ( ) ) ) ;
194+ features. active_features . insert ( name) ;
192195 }
193196 }
194197
Original file line number Diff line number Diff line change 22
33use super :: { to_nonzero, Feature , State } ;
44
5+ use rustc_data_structures:: fx:: FxHashSet ;
56use rustc_span:: edition:: Edition ;
67use rustc_span:: symbol:: { sym, Symbol } ;
78use rustc_span:: Span ;
@@ -47,6 +48,8 @@ macro_rules! declare_features {
4748 pub declared_lang_features: Vec <( Symbol , Span , Option <Symbol >) >,
4849 /// `#![feature]` attrs for non-language (library) features.
4950 pub declared_lib_features: Vec <( Symbol , Span ) >,
51+ /// Features enabled for this crate.
52+ pub active_features: FxHashSet <Symbol >,
5053 $(
5154 $( #[ doc = $doc] ) *
5255 pub $feature: bool
@@ -58,6 +61,11 @@ macro_rules! declare_features {
5861 $( f( stringify!( $feature) , self . $feature) ; ) +
5962 }
6063
64+ /// Is the given feature active?
65+ pub fn active( & self , feature: Symbol ) -> bool {
66+ self . active_features. contains( & feature)
67+ }
68+
6169 /// Is the given feature enabled?
6270 ///
6371 /// Panics if the symbol doesn't correspond to a declared feature.
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ pub use self::StabilityLevel::*;
66use crate :: ty:: { self , DefIdTree , TyCtxt } ;
77use rustc_ast:: NodeId ;
88use rustc_attr:: { self as attr, ConstStability , Deprecation , Stability } ;
9- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
9+ use rustc_data_structures:: fx:: FxHashMap ;
1010use rustc_errors:: { Applicability , Diagnostic } ;
1111use rustc_feature:: GateIssue ;
1212use rustc_hir as hir;
@@ -66,9 +66,6 @@ pub struct Index {
6666
6767 /// Maps for each crate whether it is part of the staged API.
6868 pub staged_api : FxHashMap < CrateNum , bool > ,
69-
70- /// Features enabled for this crate.
71- pub active_features : FxHashSet < Symbol > ,
7269}
7370
7471impl Index {
@@ -423,7 +420,7 @@ impl<'tcx> TyCtxt<'tcx> {
423420 debug ! ( "stability: skipping span={:?} since it is internal" , span) ;
424421 return EvalResult :: Allow ;
425422 }
426- if self . stability ( ) . active_features . contains ( & feature) {
423+ if self . features ( ) . active ( feature) {
427424 return EvalResult :: Allow ;
428425 }
429426
Original file line number Diff line number Diff line change @@ -663,19 +663,8 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
663663 stab_map : Default :: default ( ) ,
664664 const_stab_map : Default :: default ( ) ,
665665 depr_map : Default :: default ( ) ,
666- active_features : Default :: default ( ) ,
667666 } ;
668667
669- let active_lib_features = & tcx. features ( ) . declared_lib_features ;
670- let active_lang_features = & tcx. features ( ) . declared_lang_features ;
671-
672- // Put the active features into a map for quick lookup.
673- index. active_features = active_lib_features
674- . iter ( )
675- . map ( |& ( s, ..) | s)
676- . chain ( active_lang_features. iter ( ) . map ( |& ( s, ..) | s) )
677- . collect ( ) ;
678-
679668 {
680669 let mut annotator = Annotator {
681670 tcx,
You can’t perform that action at this time.
0 commit comments