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 #![feature(box_syntax)]
13 use std::marker::MarkerTrait;
15 trait X : MarkerTrait {}
20 fn into_item(self) -> Self::Item;
21 fn as_item(&self) -> &Self::Item;
24 fn bad1<T: Iter>(v: T) -> Box<X+'static>
26 let item = v.into_item();
27 box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough
30 fn bad2<T: Iter>(v: T) -> Box<X+'static>
31 where Box<T::Item> : X
33 let item = box v.into_item();
34 box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough
37 fn bad3<'a, T: Iter>(v: T) -> Box<X+'a>
39 let item = v.into_item();
40 box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough
43 fn bad4<'a, T: Iter>(v: T) -> Box<X+'a>
44 where Box<T::Item> : X
46 let item = box v.into_item();
47 box item //~ ERROR associated type `<T as Iter>::Item` may not live long enough
50 fn ok1<'a, T: Iter>(v: T) -> Box<X+'a>
53 let item = v.into_item();
54 box item // OK, T::Item : 'a is declared
57 fn ok2<'a, T: Iter>(v: &T, w: &'a T::Item) -> Box<X+'a>
60 let item = Clone::clone(w);
61 box item // OK, T::Item : 'a is implied
64 fn ok3<'a, T: Iter>(v: &'a T) -> Box<X+'a>
65 where T::Item : Clone + 'a
67 let item = Clone::clone(v.as_item());
68 box item // OK, T::Item : 'a was declared
71 fn meh1<'a, T: Iter>(v: &'a T) -> Box<X+'a>
74 // This case is kind of interesting. It's the same as `ok3` but
75 // without the explicit declaration. In principle, it seems like
76 // we ought to be able to infer that `T::Item : 'a` because we
77 // invoked `v.as_self()` which yielded a value of type `&'a
78 // T::Item`. But we're not that smart at present.
80 let item = Clone::clone(v.as_item());
81 box item //~ ERROR associated type `<T as Iter>::Item` may not live