Skip to content

Document how closure capturing interacts with discriminant reads #1837

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

meithecatte
Copy link
Contributor

This is the behavior after the bugfixes in rust-lang/rust#138961. I have successfully ran mdbook test with RUSTUP_TOOLCHAIN pointed at a stage1 built on top of the aforementioned PR – until it's merged, the CI here will fail.

This is the behavior after the bugfixes in rustc PR 138961.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 30, 2025
r[type.closure.capture.precision.discriminants]
### Capturing for discriminant reads

If pattern matching requires inspecting a discriminant, the relevant place will get captured by `ImmBorrow`.
Copy link
Member

@Nadrieril Nadrieril May 31, 2025

Choose a reason for hiding this comment

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

Unless we mutably access the contents, right? E.g.

let c = || match x {
    (Example::A(ref mut _y), _) => println!("variant A"),
    (Example::B(_), _) => println!("variant B"),
};

Is that already implied by the other rules?

Copy link
Member

Choose a reason for hiding this comment

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

ok yep, that's the "Shared prefix" thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. Do you think this deserves a clarification? (if so, how would you word it)

Copy link
Member

Choose a reason for hiding this comment

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

no, I think it's clear in the context

Copy link
Member

@Nadrieril Nadrieril left a comment

Choose a reason for hiding this comment

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

The changes look accurate to me. I don't know about things related to how the reference is organized so I'll leave to someone who knows to approve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: The marked PR is awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants