From f88af6176e24e62670f33f3d119db02850c11af2 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Mon, 24 Feb 2025 13:09:17 +0100 Subject: expansion: Correctly expand $crate metavar gcc/rust/ChangeLog: * expand/rust-macro-expand.cc: Use new SubstituteCtx API. * expand/rust-macro-expand.h: Likewise. * expand/rust-macro-substitute-ctx.cc: Implement proper expansion of $crate. * expand/rust-macro-substitute-ctx.h: Adapt APIs to take macro definition when substituting. * util/rust-hir-map.cc (Mappings::insert_macro_def): Store crate information when inserting macro definition in mappings. (Mappings::lookup_macro_def_crate): New. * util/rust-hir-map.h: Adapt mappings to store crate in which macros were defined. gcc/testsuite/ChangeLog: * rust/execute/crate-metavar1.rs: New test. * rust/compile/crate-metavar1.rs: New test. --- gcc/rust/util/rust-hir-map.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/rust/util/rust-hir-map.h') diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 6f21f38..9fcb3c6 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -269,6 +269,7 @@ public: void insert_macro_def (AST::MacroRulesDefinition *macro); tl::optional lookup_macro_def (NodeId id); + tl::optional lookup_macro_def_crate (NodeId id); void insert_macro_invocation (AST::MacroInvocation &invoc, AST::MacroRulesDefinition *def); @@ -402,7 +403,8 @@ private: std::map> hirNodesWithinCrate; // MBE macros - std::map macroMappings; + std::map> + macroMappings; std::map macroInvocations; std::vector exportedMacros; -- cgit v1.1