Skip to content

Commit f9b5859

Browse files
committed
resolve: Simplify built-in macro table
1 parent 34628e5 commit f9b5859

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ extern crate proc_macro;
1414

1515
use crate::deriving::*;
1616

17-
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtension, SyntaxExtensionKind};
17+
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
1818
use rustc_expand::proc_macro::BangProcMacro;
19-
use rustc_span::edition::Edition;
20-
use rustc_span::symbol::{sym, Ident};
19+
use rustc_span::symbol::sym;
2120

2221
mod asm;
2322
mod assert;
@@ -44,13 +43,8 @@ pub mod proc_macro_harness;
4443
pub mod standard_library_imports;
4544
pub mod test_harness;
4645

47-
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Edition) {
48-
let mut register = |name, kind| {
49-
resolver.register_builtin_macro(
50-
Ident::with_dummy_span(name),
51-
SyntaxExtension::default(kind, edition),
52-
)
53-
};
46+
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
47+
let mut register = |name, kind| resolver.register_builtin_macro(name, kind);
5448
macro register_bang($($name:ident: $f:expr,)*) {
5549
$(register(sym::$name, SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)));)*
5650
}

compiler/rustc_expand/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ pub trait ResolverExpand {
868868

869869
fn resolve_dollar_crates(&mut self);
870870
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment);
871-
fn register_builtin_macro(&mut self, ident: Ident, ext: SyntaxExtension);
871+
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind);
872872

873873
fn expansion_for_ast_pass(
874874
&mut self,

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fn configure_and_expand_inner<'a>(
236236
pre_expansion_lint(sess, lint_store, &krate);
237237

238238
let mut resolver = Resolver::new(sess, &krate, crate_name, metadata_loader, &resolver_arenas);
239-
rustc_builtin_macros::register_builtin_macros(&mut resolver, sess.edition());
239+
rustc_builtin_macros::register_builtin_macros(&mut resolver);
240240

241241
krate = sess.time("crate_injection", || {
242242
let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s));

compiler/rustc_resolve/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
3333
use rustc_data_structures::ptr_key::PtrKey;
3434
use rustc_data_structures::sync::Lrc;
3535
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
36-
use rustc_expand::base::SyntaxExtension;
36+
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
3737
use rustc_hir::def::Namespace::*;
3838
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
3939
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
@@ -870,7 +870,7 @@ pub struct ExternPreludeEntry<'a> {
870870

871871
/// Used for better errors for E0773
872872
enum BuiltinMacroState {
873-
NotYetSeen(SyntaxExtension),
873+
NotYetSeen(SyntaxExtensionKind),
874874
AlreadySeen(Span),
875875
}
876876

compiler/rustc_resolve/src/macros.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use rustc_data_structures::fx::FxHashSet;
1414
use rustc_data_structures::ptr_key::PtrKey;
1515
use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::struct_span_err;
17-
use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand, SyntaxExtension};
17+
use rustc_expand::base::{Indeterminate, InvocationRes, ResolverExpand};
18+
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1819
use rustc_expand::compile_declarative_macro;
1920
use rustc_expand::expand::{AstFragment, Invocation, InvocationKind};
2021
use rustc_feature::is_builtin_attr_name;
@@ -176,10 +177,11 @@ impl<'a> ResolverExpand for Resolver<'a> {
176177
parent_scope.module.unexpanded_invocations.borrow_mut().remove(&expansion);
177178
}
178179

179-
fn register_builtin_macro(&mut self, ident: Ident, ext: SyntaxExtension) {
180-
if self.builtin_macros.insert(ident.name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
180+
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) {
181+
if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
181182
self.session
182-
.span_err(ident.span, &format!("built-in macro `{}` was already defined", ident));
183+
.diagnostic()
184+
.bug(&format!("built-in macro `{}` was already registered", name));
183185
}
184186
}
185187

@@ -1096,7 +1098,7 @@ impl<'a> Resolver<'a> {
10961098
// while still taking everything else from the source code.
10971099
// If we already loaded this builtin macro, give a better error message than 'no such builtin macro'.
10981100
match mem::replace(builtin_macro, BuiltinMacroState::AlreadySeen(item.span)) {
1099-
BuiltinMacroState::NotYetSeen(ext) => result.kind = ext.kind,
1101+
BuiltinMacroState::NotYetSeen(ext) => result.kind = ext,
11001102
BuiltinMacroState::AlreadySeen(span) => {
11011103
struct_span_err!(
11021104
self.session,

0 commit comments

Comments
 (0)