Skip to content

Improve TokenCursor. #107544

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Feb 3, 2023
Merged

Improve TokenCursor. #107544

merged 4 commits into from
Feb 3, 2023

Conversation

nnethercote
Copy link
Contributor

Some small improvements, for things that were bugging me.

Best reviewed one commit at a time.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 1, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2023

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 1, 2023

📌 Commit a50216ac79c215bbb5ac773cb6c650c8a66397e2 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2023
@bors
Copy link
Collaborator

bors commented Feb 1, 2023

⌛ Testing commit a50216ac79c215bbb5ac773cb6c650c8a66397e2 with merge 8922ad9d3bc9694b3cb72b9c11bbeeab720023d9...

@bors
Copy link
Collaborator

bors commented Feb 1, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 1, 2023
@compiler-errors
Copy link
Member

@bors retry CI was broken

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2023
@rust-log-analyzer

This comment has been minimized.

Sometimes the parser needs to desugar a doc comment into `#[doc =
r"foo"]`. Currently it does this in a hacky way: by pushing a "fake" new
frame (one without a delimiter) onto the `TokenCursor` stack.

This commit changes things so that the token stream itself is modified
in place. The nice thing about this is that it means
`TokenCursorFrame::delim_sp` is now only `None` for the outermost frame.
The motivation here is to eliminate the `Option<(Delimiter,
DelimSpan)>`, which is `None` for the outermost token stream and `Some`
for all other token streams.

We are already treating the innermost frame specially -- this is the
`frame` vs `stack` distinction in `TokenCursor`. We can push that
further so that `frame` only contains the cursor, and `stack` elements
contain the delimiters for their children. When we are in the outermost
token stream `stack` is empty, so there are no stored delimiters, which
is what we want because the outermost token stream *has* no delimiters.

This change also shrinks `TokenCursor`, which shrinks `Parser` and
`LazyAttrTokenStreamImpl`, which is nice.
This makes it clear they return token trees, and makes for a nice
comparison against `TokenCursor` which returns tokens.
@nnethercote
Copy link
Contributor Author

@bors r=petrochenkov

@bors
Copy link
Collaborator

bors commented Feb 2, 2023

📌 Commit a86fc72 has been approved by petrochenkov

It is now in the queue for this repository.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 3, 2023
…=petrochenkov

Improve `TokenCursor`.

Some small improvements, for things that were bugging me.

Best reviewed one commit at a time.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#107082 (Autotrait bounds on dyn-safe trait methods)
 - rust-lang#107427 (Add candidates for DiscriminantKind builtin)
 - rust-lang#107539 (Emit warnings on unused parens in index expressions)
 - rust-lang#107544 (Improve `TokenCursor`.)
 - rust-lang#107585 (Don't cause a cycle when formatting query description that references a FnDef)
 - rust-lang#107633 (Fix suggestion for coercing Option<&String> to Option<&str>)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 815dc9c into rust-lang:master Feb 3, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 3, 2023
@nnethercote nnethercote deleted the improve-TokenCursor branch February 5, 2023 21:37
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants