-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Do for
loops still need to be a terminating scope?
#60253
Comments
Even beside the |
PR #21984 itself was motivated (or at least spawned off of) PR #21972. I'm actually trying to find out what the actual motivation for the described change was. The change, as described, was that the temporaries within So if you consider the following code (play): #![allow(unused_variables, unused_mut)]
#[derive(Debug)]
struct D(&'static str);
impl Drop for D {
fn drop(&mut self) {
println!("dropping D(\"{}\")", self.0);
}
}
fn main() {
let mut foo: Vec<&D> = Vec::new();
{
let block_temp = D("a block temp");
println!("start of enclosing block");
for (j, i) in (&vec![D("1"), D("2"), D("3")]).into_iter().enumerate() {
println!("iter: {}", j);
foo.push(i);
}
println!("end of enclosing block");
}
} which, when it is accepted by the compiler (as written it requires NLL), it should print this:
notably, we drop all of { The breakage I would be concerned about, if we made for-loops no longer a terminating scope for their @Centril has relayed to me in private conversation that they tried examples like this under variants of their desugaring and did not witness any change in behavior. Our best guess as to why this is, is because the desugaring is, in the end, turning into a |
Note: it is nonetheless possible that the distinction here is more subtle and my above example isn't quite right. in particular, I'm a little worried that there may have been a reason that the example from PR #21984 puts the for-expression in the tail expression of a block, and that examples that don't take similar care might fail to pick up on a relevant distinction here... |
Cleanup & Simplify stuff in lowering Closes rust-lang#60253 as a byproduct. It turns out that it is in fact necessary to have a `DropTemps(...)` around the `match_expr` and there is a test (https://github.com/rust-lang/rust/blob/master/src/test/ui/issues/issue-13304.rs) which fails without that. r? @eddyb
See: #60225
The text was updated successfully, but these errors were encountered: