-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Closure captures immutable reference when mutable reference is necessary #87814
Comments
@rustbot claim |
The issue appears to span from this line: I am still investigating why |
@LeSeulArtichaut I don't think this error is related to my changes anymore. I think my code instead led us to discover an ICE when For instance, these 2 code works: fn main() {
let mut schema_all = vec![];
(0..42).for_each(|_x| match Err(()) { // removed as Result...
Ok(()) => schema_all.push(()),
Err(_) => (),
});
} fn main() {
let mut schema_all = vec![];
(0..42).for_each(|_x| match Err(()) as Result<(), _> {
Ok(()) => schema_all.push(()),
_ => (), // Use only _ here
});
} Otherwise, I took a look at why In the meantime, a work around would be to first walk all of the arms of the match before trying to figure out whether the discreminent should be read or not. However, even with this fix, it is very likely that a similar issue would arise in the case that the discriminant also needs to be captured. EDIT: In case we want to continue this conversation on zulip, I created a topic here: https://rust-lang.zulipchat.com/#narrow/stream/189812-t-compiler.2Fwg-rfc-2229/topic/Issue.20.2387814 |
@rustbot label +A-edition-2021 |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-medium EDIT: fixed link |
(@apiraino That link links to the thread of another issue.) |
Code
I tried this code:
I expected to see this happen: cargo build success
Instead, this happened: cargo build failed
Version it worked on
It most recently worked on:
nightly-2021-03-16
Version with regression
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: