diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9b1c5a406cf69..0ea03eaee18ac 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -273,7 +273,8 @@ macro_rules! vec( let mut _temp = ::std::vec::Vec::new(); $(_temp.push($e);)* _temp - }) + }); + ($($e:expr),+,) => (vec!($($e),+)) ) diff --git a/src/test/compile-fail/vec-macro-with-comma-only.rs b/src/test/compile-fail/vec-macro-with-comma-only.rs new file mode 100644 index 0000000000000..8c8e789cd9640 --- /dev/null +++ b/src/test/compile-fail/vec-macro-with-comma-only.rs @@ -0,0 +1,13 @@ +// 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. + +pub fn main() { + vec!(,); //~ ERROR unexpected token +} diff --git a/src/test/run-pass/vec-macro-with-trailing-comma.rs b/src/test/run-pass/vec-macro-with-trailing-comma.rs new file mode 100644 index 0000000000000..07033d6049747 --- /dev/null +++ b/src/test/run-pass/vec-macro-with-trailing-comma.rs @@ -0,0 +1,15 @@ +// 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. + + +pub fn main() { + assert_eq!(vec!(1), vec!(1,)); + assert_eq!(vec!(1, 2, 3), vec!(1, 2, 3,)); +}