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)]
18 fn into_item(self) -> Self::Item;
19 fn as_item(&self) -> &Self::Item;
22 fn bad1<T: Iter>(v: T) -> Box<X+'static>
24 let item = v.into_item();
25 Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
28 fn bad2<T: Iter>(v: T) -> Box<X+'static>
29 where Box<T::Item> : X
31 let item: Box<_> = box v.into_item();
32 Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
35 fn bad3<'a, T: Iter>(v: T) -> Box<X+'a>
37 let item = v.into_item();
38 Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
41 fn bad4<'a, T: Iter>(v: T) -> Box<X+'a>
42 where Box<T::Item> : X
44 let item: Box<_> = box v.into_item();
45 Box::new(item) //~ ERROR associated type `<T as Iter>::Item` may not live long enough
48 fn ok1<'a, T: Iter>(v: T) -> Box<X+'a>
51 let item = v.into_item();
52 Box::new(item) // OK, T::Item : 'a is declared
55 fn ok2<'a, T: Iter>(v: &T, w: &'a T::Item) -> Box<X+'a>
58 let item = Clone::clone(w);
59 Box::new(item) // OK, T::Item : 'a is implied
62 fn ok3<'a, T: Iter>(v: &'a T) -> Box<X+'a>
63 where T::Item : Clone + 'a
65 let item = Clone::clone(v.as_item());
66 Box::new(item) // OK, T::Item : 'a was declared
69 fn meh1<'a, T: Iter>(v: &'a T) -> Box<X+'a>
72 // This case is kind of interesting. It's the same as `ok3` but
73 // without the explicit declaration. This is valid because `T: 'a
74 // => T::Item: 'a`, and the former we can deduce from our argument
77 let item = Clone::clone(v.as_item());