Skip to content
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

std: make vec!() macro handle a trailing comma #13278

Conversation

lifthrasiir
Copy link
Contributor

Fixes #12910.

// leading _ to allow empty construction without a warning.
let mut _temp = ::std::vec::Vec::new();
$(_temp.push($e);)*
_temp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to prevent duplication, could you change this to:

($($e:expr),+,) => (vec!($($e),+))

@@ -273,7 +273,8 @@ macro_rules! vec(
let mut _temp = ::std::vec::Vec::new();
$(_temp.push($e);)*
_temp
})
});
($($e:expr),+,) => (vec!($($e),+))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be written as `$($e:expr,)+

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I thought it is less confusing in this way. Is there any non-cosmetic downside (e.g. macro invocation parser does not like it)?

bors added a commit that referenced this pull request Apr 8, 2014
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vec!() does not handle a trailing comma
4 participants