auto invoc_stream = invoc_token_tree.to_token_stream ();
auto macro_rule_tokens = transcribe_tree.to_token_stream ();
- auto substitute_context = SubstituteCtx (invoc_stream, macro_rule_tokens,
- matched_fragments, definition);
+ auto substitute_context
+ = SubstituteCtx (invoc_stream, macro_rule_tokens, matched_fragments,
+ definition, invoc_token_tree.get_locus ());
std::vector<std::unique_ptr<AST::Token>> substituted_tokens
= substitute_context.substitute_tokens ();
if (*def_crate == current_crate)
{
expanded.push_back (std::make_unique<AST::Token> (
- Rust::Token::make_identifier (UNKNOWN_LOCATION, "crate")));
+ Rust::Token::make_identifier (origin, "crate")));
}
else
{
rust_assert (name);
expanded.push_back (std::make_unique<AST::Token> (
- Rust::Token::make (SCOPE_RESOLUTION, UNKNOWN_LOCATION)));
+ Rust::Token::make (SCOPE_RESOLUTION, origin)));
expanded.push_back (std::make_unique<AST::Token> (
- Rust::Token::make_identifier (UNKNOWN_LOCATION, std::string (*name))));
+ Rust::Token::make_identifier (origin, std::string (*name))));
}
return true;
}
auto substitute_context
- = SubstituteCtx (input, new_macro, sub_map, definition);
+ = SubstituteCtx (input, new_macro, sub_map, definition, origin);
auto new_tokens = substitute_context.substitute_tokens ();
// Skip the first repetition, but add the separator to the expanded
std::vector<std::unique_ptr<AST::Token>> ¯o;
std::map<std::string, MatchedFragmentContainer *> &fragments;
AST::MacroRulesDefinition &definition;
+ // Macro invocation location
+ location_t origin;
/**
* Find the repetition amount to use when expanding a repetition, and
SubstituteCtx (std::vector<std::unique_ptr<AST::Token>> &input,
std::vector<std::unique_ptr<AST::Token>> ¯o,
std::map<std::string, MatchedFragmentContainer *> &fragments,
- AST::MacroRulesDefinition &definition)
+ AST::MacroRulesDefinition &definition, location_t origin)
: input (input), macro (macro), fragments (fragments),
- definition (definition)
+ definition (definition), origin (origin)
{}
/**
--- /dev/null
+pub fn print(a: *const u8) {}
+#[macro_export]
+macro_rules! pr_warn (
+ ($($arg:tt)*) => (
+ $($crate::print($arg))*
+ )
+);
+
+fn main() {
+ pr_warn!("test\0", "test\0");
+ // { dg-error "expecting .;. but .identifier. found" "" { target *-*-* } .-1 }
+}