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

Point to a move-related span when pointing to closure upvars #75933

Merged
merged 1 commit into from
Aug 27, 2020

Conversation

Aaron1011
Copy link
Member

Fixes #75904

When emitting move/borrow errors, we may point into a closure to
indicate why an upvar is used in the closure. However, we use the
'upvar span', which is just an arbitrary usage of the upvar. If the
upvar is used in multiple places (e.g. a borrow and a move), we may end
up pointing to the borrow. If the overall error is a move error, this
can be confusing.

This PR tracks the span that caused an upvar to become captured by-value
instead of by-ref (assuming that it's not a move closure). We use this
span instead of the 'upvar' span when we need to point to an upvar usage
during borrow checking.

Fixes rust-lang#75904

When emitting move/borrow errors, we may point into a closure to
indicate why an upvar is used in the closure. However, we use the
'upvar span', which is just an arbitrary usage of the upvar. If the
upvar is used in multiple places (e.g. a borrow and a move), we may end
up pointing to the borrow. If the overall error is a move error, this
can be confusing.

This PR tracks the span that caused an upvar to become captured by-value
instead of by-ref (assuming that it's not a `move` closure). We use this
span instead of the 'upvar' span when we need to point to an upvar usage
during borrow checking.
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(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 Aug 26, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Aug 26, 2020

Have you considered changing the site where the upvar.span is computed? If so, what made you decide against doing it there?

@Aaron1011
Copy link
Member Author

@oli-obk: upvar.span is computed during the upvars_mentioned query, which is used by closure typechecking. We need the results of typechecking to determine if we should use a more specific span, so we would need to refactor some queries in order to avoid a cycle.

@Aaron1011
Copy link
Member Author

I think some upvar-related queries are in the process of being refactored to support disjoint fields capture (see #53488), which might make it easier to change the computation of upvar.span.

@oli-obk oli-obk added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 27, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Aug 27, 2020

oh, yea that makes sense.

Can you open an issue about doing this change so we don't forget about it?

@bors r+

@bors
Copy link
Contributor

bors commented Aug 27, 2020

📌 Commit b5b8b93 has been approved by oli-obk

@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 Aug 27, 2020
@bors
Copy link
Contributor

bors commented Aug 27, 2020

⌛ Testing commit b5b8b93 with merge 132f5fc...

@bors
Copy link
Contributor

bors commented Aug 27, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing 132f5fc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 27, 2020
@bors bors merged commit 132f5fc into rust-lang:master Aug 27, 2020
@Aaron1011
Copy link
Member Author

@oli-obk: Opened #76005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect 'use occurs' note when value is moved into a closure inside a loop
5 participants