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(
165
165
if let Some ( Feature { since, .. } ) = ACCEPTED_FEATURES . iter ( ) . find ( |f| name == f. name ) {
166
166
let since = Some ( Symbol :: intern ( since) ) ;
167
167
features. declared_lang_features . push ( ( name, mi. span ( ) , since) ) ;
168
+ features. active_features . insert ( name) ;
168
169
continue ;
169
170
}
170
171
@@ -185,10 +186,12 @@ fn get_features(
185
186
if let Some ( f) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. name ) {
186
187
f. set ( & mut features, mi. span ( ) ) ;
187
188
features. declared_lang_features . push ( ( name, mi. span ( ) , None ) ) ;
189
+ features. active_features . insert ( name) ;
188
190
continue ;
189
191
}
190
192
191
193
features. declared_lib_features . push ( ( name, mi. span ( ) ) ) ;
194
+ features. active_features . insert ( name) ;
192
195
}
193
196
}
194
197
Original file line number Diff line number Diff line change 2
2
3
3
use super :: { to_nonzero, Feature , State } ;
4
4
5
+ use rustc_data_structures:: fx:: FxHashSet ;
5
6
use rustc_span:: edition:: Edition ;
6
7
use rustc_span:: symbol:: { sym, Symbol } ;
7
8
use rustc_span:: Span ;
@@ -47,6 +48,8 @@ macro_rules! declare_features {
47
48
pub declared_lang_features: Vec <( Symbol , Span , Option <Symbol >) >,
48
49
/// `#![feature]` attrs for non-language (library) features.
49
50
pub declared_lib_features: Vec <( Symbol , Span ) >,
51
+ /// Features enabled for this crate.
52
+ pub active_features: FxHashSet <Symbol >,
50
53
$(
51
54
$( #[ doc = $doc] ) *
52
55
pub $feature: bool
@@ -58,6 +61,11 @@ macro_rules! declare_features {
58
61
$( f( stringify!( $feature) , self . $feature) ; ) +
59
62
}
60
63
64
+ /// Is the given feature active?
65
+ pub fn active( & self , feature: Symbol ) -> bool {
66
+ self . active_features. contains( & feature)
67
+ }
68
+
61
69
/// Is the given feature enabled?
62
70
///
63
71
/// 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::*;
6
6
use crate :: ty:: { self , DefIdTree , TyCtxt } ;
7
7
use rustc_ast:: NodeId ;
8
8
use rustc_attr:: { self as attr, ConstStability , Deprecation , Stability } ;
9
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
9
+ use rustc_data_structures:: fx:: FxHashMap ;
10
10
use rustc_errors:: { Applicability , Diagnostic } ;
11
11
use rustc_feature:: GateIssue ;
12
12
use rustc_hir as hir;
@@ -66,9 +66,6 @@ pub struct Index {
66
66
67
67
/// Maps for each crate whether it is part of the staged API.
68
68
pub staged_api : FxHashMap < CrateNum , bool > ,
69
-
70
- /// Features enabled for this crate.
71
- pub active_features : FxHashSet < Symbol > ,
72
69
}
73
70
74
71
impl Index {
@@ -423,7 +420,7 @@ impl<'tcx> TyCtxt<'tcx> {
423
420
debug ! ( "stability: skipping span={:?} since it is internal" , span) ;
424
421
return EvalResult :: Allow ;
425
422
}
426
- if self . stability ( ) . active_features . contains ( & feature) {
423
+ if self . features ( ) . active ( feature) {
427
424
return EvalResult :: Allow ;
428
425
}
429
426
Original file line number Diff line number Diff line change @@ -663,19 +663,8 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
663
663
stab_map : Default :: default ( ) ,
664
664
const_stab_map : Default :: default ( ) ,
665
665
depr_map : Default :: default ( ) ,
666
- active_features : Default :: default ( ) ,
667
666
} ;
668
667
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
-
679
668
{
680
669
let mut annotator = Annotator {
681
670
tcx,
You can’t perform that action at this time.
0 commit comments