Skip to content

Conversation

@y21
Copy link
Member

@y21 y21 commented Feb 4, 2024

Fixes #12225

The same problem in the linked issue can happen to regular closures too, and conveniently async blocks are closures in the HIR so fixing closures will fix async blocks as well.

changelog: [redundant_locals]: avoid linting when redefined variable is captured by-value

@rustbot
Copy link
Collaborator

rustbot commented Feb 4, 2024

r? @Manishearth

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 4, 2024
@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 4, 2024

📌 Commit 7c3908f has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 4, 2024

⌛ Testing commit 7c3908f with merge 50917ea...

bors added a commit that referenced this pull request Feb 4, 2024
[`redundant_locals`]: take by-value closure captures into account Fixes #12225 The same problem in the linked issue can happen to regular closures too, and conveniently async blocks are closures in the HIR so fixing closures will fix async blocks as well. changelog: [`redundant_locals`]: avoid linting when redefined variable is captured by-value
@bors
Copy link
Contributor

bors commented Feb 4, 2024

💔 Test failed - checks-action_test

@y21
Copy link
Member Author

y21 commented Feb 4, 2024

spurious

I wonder if bors lets me retry something that was already approved, probably not
@bors retry

@bors
Copy link
Contributor

bors commented Feb 4, 2024

@y21: 🔑 Insufficient privileges: not in try users

Comment on lines 103 to 110
if let DefKind::Closure = cx.tcx.def_kind(body) {
cx.tcx.closure_captures(body).iter().any(|c| {
matches!(c.info.capture_kind, UpvarCapture::ByValue)
&& matches!(c.place.base, PlaceBase::Upvar(upvar) if upvar.var_path.hir_id == root_variable)
})
} else {
false
}
Copy link
Member

Choose a reason for hiding this comment

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

This could probably have been simpler:

 matches!(cx.tcx.def_kind(body), DefKind::Closure) && cx.tcx.closure_captures(body).iter().any(|c| { matches!(c.info.capture_kind, UpvarCapture::ByValue) && matches!(c.place.base, PlaceBase::Upvar(upvar) if upvar.var_path.hir_id == root_variable) })
Copy link
Member Author

Choose a reason for hiding this comment

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

good point, i'll change it later today

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 ended up using tcx.is_closure_or_coroutine (and added tests for coroutines) since that seems more correct, but the suggestion here to get rid of the if and simplify it to && still applies so thanks :)

@Manishearth
Copy link
Member

@bors r+

subtle

@bors
Copy link
Contributor

bors commented Feb 5, 2024

📌 Commit 6807977 has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Feb 5, 2024

⌛ Testing commit 6807977 with merge fdf819d...

@bors
Copy link
Contributor

bors commented Feb 5, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing fdf819d to master...

@bors bors merged commit fdf819d into rust-lang:master Feb 5, 2024
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

5 participants