diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4e1703fe6b0..557e7e04ebf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2021,7 +2021,7 @@ impl Parser { let es = self.parse_unspanned_seq( &token::LPAREN, &token::RPAREN, - seq_sep_trailing_disallowed(token::COMMA), + seq_sep_trailing_allowed(token::COMMA), |p| p.parse_expr() ); hi = self.last_span.hi; @@ -2994,6 +2994,7 @@ impl Parser { if self.look_ahead(1, |t| *t != token::RPAREN) { while self.token == token::COMMA { self.bump(); + if self.token == token::RPAREN { break; } fields.push(self.parse_pat()); } } @@ -3573,7 +3574,7 @@ impl Parser { self.parse_unspanned_seq( &token::LPAREN, &token::RPAREN, - seq_sep_trailing_disallowed(token::COMMA), + seq_sep_trailing_allowed(token::COMMA), |p| { if p.token == token::DOTDOTDOT { p.bump(); diff --git a/src/test/run-pass/trailing-comma.rs b/src/test/run-pass/trailing-comma.rs new file mode 100644 index 00000000000..13d79959f81 --- /dev/null +++ b/src/test/run-pass/trailing-comma.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn f(_: int,) {} + +pub fn main() { + f(0,); + let (_, _,) = (1, 1,); +}