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

Fix parsing of erroneously placed semicolons #125245

Closed
wants to merge 1 commit into from

Conversation

gurry
Copy link
Contributor

@gurry gurry commented May 18, 2024

Fixes #124935

The issue occurred with code like this where a semicolon occurs at the start before any items:

;
fn main() { }

The root cause lay in the parser wherein we weren't consuming the semicolon and getting it out of the way before trying to parse the item (i.e. main in this case). This meant we attempted to parse the semicolon as an item which failed and we stopped parsing further because of that failure. The end result was that no main was recorded in the AST which lead to the no main error later on in one of the lints.

This PR ensures that we consume all consecutive semicolons (as there could be more than one) before trying to parse an item.

There were two issues here: a. we weren't consuming
any semicolons that occurred at the start of a mod
before all the items b. we weren't consuming multiple
consecutive wrongly placed semicolons; we consumed
only one and then tried to consume an item.
@rustbot
Copy link
Collaborator

rustbot commented May 18, 2024

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 May 18, 2024
@gurry gurry closed this May 18, 2024
@fmease
Copy link
Member

fmease commented May 18, 2024

Sorry about that, I didn't realize the author of the other PR was fixing a GH issue for precisely the same reason, I'll tell them to link issues in the future (I've already added a fixes keyword to their PR descr).

@fmease fmease mentioned this pull request May 18, 2024
@gurry
Copy link
Contributor Author

gurry commented May 19, 2024

No worries @fmease. Thanks 😊

@gurry gurry deleted the 124935-main-not-found branch May 19, 2024 06:36
@dev-ardi
Copy link
Contributor

dev-ardi commented May 19, 2024

What? I don't think I've fixed the issue, have I?

The PR I made existed because I'm very new and I wanted to document and make some improvements to the parser while I was reading the code in order to fix an unrelated issue :P

@fmease
Copy link
Member

fmease commented May 19, 2024

Oops, that's embarrassing 😅 I should've looked closer at the changes, I just saw both PRs swapping the order of maybe_consume_incorrect_semicolon and parse_item inside parse_mod and jumped to conclusions.

@gurry Please proceed

@dev-ardi
Copy link
Contributor

I reimplemented this after rebasing master.

@gurry
Copy link
Contributor Author

gurry commented May 20, 2024

I reimplemented this after rebasing master.

Thanks @dev-ardi

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 21, 2024
Fix parsing of erroneously placed semicolons

This closes rust-lang#124935, is a continuation of rust-lang#125245 after rebasing rust-lang#125117.

Thanks `@gurry` for your code and sorry for making it confusing :P

r? fmease
fmease added a commit to fmease/rust that referenced this pull request May 21, 2024
Fix parsing of erroneously placed semicolons

This closes rust-lang#124935, is a continuation of rust-lang#125245 after rebasing rust-lang#125117.

Thanks ``@gurry`` for your code and sorry for making it confusing :P

r? fmease
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 21, 2024
Fix parsing of erroneously placed semicolons

This closes rust-lang#124935, is a continuation of rust-lang#125245 after rebasing rust-lang#125117.

Thanks ```@gurry``` for your code and sorry for making it confusing :P

r? fmease
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 21, 2024
Rollup merge of rust-lang#125276 - dev-ardi:no-main-diag, r=fmease

Fix parsing of erroneously placed semicolons

This closes rust-lang#124935, is a continuation of rust-lang#125245 after rebasing rust-lang#125117.

Thanks ```@gurry``` for your code and sorry for making it confusing :P

r? fmease
@fmease fmease removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Wrong diagnostic: main function not found in crate
5 participants