Skip to content

Commit 290475e

Browse files
committed
Collect library features from non-exported macros
1 parent 3b6370b commit 290475e

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

src/librustc/hir/lowering.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct LoweringContext<'a> {
9090
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>,
9191
bodies: BTreeMap<hir::BodyId, hir::Body>,
9292
exported_macros: Vec<hir::MacroDef>,
93+
non_exported_macro_attrs: Vec<ast::Attribute>,
9394

9495
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
9596

@@ -252,6 +253,7 @@ pub fn lower_crate(
252253
trait_impls: BTreeMap::new(),
253254
modules: BTreeMap::new(),
254255
exported_macros: Vec::new(),
256+
non_exported_macro_attrs: Vec::new(),
255257
catch_scopes: Vec::new(),
256258
loop_scopes: Vec::new(),
257259
is_in_loop_condition: false,
@@ -662,6 +664,7 @@ impl<'a> LoweringContext<'a> {
662664
attrs,
663665
span: c.span,
664666
exported_macros: hir::HirVec::from(self.exported_macros),
667+
non_exported_macro_attrs: hir::HirVec::from(self.non_exported_macro_attrs),
665668
items: self.items,
666669
trait_items: self.trait_items,
667670
impl_items: self.impl_items,
@@ -4022,6 +4025,8 @@ impl<'a> LoweringContext<'a> {
40224025
body,
40234026
legacy: def.legacy,
40244027
});
4028+
} else {
4029+
self.non_exported_macro_attrs.extend(attrs.into_iter());
40254030
}
40264031
return None;
40274032
}

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
119119
span,
120120
// These fields are handled separately:
121121
exported_macros: _,
122+
non_exported_macro_attrs: _,
122123
items: _,
123124
trait_items: _,
124125
impl_items: _,

src/librustc/hir/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ pub struct Crate {
727727
pub attrs: HirVec<Attribute>,
728728
pub span: Span,
729729
pub exported_macros: HirVec<MacroDef>,
730+
// Attributes from non-exported macros, kept only for collecting the library feature list.
731+
pub non_exported_macro_attrs: HirVec<Attribute>,
730732

731733
// N.B., we use a BTreeMap here so that `visit_all_items` iterates
732734
// over the ids in increasing order. In principle it should not

src/librustc/middle/lib_features.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
144144

145145
pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures {
146146
let mut collector = LibFeatureCollector::new(tcx);
147-
intravisit::walk_crate(&mut collector, tcx.hir().krate());
147+
let krate = tcx.hir().krate();
148+
for attr in &krate.non_exported_macro_attrs {
149+
collector.visit_attribute(attr);
150+
}
151+
intravisit::walk_crate(&mut collector, krate);
148152
collector.lib_features
149153
}

src/test/run-pass/macros/macro-stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22
// aux-build:unstable-macros.rs
33

4-
#![feature(unstable_macros)]
4+
#![feature(unstable_macros, local_unstable)]
55

66
#[macro_use] extern crate unstable_macros;
77

0 commit comments

Comments
 (0)