-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Support macros expanding to multiple items #10649
Conversation
pub enum SmallVector<T> { | ||
priv Zero, | ||
priv One(T), | ||
priv Many(~[T]), |
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.
Why priv
? Since this is mainly a fill-in until we have a proper small-vector, I'd think it's ok to just use them directly and not have the one statement constructor functions?
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.
The names would probably have to change to ZeroVec
or whatever. I was initially keeping them hidden in case this ends up being restructured into something like
pub struct SmallVector<T, N: uint> {
priv size: uint,
priv start: [Option<T>, ..N],
priv rest: Option<~[T]>
}
but I don't know if that's worth it.
@huonw I've cleaned up |
That's probably best. Also, just looking quickly now, it appears that there are some unused/can be private functions on |
I'd lean towards keeping |
@huonw removed multi-statement macros. |
Well, removing them/folding them into their point-of-use would reduce the amount of patch-over-library-holes code this adds (we already have one too many vectors defined in libsyntax, i.e. |
@huonw Updated |
} | ||
} | ||
|
||
pub fn expect_one(mut self, err: &'static str) -> T { |
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.
Isn't this mut
unnecessary? (Doesn't it warn?)
(Windows needs |
@huonw fixed |
The majority of this change is modifying some of the `ast_visit` methods to return multiple values. It's prohibitively expensive to allocate a `~[Foo]` every time a statement, declaration, item, etc is visited, especially since the vast majority will have 0 or 1 elements. I've added a `SmallVector` class that avoids allocation in the 0 and 1 element cases to take care of that.
Spelling This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling). The misspellings have been reported at https://github.com/jsoref/rust-clippy/actions/runs/4710771873#summary-12776860721 The action reports that the changes in this PR would make it happy: https://github.com/jsoref/rust-clippy/actions/runs/4710771874#summary-12776860722 changelog: none
The majority of this change is modifying some of the
ast_visit
methods to return multiple values.It's prohibitively expensive to allocate a
~[Foo]
every time a statement, declaration, item, etc is visited, especially since the vast majority will have 0 or 1 elements. I've added aSmallVector
class that avoids allocation in the 0 and 1 element cases to take care of that.