Skip to content

Commit 89d9c81

Browse files
committed
don't stability-check macros in the same crate
1 parent 0610a4e commit 89d9c81

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ pub struct ExpansionData {
671671
pub depth: usize,
672672
pub module: Rc<ModuleData>,
673673
pub directory_ownership: DirectoryOwnership,
674+
pub crate_span: Option<Span>,
674675
}
675676

676677
/// One of these is made during expansion and incrementally updated as we go;
@@ -702,6 +703,7 @@ impl<'a> ExtCtxt<'a> {
702703
depth: 0,
703704
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
704705
directory_ownership: DirectoryOwnership::Owned { relative: None },
706+
crate_span: None,
705707
},
706708
expansions: HashMap::new(),
707709
}

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
229229
module.directory.pop();
230230
self.cx.root_path = module.directory.clone();
231231
self.cx.current_expansion.module = Rc::new(module);
232+
self.cx.current_expansion.crate_span = Some(krate.span);
232233

233234
let orig_mod_span = krate.module.inner;
234235

@@ -540,9 +541,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
540541

541542
// feature-gate the macro invocation
542543
if let Some((feature, issue)) = unstable_feature {
543-
// only if the outer span doesn't allow unstable invocations
544-
// TODO: compare crates of span and def_site_span (can't figure out how)
545-
if !span.allows_unstable() && self_.cx.ecfg.features.map_or(true, |feats| {
544+
let crate_span = self_.cx.current_expansion.crate_span.unwrap();
545+
// don't stability-check macros in the same crate
546+
if !crate_span.contains(def_site_span)
547+
&& !span.allows_unstable() && self_.cx.ecfg.features.map_or(true, |feats| {
546548
// macro features will count as lib features
547549
!feats.declared_lib_features.iter().any(|&(feat, _)| feat == feature)
548550
}) {

0 commit comments

Comments
 (0)