Skip to content

Commit 0e2a963

Browse files
committed
syntax_ext: format: separate verification and translation of pieces
1 parent 06b034a commit 0e2a963

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/libsyntax_ext/format.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,27 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
651651
};
652652

653653
let mut parser = parse::Parser::new(&fmt);
654+
let mut pieces = vec![];
654655

655656
loop {
656657
match parser.next() {
657658
Some(piece) => {
658659
if !parser.errors.is_empty() { break }
659660
cx.verify_piece(&piece);
660-
if let Some(piece) = cx.trans_piece(&piece) {
661-
let s = cx.trans_literal_string();
662-
cx.str_pieces.push(s);
663-
cx.pieces.push(piece);
664-
}
661+
pieces.push(piece);
665662
}
666663
None => break
667664
}
668665
}
666+
667+
for piece in pieces {
668+
if let Some(piece) = cx.trans_piece(&piece) {
669+
let s = cx.trans_literal_string();
670+
cx.str_pieces.push(s);
671+
cx.pieces.push(piece);
672+
}
673+
}
674+
669675
if !parser.errors.is_empty() {
670676
cx.ecx.span_err(cx.fmtsp, &format!("invalid format string: {}",
671677
parser.errors.remove(0)));

0 commit comments

Comments
 (0)