Give a better error message for duplicate built-in macros

Previously, this would say no such macro existed, but this was
misleading, since the macro _did_ exist, it was just already seen.

- Say where the macro was previously defined
- Add long-form error message
This commit is contained in:
Joshua Nelson 2020-08-31 00:04:01 -04:00
parent 022e1fe235
commit be2947d0b7
8 changed files with 112 additions and 8 deletions

View file

@ -867,6 +867,12 @@ pub struct ExternPreludeEntry<'a> {
pub introduced_by_item: bool,
}
/// Used for better errors for E0773
enum BuiltinMacroState {
NotYetSeen(SyntaxExtension),
AlreadySeen(Span),
}
/// The main resolver class.
///
/// This is the visitor that walks the whole crate.
@ -960,7 +966,7 @@ pub struct Resolver<'a> {
crate_loader: CrateLoader<'a>,
macro_names: FxHashSet<Ident>,
builtin_macros: FxHashMap<Symbol, SyntaxExtension>,
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
registered_attrs: FxHashSet<Ident>,
registered_tools: FxHashSet<Ident>,
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,