From 5742cdf3f1c591709e68d65c5701257cb77583db Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 3 Apr 2021 03:13:04 +0200 Subject: Support `#[rustc_builtin_macro = "builtin_name"]` --- crates/hir_def/src/nameres/collector.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 6f946a6dd..c8f494707 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -1402,8 +1402,18 @@ impl ModCollector<'_, '_> { // Case 1: builtin macros if attrs.by_key("rustc_builtin_macro").exists() { + // `#[rustc_builtin_macro = "builtin_name"]` overrides the `macro_rules!` name. + let name; + let name = match attrs.by_key("rustc_builtin_macro").string_value() { + Some(it) => { + // FIXME: a hacky way to create a Name from string. + name = tt::Ident { text: it.clone(), id: tt::TokenId::unspecified() }.as_name(); + &name + } + None => &mac.name, + }; let krate = self.def_collector.def_map.krate; - if let Some(macro_id) = find_builtin_macro(&mac.name, krate, ast_id) { + if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) { self.def_collector.define_macro_rules( self.module_id, mac.name.clone(), -- cgit v1.2.3