Skip to content

Commit 03ac053

Browse files
committed
syntax: Remove NodeId from SyntaxExtension
1 parent 927a3e8 commit 03ac053

File tree

6 files changed

+20
-30
lines changed

6 files changed

+20
-30
lines changed

src/librustc_plugin/registry.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ impl<'a> Registry<'a> {
8484
/// Register a syntax extension of any kind.
8585
///
8686
/// This is the most general hook into `libsyntax`'s expansion behavior.
87-
pub fn register_syntax_extension(&mut self, name: ast::Name, mut extension: SyntaxExtension) {
88-
if extension.def_info.is_none() {
89-
extension.def_info = Some((ast::CRATE_NODE_ID, self.krate_span));
90-
}
87+
pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) {
9188
self.syntax_exts.push((name, extension));
9289
}
9390

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,10 +1666,7 @@ pub struct Resolver<'a> {
16661666
non_macro_attrs: [Lrc<SyntaxExtension>; 2],
16671667
macro_defs: FxHashMap<Mark, DefId>,
16681668
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
1669-
1670-
/// List of crate local macros that we need to warn about as being unused.
1671-
/// Right now this only includes macro_rules! macros, and macros 2.0.
1672-
unused_macros: FxHashSet<DefId>,
1669+
unused_macros: NodeMap<Span>,
16731670

16741671
/// Maps the `Mark` of an expansion to its containing module or block.
16751672
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
@@ -2009,7 +2006,7 @@ impl<'a> Resolver<'a> {
20092006
name_already_seen: FxHashMap::default(),
20102007
potentially_unused_imports: Vec::new(),
20112008
struct_constructors: Default::default(),
2012-
unused_macros: FxHashSet::default(),
2009+
unused_macros: Default::default(),
20132010
current_type_ascription: Vec::new(),
20142011
injected_crate: None,
20152012
}

src/librustc_resolve/macros.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::resolve_imports::ImportResolver;
99
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
1010
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
1111
use rustc::hir::map::{self, DefCollector};
12-
use rustc::{ty, lint};
13-
use rustc::{bug, span_bug};
12+
use rustc::{ty, lint, span_bug};
1413
use syntax::ast::{self, Ident};
1514
use syntax::attr;
1615
use syntax::errors::DiagnosticBuilder;
@@ -259,14 +258,10 @@ impl<'a> base::Resolver for Resolver<'a> {
259258
}
260259

261260
fn check_unused_macros(&self) {
262-
for did in self.unused_macros.iter() {
263-
if let Some((id, span)) = self.macro_map[did].def_info {
264-
let lint = lint::builtin::UNUSED_MACROS;
265-
let msg = "unused macro definition";
266-
self.session.buffer_lint(lint, id, span, msg);
267-
} else {
268-
bug!("attempted to create unused macro error, but span not available");
269-
}
261+
for (&node_id, &span) in self.unused_macros.iter() {
262+
self.session.buffer_lint(
263+
lint::builtin::UNUSED_MACROS, node_id, span, "unused macro definition"
264+
);
270265
}
271266
}
272267
}
@@ -323,7 +318,9 @@ impl<'a> Resolver<'a> {
323318

324319
match res {
325320
Res::Def(DefKind::Macro(macro_kind), def_id) => {
326-
self.unused_macros.remove(&def_id);
321+
if let Some(node_id) = self.definitions.as_local_node_id(def_id) {
322+
self.unused_macros.remove(&node_id);
323+
}
327324
if macro_kind == MacroKind::ProcMacroStub {
328325
let msg = "can't use a procedural macro from the same crate that defines it";
329326
self.session.span_err(path.span, msg);
@@ -1157,13 +1154,13 @@ impl<'a> Resolver<'a> {
11571154
(res, vis, item.span, expansion, IsMacroExport));
11581155
} else {
11591156
self.check_reserved_macro_name(ident, res);
1160-
self.unused_macros.insert(def_id);
1157+
self.unused_macros.insert(item.id, item.span);
11611158
}
11621159
} else {
11631160
let module = self.current_module;
11641161
let vis = self.resolve_visibility(&item.vis);
11651162
if vis != ty::Visibility::Public {
1166-
self.unused_macros.insert(def_id);
1163+
self.unused_macros.insert(item.id, item.span);
11671164
}
11681165
self.define(module, ident, MacroNS, (res, vis, item.span, expansion));
11691166
}

src/libsyntax/ext/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ pub enum SyntaxExtensionKind {
606606
pub struct SyntaxExtension {
607607
/// A syntax extension kind.
608608
pub kind: SyntaxExtensionKind,
609-
/// Some info about the macro's definition point.
610-
pub def_info: Option<(ast::NodeId, Span)>,
609+
/// Span of the macro definition.
610+
pub span: Span,
611611
/// Hygienic properties of spans produced by this macro by default.
612612
pub default_transparency: Transparency,
613613
/// Whitelist of unstable features that are treated as stable inside this macro.
@@ -657,7 +657,7 @@ impl SyntaxExtension {
657657
/// Constructs a syntax extension with default properties.
658658
pub fn default(kind: SyntaxExtensionKind, edition: Edition) -> SyntaxExtension {
659659
SyntaxExtension {
660-
def_info: None,
660+
span: DUMMY_SP,
661661
default_transparency: kind.default_transparency(),
662662
allow_internal_unstable: None,
663663
allow_internal_unsafe: false,
@@ -681,7 +681,7 @@ impl SyntaxExtension {
681681
ExpnInfo {
682682
call_site,
683683
format: self.expn_format(Symbol::intern(format)),
684-
def_site: self.def_info.map(|(_, span)| span),
684+
def_site: Some(self.span),
685685
default_transparency: self.default_transparency,
686686
allow_internal_unstable: self.allow_internal_unstable.clone(),
687687
allow_internal_unsafe: self.allow_internal_unsafe,

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
673673
if let Some((feature, issue)) = ext.unstable_feature {
674674
let crate_span = this.cx.current_expansion.crate_span.unwrap();
675675
// don't stability-check macros in the same crate
676-
// (the only time this is null is for syntax extensions registered as macros)
677-
if ext.def_info.map_or(false, |(_, def_span)| !crate_span.contains(def_span))
676+
if !crate_span.contains(ext.span)
678677
&& !span.allows_unstable(feature)
679678
&& this.cx.ecfg.features.map_or(true, |feats| {
680679
// macro features will count as lib features
@@ -699,7 +698,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
699698
self.cx,
700699
span,
701700
mac.node.stream(),
702-
ext.def_info.map(|(_, s)| s),
701+
Some(ext.span),
703702
))
704703
}
705704
}

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub fn compile(
442442

443443
SyntaxExtension {
444444
kind: SyntaxExtensionKind::LegacyBang(expander),
445-
def_info: Some((def.id, def.span)),
445+
span: def.span,
446446
default_transparency,
447447
allow_internal_unstable,
448448
allow_internal_unsafe,

0 commit comments

Comments
 (0)