Skip to content

Commit 5768162

Browse files
committed
Move get_lib_features query in librustc_passes.
1 parent ec3a9f6 commit 5768162

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

Diff for: src/librustc/lib.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,30 @@ pub mod middle {
102102
pub mod exported_symbols;
103103
pub mod free_region;
104104
pub mod lang_items;
105-
pub mod lib_features;
105+
pub mod lib_features {
106+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
107+
use syntax::symbol::Symbol;
108+
109+
#[derive(HashStable)]
110+
pub struct LibFeatures {
111+
// A map from feature to stabilisation version.
112+
pub stable: FxHashMap<Symbol, Symbol>,
113+
pub unstable: FxHashSet<Symbol>,
114+
}
115+
116+
impl LibFeatures {
117+
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
118+
let mut all_features: Vec<_> = self
119+
.stable
120+
.iter()
121+
.map(|(f, s)| (*f, Some(*s)))
122+
.chain(self.unstable.iter().map(|f| (*f, None)))
123+
.collect();
124+
all_features.sort_unstable_by_key(|f| f.0.as_str());
125+
all_features
126+
}
127+
}
128+
}
106129
pub mod privacy;
107130
pub mod recursion_limit;
108131
pub mod region;

Diff for: src/librustc/ty/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2751,10 +2751,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
27512751
assert_eq!(id, LOCAL_CRATE);
27522752
tcx.crate_name
27532753
};
2754-
providers.get_lib_features = |tcx, id| {
2755-
assert_eq!(id, LOCAL_CRATE);
2756-
tcx.arena.alloc(middle::lib_features::collect(tcx))
2757-
};
27582754
providers.get_lang_items = |tcx, id| {
27592755
assert_eq!(id, LOCAL_CRATE);
27602756
tcx.arena.alloc(middle::lang_items::collect(tcx))

Diff for: src/librustc_passes/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod entry;
2727
pub mod hir_stats;
2828
mod intrinsicck;
2929
pub mod layout_test;
30+
mod lib_features;
3031
mod liveness;
3132
pub mod loops;
3233
mod reachable;
@@ -35,6 +36,7 @@ pub fn provide(providers: &mut Providers<'_>) {
3536
check_const::provide(providers);
3637
diagnostic_items::provide(providers);
3738
entry::provide(providers);
39+
lib_features::provide(providers);
3840
loops::provide(providers);
3941
liveness::provide(providers);
4042
intrinsicck::provide(providers);

Diff for: src/librustc_passes/lib_features.rs

+16-28
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,19 @@
44
// and `#[unstable (..)]`), but are not declared in one single location
55
// (unlike lang features), which means we need to collect them instead.
66

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;
1112
use syntax::ast::{Attribute, MetaItem, MetaItemKind};
1213
use syntax::symbol::Symbol;
1314
use syntax_pos::{sym, Span};
1415

1516
use rustc_error_codes::*;
1617

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() }
3920
}
4021

4122
pub struct LibFeatureCollector<'tcx> {
@@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> {
4526

4627
impl LibFeatureCollector<'tcx> {
4728
fn new(tcx: TyCtxt<'tcx>) -> LibFeatureCollector<'tcx> {
48-
LibFeatureCollector { tcx, lib_features: LibFeatures::new() }
29+
LibFeatureCollector { tcx, lib_features: new_lib_features() }
4930
}
5031

5132
fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
@@ -142,7 +123,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
142123
}
143124
}
144125

145-
pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
126+
fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
146127
let mut collector = LibFeatureCollector::new(tcx);
147128
let krate = tcx.hir().krate();
148129
for attr in krate.non_exported_macro_attrs {
@@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
151132
intravisit::walk_crate(&mut collector, krate);
152133
collector.lib_features
153134
}
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

Comments
 (0)