4
4
// and `#[unstable (..)]`), but are not declared in one single location
5
5
// (unlike lang features), which means we need to collect them instead.
6
6
7
- use crate :: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
8
- use crate :: ty:: TyCtxt ;
9
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
10
- use rustc_macros:: HashStable ;
7
+ use rustc:: hir:: def_id:: LOCAL_CRATE ;
8
+ use rustc:: hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
9
+ use rustc:: middle:: lib_features:: LibFeatures ;
10
+ use rustc:: ty:: query:: Providers ;
11
+ use rustc:: ty:: TyCtxt ;
11
12
use syntax:: ast:: { Attribute , MetaItem , MetaItemKind } ;
12
13
use syntax:: symbol:: Symbol ;
13
14
use syntax_pos:: { sym, Span } ;
14
15
15
16
use rustc_error_codes:: * ;
16
17
17
- #[ derive( HashStable ) ]
18
- pub struct LibFeatures {
19
- // A map from feature to stabilisation version.
20
- pub stable : FxHashMap < Symbol , Symbol > ,
21
- pub unstable : FxHashSet < Symbol > ,
22
- }
23
-
24
- impl LibFeatures {
25
- fn new ( ) -> LibFeatures {
26
- LibFeatures { stable : Default :: default ( ) , unstable : Default :: default ( ) }
27
- }
28
-
29
- pub fn to_vec ( & self ) -> Vec < ( Symbol , Option < Symbol > ) > {
30
- let mut all_features: Vec < _ > = self
31
- . stable
32
- . iter ( )
33
- . map ( |( f, s) | ( * f, Some ( * s) ) )
34
- . chain ( self . unstable . iter ( ) . map ( |f| ( * f, None ) ) )
35
- . collect ( ) ;
36
- all_features. sort_unstable_by_key ( |f| f. 0 . as_str ( ) ) ;
37
- all_features
38
- }
18
+ fn new_lib_features ( ) -> LibFeatures {
19
+ LibFeatures { stable : Default :: default ( ) , unstable : Default :: default ( ) }
39
20
}
40
21
41
22
pub struct LibFeatureCollector < ' tcx > {
@@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> {
45
26
46
27
impl LibFeatureCollector < ' tcx > {
47
28
fn new ( tcx : TyCtxt < ' tcx > ) -> LibFeatureCollector < ' tcx > {
48
- LibFeatureCollector { tcx, lib_features : LibFeatures :: new ( ) }
29
+ LibFeatureCollector { tcx, lib_features : new_lib_features ( ) }
49
30
}
50
31
51
32
fn extract ( & self , attr : & Attribute ) -> Option < ( Symbol , Option < Symbol > , Span ) > {
@@ -142,7 +123,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
142
123
}
143
124
}
144
125
145
- pub fn collect ( tcx : TyCtxt < ' _ > ) -> LibFeatures {
126
+ fn collect ( tcx : TyCtxt < ' _ > ) -> LibFeatures {
146
127
let mut collector = LibFeatureCollector :: new ( tcx) ;
147
128
let krate = tcx. hir ( ) . krate ( ) ;
148
129
for attr in krate. non_exported_macro_attrs {
@@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
151
132
intravisit:: walk_crate ( & mut collector, krate) ;
152
133
collector. lib_features
153
134
}
135
+
136
+ pub fn provide ( providers : & mut Providers < ' _ > ) {
137
+ providers. get_lib_features = |tcx, id| {
138
+ assert_eq ! ( id, LOCAL_CRATE ) ;
139
+ tcx. arena . alloc ( collect ( tcx) )
140
+ } ;
141
+ }
0 commit comments