Rollup merge of #80870 - petrochenkov:bmactable, r=oli-obk

resolve: Simplify built-in macro table

We don't use full `SyntaxExtension`s from the table, only `SyntaxExtensionKind`s, and `Ident` in `register_builtin_macro` always had dummy span. This PR removes unnecessary data from the table and related function signatures.

Noticed when reviewing #80850.
This commit is contained in:
Yuki Okushi 2021-01-12 07:59:13 +09:00 committed by GitHub
commit fd02c83bfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 19 deletions

View file

@ -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};
@ -874,7 +874,7 @@ pub struct ExternPreludeEntry<'a> {
/// Used for better errors for E0773
enum BuiltinMacroState {
NotYetSeen(SyntaxExtension),
NotYetSeen(SyntaxExtensionKind),
AlreadySeen(Span),
}

View file

@ -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));
}
}
@ -1097,7 +1099,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,