about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2019-12-27 18:52:36 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2019-12-29 16:18:05 +0100
commit57681628f9138a76302d0eb41cac69c44b00f75a (patch)
tree4a950c747f4a3f1ffa918b659d111bf04ed36027
parentec3a9f64f1e08520a486c2a1dfffca7bb7332d26 (diff)
downloadrust-57681628f9138a76302d0eb41cac69c44b00f75a.tar.gz
rust-57681628f9138a76302d0eb41cac69c44b00f75a.zip
Move get_lib_features query in librustc_passes.
-rw-r--r--src/librustc/lib.rs25
-rw-r--r--src/librustc/ty/context.rs4
-rw-r--r--src/librustc_passes/lib.rs2
-rw-r--r--src/librustc_passes/lib_features.rs44
4 files changed, 42 insertions, 33 deletions
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index 38dcbc8e3fb..35c20cdbaf5 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -102,7 +102,30 @@ pub mod middle {
     pub mod exported_symbols;
     pub mod free_region;
     pub mod lang_items;
-    pub mod lib_features;
+    pub mod lib_features {
+        use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+        use syntax::symbol::Symbol;
+
+        #[derive(HashStable)]
+        pub struct LibFeatures {
+            // A map from feature to stabilisation version.
+            pub stable: FxHashMap<Symbol, Symbol>,
+            pub unstable: FxHashSet<Symbol>,
+        }
+
+        impl LibFeatures {
+            pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
+                let mut all_features: Vec<_> = self
+                    .stable
+                    .iter()
+                    .map(|(f, s)| (*f, Some(*s)))
+                    .chain(self.unstable.iter().map(|f| (*f, None)))
+                    .collect();
+                all_features.sort_unstable_by_key(|f| f.0.as_str());
+                all_features
+            }
+        }
+    }
     pub mod privacy;
     pub mod recursion_limit;
     pub mod region;
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 566c814f947..69e3358d6f6 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -2751,10 +2751,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
         assert_eq!(id, LOCAL_CRATE);
         tcx.crate_name
     };
-    providers.get_lib_features = |tcx, id| {
-        assert_eq!(id, LOCAL_CRATE);
-        tcx.arena.alloc(middle::lib_features::collect(tcx))
-    };
     providers.get_lang_items = |tcx, id| {
         assert_eq!(id, LOCAL_CRATE);
         tcx.arena.alloc(middle::lang_items::collect(tcx))
diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs
index 1ac03122c4a..da781f2bae5 100644
--- a/src/librustc_passes/lib.rs
+++ b/src/librustc_passes/lib.rs
@@ -27,6 +27,7 @@ pub mod entry;
 pub mod hir_stats;
 mod intrinsicck;
 pub mod layout_test;
+mod lib_features;
 mod liveness;
 pub mod loops;
 mod reachable;
@@ -35,6 +36,7 @@ pub fn provide(providers: &mut Providers<'_>) {
     check_const::provide(providers);
     diagnostic_items::provide(providers);
     entry::provide(providers);
+    lib_features::provide(providers);
     loops::provide(providers);
     liveness::provide(providers);
     intrinsicck::provide(providers);
diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs
index b4ddb09861d..0b0183f3cce 100644
--- a/src/librustc_passes/lib_features.rs
+++ b/src/librustc_passes/lib_features.rs
@@ -4,38 +4,19 @@
 // and `#[unstable (..)]`), but are not declared in one single location
 // (unlike lang features), which means we need to collect them instead.
 
-use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
-use crate::ty::TyCtxt;
-use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_macros::HashStable;
+use rustc::hir::def_id::LOCAL_CRATE;
+use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
+use rustc::middle::lib_features::LibFeatures;
+use rustc::ty::query::Providers;
+use rustc::ty::TyCtxt;
 use syntax::ast::{Attribute, MetaItem, MetaItemKind};
 use syntax::symbol::Symbol;
 use syntax_pos::{sym, Span};
 
 use rustc_error_codes::*;
 
-#[derive(HashStable)]
-pub struct LibFeatures {
-    // A map from feature to stabilisation version.
-    pub stable: FxHashMap<Symbol, Symbol>,
-    pub unstable: FxHashSet<Symbol>,
-}
-
-impl LibFeatures {
-    fn new() -> LibFeatures {
-        LibFeatures { stable: Default::default(), unstable: Default::default() }
-    }
-
-    pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
-        let mut all_features: Vec<_> = self
-            .stable
-            .iter()
-            .map(|(f, s)| (*f, Some(*s)))
-            .chain(self.unstable.iter().map(|f| (*f, None)))
-            .collect();
-        all_features.sort_unstable_by_key(|f| f.0.as_str());
-        all_features
-    }
+fn new_lib_features() -> LibFeatures {
+    LibFeatures { stable: Default::default(), unstable: Default::default() }
 }
 
 pub struct LibFeatureCollector<'tcx> {
@@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> {
 
 impl LibFeatureCollector<'tcx> {
     fn new(tcx: TyCtxt<'tcx>) -> LibFeatureCollector<'tcx> {
-        LibFeatureCollector { tcx, lib_features: LibFeatures::new() }
+        LibFeatureCollector { tcx, lib_features: new_lib_features() }
     }
 
     fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
@@ -142,7 +123,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
     }
 }
 
-pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
+fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
     let mut collector = LibFeatureCollector::new(tcx);
     let krate = tcx.hir().krate();
     for attr in krate.non_exported_macro_attrs {
@@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
     intravisit::walk_crate(&mut collector, krate);
     collector.lib_features
 }
+
+pub fn provide(providers: &mut Providers<'_>) {
+    providers.get_lib_features = |tcx, id| {
+        assert_eq!(id, LOCAL_CRATE);
+        tcx.arena.alloc(collect(tcx))
+    };
+}