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 ICE on invalid variable declarations in macro calls #105141

Merged

Conversation

ohno418
Copy link
Contributor

@ohno418 ohno418 commented Dec 1, 2022

This fixes ICE that happens with invalid variable declarations in macro calls like:

macro_rules! m { ($s:stmt) => {} }
m! { var x }
m! { auto x }
m! { mut x }

Found this is because of not collecting tokens on recovery, so I changed to force collect them.

Fixes #103529.

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2022

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@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 Dec 1, 2022
@compiler-errors
Copy link
Member

r? @compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned TaKO8Ki Dec 1, 2022
@@ -73,13 +73,13 @@ impl<'a> Parser<'a> {
Ok(Some(if self.token.is_keyword(kw::Let) {
self.parse_local_mk(lo, attrs, capture_semi, force_collect)?
} else if self.is_kw_followed_by_ident(kw::Mut) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a may_recover check in all of these failure branches?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I mean the var and mut, etc. branches

@@ -117,7 +117,7 @@ macro_rules! maybe_recover_from_interpolated_ty_qpath {
};
}

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed for something? Otherwise, can you remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was using this for debugging, so thought this might be useful. Anyway, I'll remove it. Thanks!

@compiler-errors
Copy link
Member

compiler-errors commented Dec 3, 2022

Please use @rustbot ready when you're ready

Fix ICE on parsing an invalid variable declaration as a statement like:

```
macro_rules! m { ($s:stmt) => {} }
m! { var x }
```
@compiler-errors compiler-errors 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 Dec 3, 2022
Previously, the `recover_local_after_let` function was called from the
body of the `recover_stmt_local` function. Unifying these two functions
make it more simple and more readable.
@ohno418 ohno418 force-pushed the fix-ice-on-invalid-var-decl-in-macro-call branch from 3a78430 to e481258 Compare December 3, 2022 14:44
@ohno418
Copy link
Contributor Author

ohno418 commented Dec 3, 2022

@compiler-errors Thank you for the review! Fixed.
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 3, 2022
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 4, 2022

📌 Commit e481258 has been approved by compiler-errors

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 Dec 4, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2022
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#101975 (Suggest to use . instead of :: when accessing a method of an object)
 - rust-lang#105141 (Fix ICE on invalid variable declarations in macro calls)
 - rust-lang#105224 (Properly substitute inherent associated types.)
 - rust-lang#105236 (Add regression test for rust-lang#47814)
 - rust-lang#105247 (Use parent function WfCheckingContext to check RPITIT.)
 - rust-lang#105253 (Update a couple of rustbuild deps)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b181683 into rust-lang:master Dec 4, 2022
@rustbot rustbot added this to the 1.67.0 milestone Dec 4, 2022
@ohno418 ohno418 deleted the fix-ice-on-invalid-var-decl-in-macro-call branch December 5, 2022 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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.

Parser crashes after encountering invalid variable declaration in macro call
5 participants