Collect library features from non-exported macros

This commit is contained in:
Vadim Petrochenkov 2019-06-21 01:55:40 +03:00
parent 3b6370b4ab
commit 290475e837
5 changed files with 14 additions and 2 deletions

View File

@ -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;
}

View File

@ -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: _,

View File

@ -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

View File

@ -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
}

View File

@ -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;