-
Notifications
You must be signed in to change notification settings - Fork 13k
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
libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'. #61321
Conversation
@@ -7263,11 +7268,9 @@ impl<'a> Parser<'a> { | |||
} | |||
if self.check_keyword(kw::Impl) || | |||
self.check_keyword(kw::Unsafe) && | |||
self.look_ahead(1, |t| t.is_keyword(kw::Impl)) || | |||
self.check_keyword(kw::Default) && | |||
self.look_ahead(1, |t| t.is_keyword(kw::Impl)) || |
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.
side-note (pre existing): default unsafe fn
is eaten by this if
and will error?
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.
Yeah I believe so.
@@ -1087,6 +1087,11 @@ impl<'a> Parser<'a> { | |||
} | |||
} | |||
|
|||
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one. | |||
fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool { |
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.
We could possibly reduce this to just one keyword... that is one option... :)
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.
18 single keyword vs 5 multiple keywords.
+ look_ahead
is a single array lookup and a match, more or less, so not much reason to optimize.
Might be reasonable to reduce to one keyword.
r=me with or without addressing #61321 (comment) |
Tricky choice... can't decide one way or the other... but I'll go with what is convenient ;) @bors r=petrochenkov rollup |
📌 Commit 5d72ac3 has been approved by |
…enkov libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'. Introduces: ```rust /// Returns whether any of the given keywords are `dist` tokens ahead of the current one. fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool { self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw))) } ``` r? @oli-obk
Rollup of 11 pull requests Successful merges: - #60802 (upgrade rustdoc's `pulldown-cmark` to 0.5.2) - #60839 (Fix ICE with struct ctors and const generics.) - #60850 (Stabilize RefCell::try_borrow_unguarded) - #61231 (Fix linkage diagnostic so it doesn't ICE for external crates) - #61244 (Box::into_vec: use Box::into_raw instead of mem::forget) - #61279 (implicit `Option`-returning doctests) - #61280 (Revert "Disable solaris target since toolchain no longer builds") - #61284 (Update all s3 URLs used on CI with subdomains) - #61321 (libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'.) - #61322 (ci: display more debug information in the init_repo script) - #61333 (Fix ICE with APIT in a function with a const parameter) Failed merges: - #61304 (Speed up Azure CI installing Windows dependencies) r? @ghost
Rollup of 11 pull requests Successful merges: - #60802 (upgrade rustdoc's `pulldown-cmark` to 0.5.2) - #60839 (Fix ICE with struct ctors and const generics.) - #60850 (Stabilize RefCell::try_borrow_unguarded) - #61231 (Fix linkage diagnostic so it doesn't ICE for external crates) - #61244 (Box::into_vec: use Box::into_raw instead of mem::forget) - #61279 (implicit `Option`-returning doctests) - #61280 (Revert "Disable solaris target since toolchain no longer builds") - #61284 (Update all s3 URLs used on CI with subdomains) - #61321 (libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'.) - #61322 (ci: display more debug information in the init_repo script) - #61333 (Fix ICE with APIT in a function with a const parameter) Failed merges: - #61304 (Speed up Azure CI installing Windows dependencies) r? @ghost
Introduces:
r? @oli-obk