Skip to content

Commit 9bd9b0d

Browse files
committed
Add test extracted from rand, checking that StorageDead kills loans
Like "call-kills-loans", Polonius didn't know about some `killed` facts.
1 parent 40e6b02 commit 9bd9b0d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Whenever a `StorageDead` MIR statement destroys a value `x`,
2+
// we should kill all loans of `x`. This is extracted from `rand 0.4.6`,
3+
// is correctly accepted by NLL but was incorrectly rejected by
4+
// Polonius because of these missing `killed` facts.
5+
6+
// build-pass
7+
// compile-flags: -Z borrowck=mir -Z polonius
8+
// ignore-compare-mode-nll
9+
10+
use std::{io, mem};
11+
use std::io::Read;
12+
13+
fn fill(r: &mut Read, mut buf: &mut [u8]) -> io::Result<()> {
14+
while buf.len() > 0 {
15+
match r.read(buf).unwrap() {
16+
0 => return Err(io::Error::new(io::ErrorKind::Other,
17+
"end of file reached")),
18+
n => buf = &mut mem::replace(&mut buf, &mut [])[n..],
19+
// ^- Polonius had multiple errors on the previous line (where NLL has none)
20+
// as it didn't know `buf` was killed here, and would
21+
// incorrectly reject both the borrow expression, and the assignment.
22+
}
23+
}
24+
Ok(())
25+
}
26+
27+
fn main() {
28+
}

0 commit comments

Comments
 (0)