Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions gcc/rust/metadata/rust-export-metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rust-ast-dump.h"
#include "rust-abi.h"
#include "rust-item.h"
#include "rust-macro.h"
#include "rust-object-export.h"

#include "md5.h"
Expand Down Expand Up @@ -111,14 +112,12 @@ ExportContext::emit_function (const HIR::Function &fn)
}

void
ExportContext::emit_macro (NodeId macro)
ExportContext::emit_macro (AST::MacroRulesDefinition &macro)
{
std::stringstream oss;
AST::Dump dumper (oss);

AST::Item *item = mappings.lookup_ast_item (macro).value ();

dumper.go (*item);
dumper.go (macro);

public_interface_buffer += oss.str ();
}
Expand Down Expand Up @@ -195,7 +194,7 @@ PublicInterface::gather_export_data ()
vis_item.accept_vis (visitor);
}

for (const auto &macro : mappings.get_exported_macros ())
for (auto &macro : mappings.get_exported_macros ())
context.emit_macro (macro);
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/metadata/rust-export-metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ExportContext
* directly refer to them using their NodeId. There's no need to keep an HIR
* node for them.
*/
void emit_macro (NodeId macro);
void emit_macro (AST::MacroRulesDefinition &macro);

const std::string &get_interface_buffer () const;

Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -925,10 +925,10 @@ Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc)
void
Mappings::insert_exported_macro (AST::MacroRulesDefinition &def)
{
exportedMacros.emplace_back (def.get_node_id ());
exportedMacros.emplace_back (def);
}

std::vector<NodeId> &
std::vector<AST::MacroRulesDefinition>
Mappings::get_exported_macros ()
{
return exportedMacros;
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/util/rust-hir-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Mappings
lookup_macro_invocation (AST::MacroInvocation &invoc);

void insert_exported_macro (AST::MacroRulesDefinition &def);
std::vector<NodeId> &get_exported_macros ();
std::vector<AST::MacroRulesDefinition> get_exported_macros ();

void insert_derive_proc_macros (CrateNum num,
std::vector<CustomDeriveProcMacro> macros);
Expand Down Expand Up @@ -408,7 +408,7 @@ class Mappings
std::map<NodeId, std::pair<AST::MacroRulesDefinition *, CrateNum>>
macroMappings;
std::map<NodeId, AST::MacroRulesDefinition *> macroInvocations;
std::vector<NodeId> exportedMacros;
std::vector<AST::MacroRulesDefinition> exportedMacros;

// Procedural macros
std::map<CrateNum, std::vector<CustomDeriveProcMacro>>
Expand Down
14 changes: 14 additions & 0 deletions gcc/testsuite/rust/compile/issue-3617.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
macro_rules! quote_tokens {
() => {
#[macro_export]
macro_rules! inner {
() => {
$crate::
}
}
};
}

pub fn main() {
quote_tokens!();
}
Loading