Skip to content
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

Treat ; as a terminator rather part of a glued expression #18744

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

gbbosak
Copy link
Contributor

@gbbosak gbbosak commented Dec 22, 2024

The following code fails in rust-analyzer, but passes in rustc, using the "log" crate with the "kv" feature enabled:

fn main() {
let written:i32 = 5;
log::warn!(written:%; "Test");
}

This fails, because :%; is treated as a single glued token, rather than the :% glued expression followed by a ; terminator.

Fix this by not gluing ; to match rustc behavior.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 22, 2024
@@ -132,6 +132,7 @@ impl<'a, S: Copy> TtIter<'a, S> {
}
('-' | '!' | '*' | '/' | '&' | '%' | '^' | '+' | '<' | '=' | '>' | '|', '=', _)
| ('-' | '=' | '>', '>', _)
| (_, _, Some(';'))
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it should't change anything for the semicolon token, so that points to a more general bug in my eyes with our glueing infra structure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed because we incorrectly treat ; as a possible glued token, when it shouldn't be as it's an expression terminator. It does fix the bug in the repro mentioned above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify, why this works is that we do a 3-token at a time lookahead, and we see :%; which without this matches the rule for % followed by : followed by % (which is allowed because it's not forbidden by the match expression).

Copy link
Member

Choose a reason for hiding this comment

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

I see, it is clear that this entire part is messy and needs to be redone at some point (likely by #17830) but given this improves things right now lets merge it, thanks!

@Veykril Veykril added this pull request to the merge queue Dec 27, 2024
Merged via the queue into rust-lang:master with commit a77cf8e Dec 27, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants