Skip to content

Fix compiling empty fmt! strings #7227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2013
Merged
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
5 changes: 5 additions & 0 deletions src/libsyntax/ext/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
}
}

/* Short circuit an easy case up front (won't work otherwise) */
if pieces.len() == 0 {
return cx.expr_str_uniq(args[0].span, @"");
}

let fmt_sp = args[0].span;
let mut n = 0u;
let nargs = args.len();
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-pass/syntax-extension-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ fn part1() {
test(fmt!("%x", 0xffffffff_u), ~"ffffffff");
test(fmt!("%o", 0xffffffff_u), ~"37777777777");
test(fmt!("%t", 0xffffffff_u), ~"11111111111111111111111111111111");

// Don't result in a compilation error
test(fmt!(""), ~"");
}
fn part2() {
// Widths
Expand Down