Skip to content

Commit 5742cdf

Browse files
Support #[rustc_builtin_macro = "builtin_name"]
1 parent 6198eb7 commit 5742cdf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

crates/hir_def/src/nameres/collector.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,18 @@ impl ModCollector<'_, '_> {
14021402

14031403
// Case 1: builtin macros
14041404
if attrs.by_key("rustc_builtin_macro").exists() {
1405+
// `#[rustc_builtin_macro = "builtin_name"]` overrides the `macro_rules!` name.
1406+
let name;
1407+
let name = match attrs.by_key("rustc_builtin_macro").string_value() {
1408+
Some(it) => {
1409+
// FIXME: a hacky way to create a Name from string.
1410+
name = tt::Ident { text: it.clone(), id: tt::TokenId::unspecified() }.as_name();
1411+
&name
1412+
}
1413+
None => &mac.name,
1414+
};
14051415
let krate = self.def_collector.def_map.krate;
1406-
if let Some(macro_id) = find_builtin_macro(&mac.name, krate, ast_id) {
1416+
if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) {
14071417
self.def_collector.define_macro_rules(
14081418
self.module_id,
14091419
mac.name.clone(),

0 commit comments

Comments
 (0)