diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-21 01:55:40 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-07-07 13:04:07 +0300 |
| commit | 290475e837d7c485c524d059cda90e63435e63c3 (patch) | |
| tree | 6c44d232fa0e371bd84f18c44c6618b83003ce02 | |
| parent | 3b6370b4ab645d65e0729b3a419946a6f2f4d1cd (diff) | |
| download | rust-290475e837d7c485c524d059cda90e63435e63c3.tar.gz rust-290475e837d7c485c524d059cda90e63435e63c3.zip | |
Collect library features from non-exported macros
| -rw-r--r-- | src/librustc/hir/lowering.rs | 5 | ||||
| -rw-r--r-- | src/librustc/hir/map/collector.rs | 1 | ||||
| -rw-r--r-- | src/librustc/hir/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/lib_features.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/macros/macro-stability.rs | 2 |
5 files changed, 14 insertions, 2 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 271fac544a4..2a9fd58f84b 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -90,6 +90,7 @@ pub struct LoweringContext<'a> { impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>, bodies: BTreeMap<hir::BodyId, hir::Body>, exported_macros: Vec<hir::MacroDef>, + non_exported_macro_attrs: Vec<ast::Attribute>, trait_impls: BTreeMap<DefId, Vec<hir::HirId>>, @@ -252,6 +253,7 @@ pub fn lower_crate( trait_impls: BTreeMap::new(), modules: BTreeMap::new(), exported_macros: Vec::new(), + non_exported_macro_attrs: Vec::new(), catch_scopes: Vec::new(), loop_scopes: Vec::new(), is_in_loop_condition: false, @@ -662,6 +664,7 @@ impl<'a> LoweringContext<'a> { attrs, span: c.span, exported_macros: hir::HirVec::from(self.exported_macros), + non_exported_macro_attrs: hir::HirVec::from(self.non_exported_macro_attrs), items: self.items, trait_items: self.trait_items, impl_items: self.impl_items, @@ -4022,6 +4025,8 @@ impl<'a> LoweringContext<'a> { body, legacy: def.legacy, }); + } else { + self.non_exported_macro_attrs.extend(attrs.into_iter()); } return None; } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 8a59f6b69bc..12ea772c1fb 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -119,6 +119,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { span, // These fields are handled separately: exported_macros: _, + non_exported_macro_attrs: _, items: _, trait_items: _, impl_items: _, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 7b760a87238..e7b37d40b4b 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -727,6 +727,8 @@ pub struct Crate { pub attrs: HirVec<Attribute>, pub span: Span, pub exported_macros: HirVec<MacroDef>, + // Attributes from non-exported macros, kept only for collecting the library feature list. + pub non_exported_macro_attrs: HirVec<Attribute>, // N.B., we use a BTreeMap here so that `visit_all_items` iterates // over the ids in increasing order. In principle it should not diff --git a/src/librustc/middle/lib_features.rs b/src/librustc/middle/lib_features.rs index 694b0a98629..0d6d016e507 100644 --- a/src/librustc/middle/lib_features.rs +++ b/src/librustc/middle/lib_features.rs @@ -144,6 +144,10 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> { pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures { let mut collector = LibFeatureCollector::new(tcx); - intravisit::walk_crate(&mut collector, tcx.hir().krate()); + let krate = tcx.hir().krate(); + for attr in &krate.non_exported_macro_attrs { + collector.visit_attribute(attr); + } + intravisit::walk_crate(&mut collector, krate); collector.lib_features } diff --git a/src/test/run-pass/macros/macro-stability.rs b/src/test/run-pass/macros/macro-stability.rs index b471aa655e9..817bddf6956 100644 --- a/src/test/run-pass/macros/macro-stability.rs +++ b/src/test/run-pass/macros/macro-stability.rs @@ -1,7 +1,7 @@ // run-pass // aux-build:unstable-macros.rs -#![feature(unstable_macros)] +#![feature(unstable_macros, local_unstable)] #[macro_use] extern crate unstable_macros; |
