Skip to content

Commit 87f3741

Browse files
committed
auto merge of #15118 : stepancheg/rust/concat, r=alexcrichton
(And in other extensions implemented with `get_exprs_from_tts` function).
2 parents 719ffc2 + 85467b6 commit 87f3741

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/libsyntax/ext/base.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,14 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
593593
.collect());
594594
let mut es = Vec::new();
595595
while p.token != token::EOF {
596-
if es.len() != 0 && !p.eat(&token::COMMA) {
596+
es.push(cx.expand_expr(p.parse_expr()));
597+
if p.eat(&token::COMMA) {
598+
continue;
599+
}
600+
if p.token != token::EOF {
597601
cx.span_err(sp, "expected token: `,`");
598602
return None;
599603
}
600-
es.push(cx.expand_expr(p.parse_expr()));
601604
}
602605
Some(es)
603606
}

src/test/run-pass/concat.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -11,6 +11,8 @@
1111
pub fn main() {
1212
assert_eq!(format!(concat!("foo", "bar", "{}"), "baz"), "foobarbaz".to_string());
1313
assert_eq!(format!(concat!()), "".to_string());
14+
// check trailing comma is allowed in concat
15+
assert_eq!(concat!("qux", "quux",).to_string(), "quxquux".to_string());
1416

1517
assert_eq!(
1618
concat!(1, 2i, 3u, 4f32, 4.0, 'a', true, ()),

0 commit comments

Comments
 (0)