File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments