summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/polonius/storagedead-kills-loans.rs
blob: 669e077dea417797ef92816adb9df0011684b8d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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() {
}