From 188215b080fd7d18a1f0ba67bfc148e03ad39860 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 13 Apr 2017 17:11:45 +0800 Subject: Expand - Ordering of macro_use lookup --- src/expand/mod.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index df0a26f2..88d16216 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -109,7 +109,8 @@ void Expand_Attrs(::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate return e; } } - // TODO: Shouldn't this use the _last_ located macro? Allowing later (local) defininitions to override it? + // Find the last macro of this name (allows later #[macro_use] definitions to override) + const MacroRules* last_mac = nullptr; for( const auto& mri : mac_mod.macro_imports_res() ) { //DEBUG("- " << mri.name); @@ -118,10 +119,14 @@ void Expand_Attrs(::AST::MetaItems& attrs, AttrStage stage, ::AST::Crate& crate if( input_ident != "" ) ERROR(mi_span, E0000, "macro_rules! macros can't take an ident"); - auto e = Macro_Invoke(name.c_str(), *mri.data, mv$(input_tt), mod); - return e; + last_mac = mri.data; } } + if( last_mac ) + { + auto e = Macro_Invoke(name.c_str(), *last_mac, mv$(input_tt), mod); + return e; + } } // Error - Unknown macro name -- cgit v1.2.3