mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
resolve: Simplify built-in macro table
This commit is contained in:
parent
34628e5b53
commit
f9b5859173
@ -14,10 +14,9 @@ extern crate proc_macro;
|
||||
|
||||
use crate::deriving::*;
|
||||
|
||||
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
|
||||
use rustc_expand::proc_macro::BangProcMacro;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::symbol::sym;
|
||||
|
||||
mod asm;
|
||||
mod assert;
|
||||
@ -44,13 +43,8 @@ pub mod proc_macro_harness;
|
||||
pub mod standard_library_imports;
|
||||
pub mod test_harness;
|
||||
|
||||
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Edition) {
|
||||
let mut register = |name, kind| {
|
||||
resolver.register_builtin_macro(
|
||||
Ident::with_dummy_span(name),
|
||||
SyntaxExtension::default(kind, edition),
|
||||
)
|
||||
};
|
||||
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
||||
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
|
||||
macro register_bang($($name:ident: $f:expr,)*) {
|
||||
$(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ pub trait ResolverExpand {
|
||||
|
||||
fn resolve_dollar_crates(&mut self);
|
||||
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment);
|
||||
fn register_builtin_macro(&mut self, ident: Ident, ext: SyntaxExtension);
|
||||
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
|
||||
|
||||
fn expansion_for_ast_pass(
|
||||
&mut self,
|
||||
|
@ -236,7 +236,7 @@ fn configure_and_expand_inner<'a>(
|
||||
pre_expansion_lint(sess, lint_store, &krate);
|
||||
|
||||
let mut resolver = Resolver::new(sess, &krate, crate_name, metadata_loader, &resolver_arenas);
|
||||
rustc_builtin_macros::register_builtin_macros(&mut resolver, sess.edition());
|
||||
rustc_builtin_macros::register_builtin_macros(&mut resolver);
|
||||
|
||||
krate = sess.time("crate_injection", || {
|
||||
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));
|
||||
|
@ -33,7 +33,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||
use rustc_data_structures::ptr_key::PtrKey;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
|
||||
use rustc_expand::base::SyntaxExtension;
|
||||
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_hir::def::Namespace::*;
|
||||
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
|
||||
@ -870,7 +870,7 @@ pub struct ExternPreludeEntry<'a> {
|
||||
|
||||
/// Used for better errors for E0773
|
||||
enum BuiltinMacroState {
|
||||
NotYetSeen(SyntaxExtension),
|
||||
NotYetSeen(SyntaxExtensionKind),
|
||||
AlreadySeen(Span),
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,8 @@ use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::ptr_key::PtrKey;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand, SyntaxExtension};
|
||||
use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand};
|
||||
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_expand::compile_declarative_macro;
|
||||
use rustc_expand::expand::{AstFragment, Invocation, InvocationKind};
|
||||
use rustc_feature::is_builtin_attr_name;
|
||||
@ -176,10 +177,11 @@ impl<'a> ResolverExpand for Resolver<'a> {
|
||||
parent_scope.module.unexpanded_invocations.borrow_mut().remove(&expansion);
|
||||
}
|
||||
|
||||
fn register_builtin_macro(&mut self, ident: Ident, ext: SyntaxExtension) {
|
||||
if self.builtin_macros.insert(ident.name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
|
||||
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) {
|
||||
if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
|
||||
self.session
|
||||
.span_err(ident.span, &format!("built-in macro `{}` was already defined", ident));
|
||||
.diagnostic()
|
||||
.bug(&format!("built-in macro `{}` was already registered", name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1096,7 +1098,7 @@ impl<'a> Resolver<'a> {
|
||||
// while still taking everything else from the source code.
|
||||
// If we already loaded this builtin macro, give a better error message than 'no such builtin macro'.
|
||||
match mem::replace(builtin_macro, BuiltinMacroState::AlreadySeen(item.span)) {
|
||||
BuiltinMacroState::NotYetSeen(ext) => result.kind = ext.kind,
|
||||
BuiltinMacroState::NotYetSeen(ext) => result.kind = ext,
|
||||
BuiltinMacroState::AlreadySeen(span) => {
|
||||
struct_span_err!(
|
||||
self.session,
|
||||
|
Loading…
Reference in New Issue
Block a user