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.
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.
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.)
16 // compile-flags:-Znll -Zborrowck=mir
19 #![feature(dropck_eyepatch)]
20 #![feature(generic_param_attrs)]
22 fn use_x(_
: usize) -> bool { true }
25 let mut v
= [1, 2, 3];
26 let p
: WrapMayNotDangle
<&usize> = WrapMayNotDangle { value: &v[0] }
;
31 v
[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed
34 v
[0] += 1; //~ ERROR cannot assign to `v[..]` because it is borrowed
37 struct WrapMayNotDangle
<T
> {
41 impl<T
> Drop
for WrapMayNotDangle
<T
> {
42 fn drop(&mut self) { }