-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow syntax extensions to return multiple items, closes #16723 #17236
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
Conversation
79f55c7
to
5f0c2ea
Compare
impl MacResult for MacItems { | ||
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> { | ||
// FIXME: Implement Clone on SmallVector and use it instead of .iter().collect() | ||
Some(self.items.as_slice().iter().map(|x| x.clone()).collect()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes self
by value now so this could just be Some(self.items.move_iter().collect())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just Some(self.items)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that MacItems
does indeed store a SmallVector
this should just return Some(self.items)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes! Updated the PR.
cc @sfackler |
You might as well remove |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:issue_16723_multiple_items_syntax_ext.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to have an // ignore-stage1
.
5f0c2ea
to
36b3079
Compare
Thanks for your feedback, I've updated the PR. |
36b3079
to
98d6501
Compare
|
||
impl MacResult for MacItems { | ||
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> { | ||
// FIXME: Implement Clone on SmallVector and use it instead of .iter().collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This FIXME can likely be removed now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, thanks. Does it still make sense to implement Clone on SmallVector?
98d6501
to
f694386
Compare
f694386
to
3fc46ea
Compare
@@ -0,0 +1,30 @@ | |||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to go in run_pass_fulldeps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that was the problem!
The test should pass now, thanks for your help and patience ;)
3fc46ea
to
89b0944
Compare
This is PR is basically the change proposed by @SimonSapin for #16723. I can also extend MacItem, as @huonw suggested, but I'm not sure how that was meant exactly. A comment for MacItem states that it's a convenience type for macros that return a single item. Should I adapt MacItem to contain a SmallVector of items instead of a single item and update the comment?
And I've two questions concerning the patch.
First, I am not sure what's the best way to duplicate the SmallVector holding the items. The way I'm doing it at the moment strikes me as suboptimal (https://github.com/fhahn/rust/compare/issue-16723-multiple-items?expand=1#diff-5100da09ad52c81568562e36ee359343R241). An additional map() call is required, because
iter()
returns an iterator to pointers to the elements. Is there a better way? Should I open a ticket and implementclone()
forSmallVector
?And second, I had problems running the test in the test suite because it complains that there is no name
MacItems
insyntax::base::ext
although there is. When I compile the file withit works. But I'm not sure which
rustc
binary should be used, e.g. there is on stage1 build inx86_64-unknown-linux-gnu/stage1/bin/rustc
and one inx86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/rustc
.