]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/drop-no-may-dangle.rs
Update upstream source from tag 'upstream/1.27.1+dfsg1'
[rustc.git] / src / test / ui / nll / drop-no-may-dangle.rs
1 // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Basic test for liveness constraints: the region (`R1`) that appears
12 // in the type of `p` must include everything until `p` is dropped
13 // because of destructor. (Note that the stderr also identifies this
14 // destructor in the error message.)
15
16 // compile-flags:-Zborrowck=mir
17
18 #![allow(warnings)]
19 #![feature(dropck_eyepatch)]
20
21 fn use_x(_: usize) -> bool { true }
22
23 fn main() {
24 let mut v = [1, 2, 3];
25 let p: WrapMayNotDangle<&usize> = WrapMayNotDangle { value: &v[0] };
26 if true {
27 use_x(*p.value);
28 } else {
29 use_x(22);
30 v[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed
31 }
32
33 v[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed
34 }
35
36 struct WrapMayNotDangle<T> {
37 value: T
38 }
39
40 impl<T> Drop for WrapMayNotDangle<T> {
41 fn drop(&mut self) { }
42 }