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

Visit expressions in-order when resolving pattern bindings #92237

Merged
merged 1 commit into from
Dec 29, 2021

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Dec 24, 2021

[edited:] Visit the pattern's sub-expressions before defining any bindings.

Otherwise, we might get into a case where a Lit/Range expression in a pattern has a qpath pointing to a Ident pattern that is defined after it, causing an ICE when lowering to HIR. I have a more detailed explanation in the issue linked.

Fixes #92100

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 24, 2021
@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2021
@compiler-errors compiler-errors changed the title Visit expressions while resolving pattern bindings Visit expressions in-order when resolving pattern bindings Dec 24, 2021
@@ -1603,97 +1603,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
pat_src: PatternSource,
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>,
) {
self.resolve_pattern_inner(pat, pat_src, bindings);
ResolvePatternWalker { late: self, pat_src, bindings }.visit_pat(pat);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need another visitor? We may risk forgetting part forwarding newly added methods between the two visitors.
Could the same results be achieved by calling walk_pat earlier?
Or could we have the ResolvePatternWalker restricted to patterns and not forwarding anything else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually that's a very good point. We can achieve the same behavior by calling walk_pat first, then declaring the bindings. Fixed up the PR to be much simpler.

@cjgillot
Copy link
Contributor

r? @cjgillot
r=me with a comment explaining why we call walk_pat before the rest.

@cjgillot cjgillot 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 27, 2021
@compiler-errors
Copy link
Member Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@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 27, 2021
@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 28, 2021

📌 Commit b1529a6 has been approved by cjgillot

@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 28, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 29, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92075 (rustdoc: Only special case struct fields for intra-doc links, not enum variants)
 - rust-lang#92118 (Parse and suggest moving where clauses after equals for type aliases)
 - rust-lang#92237 (Visit expressions in-order when resolving pattern bindings)
 - rust-lang#92340 (rustdoc: Start cleaning up search index generation)
 - rust-lang#92351 (Add long error explanation for E0227)
 - rust-lang#92371 (Remove pretty printer space inside block with only outer attrs)
 - rust-lang#92372 (Print space after formal generic params in fn type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f044c6c into rust-lang:master Dec 29, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 29, 2021
@compiler-errors compiler-errors deleted the issue-92100 branch April 7, 2022 04:36
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 7, 2022
…n-DPC

Regression test for rust-lang#82866

Saw that this issue was open when i was cleaning my old branch for rust-lang#92237.
I am also not opposed to not adding an extra test and just closing rust-lang#82866.

Fixes rust-lang#82866
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.

ICE vec iter
6 participants