Skip to content

Commit df166ba

Browse files
committed
Merge pull request #7227 from alexcrichton/issue-7218
Fix compiling empty fmt! strings
2 parents ef07d7c + df626ea commit df166ba

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/libsyntax/ext/fmt.rs

+5
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
249249
}
250250
}
251251

252+
/* Short circuit an easy case up front (won't work otherwise) */
253+
if pieces.len() == 0 {
254+
return cx.expr_str_uniq(args[0].span, @"");
255+
}
256+
252257
let fmt_sp = args[0].span;
253258
let mut n = 0u;
254259
let nargs = args.len();

src/test/run-pass/syntax-extension-fmt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ fn part1() {
5858
test(fmt!("%x", 0xffffffff_u), ~"ffffffff");
5959
test(fmt!("%o", 0xffffffff_u), ~"37777777777");
6060
test(fmt!("%t", 0xffffffff_u), ~"11111111111111111111111111111111");
61+
62+
// Don't result in a compilation error
63+
test(fmt!(""), ~"");
6164
}
6265
fn part2() {
6366
// Widths

0 commit comments

Comments
 (0)