-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Borrow checker permits use after move in if statements #37891
Comments
Related to, maybe a duplicate of, #31287. |
I agree, the issues are very similar. |
when desugared into HIR, this pretty-prints as:
so I agree it's a dup of #31287. But definitely bad. We should move on fixing these. The plan of record has been MIR borrowck, however. |
Closing as a duplicate of #31287. |
Hmm, there is an argument for keeping this open, and addressing it by tweaking the desugaring, just because that can be done quickly, even if it's just a workaround. |
If you can hit two birds with one stone by fixing 31287 though why bother addressing this? |
Below code when compiled with Rust 1.13 (current stable) and Rust 1.15 (current nightly) will result in segmentation faults and memory corruption. The unwrap call in the else if should consume the value and prevent further use but it does not.
I expected: the borrow checker to mark the for loop as a use after move due to calling unwrap() after the value had been consumed by checking it in the else if statement
What happened: The borrow checker did not prevent this from compiling which resulted in segfaults and memory corruption.
Reproduction tip: You will get slightly different behavior of this code on each execution as memory errors are a bit finicky like that, if it works the first time try it a few more times, I'm sure you'll see it crash before you get to 5 attempts.
Meta
rustc --version --verbose
:rustc 1.15.0-nightly (ac635aa 2016-11-18)
binary: rustc
commit-hash: ac635aa
commit-date: 2016-11-18
host: x86_64-pc-windows-gnu
release: 1.15.0-nightly
LLVM version: 3.9
The text was updated successfully, but these errors were encountered: