syntax: Remove `NodeId` from `SyntaxExtension`

This commit is contained in:
Vadim Petrochenkov 2019-06-20 11:52:31 +03:00
parent 927a3e873d
commit 03ac05338c
6 changed files with 20 additions and 30 deletions

View File

@ -84,10 +84,7 @@ impl<'a> Registry<'a> {
/// Register a syntax extension of any kind.
///
/// This is the most general hook into `libsyntax`'s expansion behavior.
pub fn register_syntax_extension(&mut self, name: ast::Name, mut extension: SyntaxExtension) {
if extension.def_info.is_none() {
extension.def_info = Some((ast::CRATE_NODE_ID, self.krate_span));
}
pub fn register_syntax_extension(&mut self, name: ast::Name, extension: SyntaxExtension) {
self.syntax_exts.push((name, extension));
}

View File

@ -1666,10 +1666,7 @@ pub struct Resolver<'a> {
non_macro_attrs: [Lrc<SyntaxExtension>; 2],
macro_defs: FxHashMap<Mark, DefId>,
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
/// List of crate local macros that we need to warn about as being unused.
/// Right now this only includes macro_rules! macros, and macros 2.0.
unused_macros: FxHashSet<DefId>,
unused_macros: NodeMap<Span>,
/// Maps the `Mark` of an expansion to its containing module or block.
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
@ -2009,7 +2006,7 @@ impl<'a> Resolver<'a> {
name_already_seen: FxHashMap::default(),
potentially_unused_imports: Vec::new(),
struct_constructors: Default::default(),
unused_macros: FxHashSet::default(),
unused_macros: Default::default(),
current_type_ascription: Vec::new(),
injected_crate: None,
}

View File

@ -9,8 +9,7 @@ use crate::resolve_imports::ImportResolver;
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
use rustc::hir::map::{self, DefCollector};
use rustc::{ty, lint};
use rustc::{bug, span_bug};
use rustc::{ty, lint, span_bug};
use syntax::ast::{self, Ident};
use syntax::attr;
use syntax::errors::DiagnosticBuilder;
@ -259,14 +258,10 @@ impl<'a> base::Resolver for Resolver<'a> {
}
fn check_unused_macros(&self) {
for did in self.unused_macros.iter() {
if let Some((id, span)) = self.macro_map[did].def_info {
let lint = lint::builtin::UNUSED_MACROS;
let msg = "unused macro definition";
self.session.buffer_lint(lint, id, span, msg);
} else {
bug!("attempted to create unused macro error, but span not available");
}
for (&node_id, &span) in self.unused_macros.iter() {
self.session.buffer_lint(
lint::builtin::UNUSED_MACROS, node_id, span, "unused macro definition"
);
}
}
}
@ -323,7 +318,9 @@ impl<'a> Resolver<'a> {
match res {
Res::Def(DefKind::Macro(macro_kind), def_id) => {
self.unused_macros.remove(&def_id);
if let Some(node_id) = self.definitions.as_local_node_id(def_id) {
self.unused_macros.remove(&node_id);
}
if macro_kind == MacroKind::ProcMacroStub {
let msg = "can't use a procedural macro from the same crate that defines it";
self.session.span_err(path.span, msg);
@ -1157,13 +1154,13 @@ impl<'a> Resolver<'a> {
(res, vis, item.span, expansion, IsMacroExport));
} else {
self.check_reserved_macro_name(ident, res);
self.unused_macros.insert(def_id);
self.unused_macros.insert(item.id, item.span);
}
} else {
let module = self.current_module;
let vis = self.resolve_visibility(&item.vis);
if vis != ty::Visibility::Public {
self.unused_macros.insert(def_id);
self.unused_macros.insert(item.id, item.span);
}
self.define(module, ident, MacroNS, (res, vis, item.span, expansion));
}

View File

@ -606,8 +606,8 @@ pub enum SyntaxExtensionKind {
pub struct SyntaxExtension {
/// A syntax extension kind.
pub kind: SyntaxExtensionKind,
/// Some info about the macro's definition point.
pub def_info: Option<(ast::NodeId, Span)>,
/// Span of the macro definition.
pub span: Span,
/// Hygienic properties of spans produced by this macro by default.
pub default_transparency: Transparency,
/// Whitelist of unstable features that are treated as stable inside this macro.
@ -657,7 +657,7 @@ impl SyntaxExtension {
/// Constructs a syntax extension with default properties.
pub fn default(kind: SyntaxExtensionKind, edition: Edition) -> SyntaxExtension {
SyntaxExtension {
def_info: None,
span: DUMMY_SP,
default_transparency: kind.default_transparency(),
allow_internal_unstable: None,
allow_internal_unsafe: false,
@ -681,7 +681,7 @@ impl SyntaxExtension {
ExpnInfo {
call_site,
format: self.expn_format(Symbol::intern(format)),
def_site: self.def_info.map(|(_, span)| span),
def_site: Some(self.span),
default_transparency: self.default_transparency,
allow_internal_unstable: self.allow_internal_unstable.clone(),
allow_internal_unsafe: self.allow_internal_unsafe,

View File

@ -673,8 +673,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
if let Some((feature, issue)) = ext.unstable_feature {
let crate_span = this.cx.current_expansion.crate_span.unwrap();
// don't stability-check macros in the same crate
// (the only time this is null is for syntax extensions registered as macros)
if ext.def_info.map_or(false, |(_, def_span)| !crate_span.contains(def_span))
if !crate_span.contains(ext.span)
&& !span.allows_unstable(feature)
&& this.cx.ecfg.features.map_or(true, |feats| {
// macro features will count as lib features
@ -699,7 +698,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
self.cx,
span,
mac.node.stream(),
ext.def_info.map(|(_, s)| s),
Some(ext.span),
))
}
}

View File

@ -442,7 +442,7 @@ pub fn compile(
SyntaxExtension {
kind: SyntaxExtensionKind::LegacyBang(expander),
def_info: Some((def.id, def.span)),
span: def.span,
default_transparency,
allow_internal_unstable,
allow_internal_unsafe,