diff options
| author | Wang Xuerui <idontknw.wang@gmail.com> | 2016-06-05 18:01:37 +0800 |
|---|---|---|
| committer | Wang Xuerui <idontknw.wang@gmail.com> | 2016-07-14 02:55:33 +0800 |
| commit | 0e2a96321a368c62cf98e73c67507a9bcdded01e (patch) | |
| tree | 2e59f1edd04d1cb94cdf62222a10f1c9cd1c04b1 /src/libsyntax_ext | |
| parent | 06b034ae8b418beab7d0767a9a8d29023558d701 (diff) | |
| download | rust-0e2a96321a368c62cf98e73c67507a9bcdded01e.tar.gz rust-0e2a96321a368c62cf98e73c67507a9bcdded01e.zip | |
syntax_ext: format: separate verification and translation of pieces
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/format.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index c0150e5ce1d..8a329126ca8 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -651,21 +651,27 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, }; let mut parser = parse::Parser::new(&fmt); + let mut pieces = vec![]; loop { match parser.next() { Some(piece) => { if !parser.errors.is_empty() { break } cx.verify_piece(&piece); - if let Some(piece) = cx.trans_piece(&piece) { - let s = cx.trans_literal_string(); - cx.str_pieces.push(s); - cx.pieces.push(piece); - } + pieces.push(piece); } None => break } } + + for piece in pieces { + if let Some(piece) = cx.trans_piece(&piece) { + let s = cx.trans_literal_string(); + cx.str_pieces.push(s); + cx.pieces.push(piece); + } + } + if !parser.errors.is_empty() { cx.ecx.span_err(cx.fmtsp, &format!("invalid format string: {}", parser.errors.remove(0))); |
