-
Notifications
You must be signed in to change notification settings - Fork 13.4k
break stmt confuses intialization-knowledge of borrow checker #24267
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
Comments
Here is a vastly reduced test case: struct Foo { n0: i32, n1: i32 }
fn leak_1_brk() -> Foo {
let ret;
loop {
ret = Foo { n0: { break }, n1: 22 };
}
ret
}
fn main() { } |
triage: P-high (1.0) |
An example not involving fields: fn consume(bar: Box<i32>) {
println!("{:?}", x);
}
fn main() {
let mut foo = Box::new(1);
loop {
foo = { consume(foo); break };
}
consume(foo);
} |
I've actually been exploiting this here: https://github.com/apasel422/tree/blob/master/src/node/mod.rs#L254-L269. It's only "worked," apparently, because there is no implementation of |
Based on some cursory investigation, my current hypothesis is that there is a bug in In particular, we have a method, The problem is that it does this by taking the union of all of the kill-effects for every node in the Its possible the fix here may be simple. Not sure yet. |
Minimal: fn main() {
let x: i32;
loop {
x = break;
}
println!("{}", x);
} |
…-exits. Fix borrowck analysis so that it will not treat a break that pops through an assignment `x = { ... break; ... }` as a kill of the "moved-out" bit for `x`. Fix rust-lang#24267.
Revise rustc::middle::dataflow: one must select kill-kind when calling add_kill. The current kill-kinds are (1.) kills associated with ends-of-scopes and (2.) kills associated with the actual action of the expression/pattern. Then, use this to fix borrowck analysis so that it will not treat a break that pops through an assignment `x = { ... break; ... }` as a kill of the "moved-out" bit for `x`. Fix rust-lang#24267.
Revise rustc::middle::dataflow: one must select kill-kind when calling add_kill. The current kill-kinds are (1.) kills associated with ends-of-scopes and (2.) kills associated with the actual action of the expression/pattern. Then, use this to fix borrowck analysis so that it will not treat a break that pops through an assignment `x = { ... break; ... }` as a kill of the "moved-out" bit for `x`. Fix rust-lang#24267.
Revise rustc::middle::dataflow: one must select kill-kind when calling add_kill. The current kill-kinds are (1.) kills associated with ends-of-scopes and (2.) kills associated with the actual action of the expression/pattern. Then, use this to fix borrowck analysis so that it will not treat a break that pops through an assignment `x = { ... break; ... }` as a kill of the "moved-out" bit for `x`. Fix rust-lang#24267. (incorporated review feedback.)
Extend rustc::middle::dataflow to allow filtering kills from flow-exits. Fix borrowck analysis so that it will not treat a break that pops through an assignment ```rust x = { ... break; ... } ``` as a kill of the "moved-out" bit for `x`. Fix #24267. [breaking-change], but really, its only breaking code that was already buggy.
This code should not compile:
demo code courtesy of niko's comment below.
Original report:
I was making regression tests for #21486 and ran into this, though @nikomatsakis has pointed out that it is not specific to FRU.
Test case 1:
Test case 2:
The text was updated successfully, but these errors were encountered: