about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorlqd <remy.rakic+github@gmail.com>2019-07-15 18:50:50 +0200
committerlqd <remy.rakic+github@gmail.com>2019-07-22 11:36:46 +0200
commit9bd9b0d9bf616e8a8e7f6b4c3580041b007dd868 (patch)
treec38b77a59e212849b9823f8b7573fe1c64c5128a /src/test
parent40e6b025b27892877935c96315920b382083fcce (diff)
downloadrust-9bd9b0d9bf616e8a8e7f6b4c3580041b007dd868.tar.gz
rust-9bd9b0d9bf616e8a8e7f6b4c3580041b007dd868.zip
Add test extracted from rand, checking that StorageDead kills loans
Like "call-kills-loans", Polonius didn't know about some `killed` facts.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/nll/polonius/storagedead-kills-loans.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/nll/polonius/storagedead-kills-loans.rs b/src/test/ui/nll/polonius/storagedead-kills-loans.rs
new file mode 100644
index 00000000000..3c121d3cd18
--- /dev/null
+++ b/src/test/ui/nll/polonius/storagedead-kills-loans.rs
@@ -0,0 +1,28 @@
+// Whenever a `StorageDead` MIR statement destroys a value `x`,
+// we should kill all loans of `x`. This is extracted from `rand 0.4.6`,
+// is correctly accepted by NLL but was incorrectly rejected by
+// Polonius because of these missing `killed` facts.
+
+// build-pass
+// compile-flags: -Z borrowck=mir -Z polonius
+// ignore-compare-mode-nll
+
+use std::{io, mem};
+use std::io::Read;
+
+fn fill(r: &mut Read, mut buf: &mut [u8]) -> io::Result<()> {
+    while buf.len() > 0 {
+        match r.read(buf).unwrap() {
+            0 => return Err(io::Error::new(io::ErrorKind::Other,
+                                           "end of file reached")),
+            n => buf = &mut mem::replace(&mut buf, &mut [])[n..],
+            // ^- Polonius had multiple errors on the previous line (where NLL has none)
+            // as it didn't know `buf` was killed here, and would
+            // incorrectly reject both the borrow expression, and the assignment.
+        }
+    }
+    Ok(())
+}
+
+fn main() {
+}