]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/span/dropck-object-cycle.rs
1 // Copyright 2014 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 // This test used to be part of a run-pass test, but revised outlives
12 // rule means that it no longer compiles.
14 #![allow(unused_variables)]
17 fn long(&'a
self) -> isize;
18 fn short
<'b
>(&'b
self) -> isize;
21 fn object_invoke1
<'d
>(x
: &'d Trait
<'d
>) -> (isize, isize) { loop { }
}
27 fn make_val
<T
:MakerTrait
>() -> T
{
31 impl<'t
> MakerTrait
for Box
<Trait
<'t
>+'
static> {
32 fn mk() -> Box
<Trait
<'t
>+'
static> { loop { }
}
36 let m
: Box
<Trait
+'
static> = make_val();
37 assert_eq
!(object_invoke1(&*m
), (4,5));
38 //~^ NOTE borrow occurs here
40 // the problem here is that the full type of `m` is
42 // Box<Trait<'m>+'static>
44 // Here `'m` must be exactly the lifetime of the variable `m`.
45 // This is because of two requirements:
46 // 1. First, the basic type rules require that the
47 // type of `m`'s value outlives the lifetime of `m`. This puts a lower
50 // 2. Meanwhile, the signature of `object_invoke1` requires that
51 // we create a reference of type `&'d Trait<'d>` for some `'d`.
52 // `'d` cannot outlive `'m`, so that forces the lifetime to be `'m`.
54 // This then conflicts with the dropck rules, which require that
55 // the type of `m` *strictly outlives* `'m`. Hence we get an
58 //~^ ERROR `*m` does not live long enough
59 //~| NOTE `*m` dropped here while still borrowed
60 //~| NOTE values in a scope are dropped in the opposite order they are created