Skip to content

Commit 51345d2

Browse files
committed
format_args: Parse format string properly
1 parent 98fe315 commit 51345d2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

gcc/rust/expand/rust-macro-builtins.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,24 @@ tl::optional<AST::Fragment>
947947
MacroBuiltin::format_args_handler (location_t invoc_locus,
948948
AST::MacroInvocData &invoc)
949949
{
950-
Fmt::Pieces::collect ("heyo this {is} what I {} want to {3}, {parse}");
950+
auto fmt_expr
951+
= parse_single_string_literal (BuiltinMacro::FormatArgs,
952+
invoc.get_delim_tok_tree (), invoc_locus,
953+
invoc.get_expander ());
954+
955+
if (!fmt_expr)
956+
return AST::Fragment::create_error ();
957+
958+
// if it is not a literal, it's an eager macro invocation - return it
959+
if (!fmt_expr->is_literal ())
960+
{
961+
auto token_tree = invoc.get_delim_tok_tree ();
962+
return AST::Fragment ({AST::SingleASTNode (std::move (fmt_expr))},
963+
token_tree.to_token_stream ());
964+
}
965+
966+
auto format_string = fmt_expr->as_string ();
967+
auto pieces = Fmt::Pieces::collect (format_string);
951968

952969
return AST::Fragment::create_empty ();
953970
}

0 commit comments

Comments
 (0)