Skip to content

libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'. - #61321

Merged
bors merged 1 commit into
rust-lang:masterfrom
Centril:is_keyword_ahead
May 30, 2019
Merged

libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'.#61321
bors merged 1 commit into
rust-lang:masterfrom
Centril:is_keyword_ahead

Conversation

@Centril

Copy link
Copy Markdown
Contributor

Introduces:

/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.fnis_keyword_ahead(&self,dist:usize,kws:&[Symbol]) -> bool{self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw)))}

r? @oli-obk

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 29, 2019
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)) ||

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah I believe so.

@Centril

Copy link
Copy Markdown
ContributorAuthor

r? @petrochenkov

}

/// 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 {

Copy link
Copy Markdown
ContributorAuthor

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... :)

Copy link
Copy Markdown
Contributor

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.

@petrochenkov

Copy link
Copy Markdown
Contributor

r=me with or without addressing #61321 (comment)

@petrochenkovpetrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2019
@Centril

Copy link
Copy Markdown
ContributorAuthor

Tricky choice... can't decide one way or the other... but I'll go with what is convenient ;)

@bors r=petrochenkov rollup

@bors

bors commented May 30, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 5d72ac3 has been approved by petrochenkov

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 30, 2019
Centril added a commit to Centril/rust that referenced this pull request May 30, 2019
…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
@CentrilCentril mentioned this pull request May 30, 2019
bors added a commit that referenced this pull request May 30, 2019
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
bors added a commit that referenced this pull request May 30, 2019
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
@bors
bors merged commit 5d72ac3 into rust-lang:masterMay 30, 2019
@Centril
Centril deleted the is_keyword_ahead branch May 30, 2019 14:57
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Centril@petrochenkov@bors@oli-obk@rust-highfive