summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/polonius/storagedead-kills-loans.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/nll/polonius/storagedead-kills-loans.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/nll/polonius/storagedead-kills-loans.rs')
-rw-r--r--tests/ui/nll/polonius/storagedead-kills-loans.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/nll/polonius/storagedead-kills-loans.rs b/tests/ui/nll/polonius/storagedead-kills-loans.rs
new file mode 100644
index 000000000..669e077de
--- /dev/null
+++ b/tests/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.
+
+// check-pass
+// compile-flags: -Z polonius
+
+use std::{io, mem};
+use std::io::Read;
+
+#[allow(dead_code)]
+fn fill(r: &mut dyn 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() {
+}