Skip to content

Allow trailing comma in concat! #15118

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,14 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
.collect());
let mut es = Vec::new();
while p.token != token::EOF {
if es.len() != 0 && !p.eat(&token::COMMA) {
es.push(cx.expand_expr(p.parse_expr()));
if p.eat(&token::COMMA) {
continue;
}
if p.token != token::EOF {
cx.span_err(sp, "expected token: `,`");
return None;
}
es.push(cx.expand_expr(p.parse_expr()));
}
Some(es)
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/run-pass/concat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -11,6 +11,8 @@
pub fn main() {
assert_eq!(format!(concat!("foo", "bar", "{}"), "baz"), "foobarbaz".to_string());
assert_eq!(format!(concat!()), "".to_string());
// check trailing comma is allowed in concat
assert_eq!(concat!("qux", "quux",).to_string(), "quxquux".to_string());

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