1 // Copyright 2012 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(generic_associated_types)]
12 //~^ WARNING the feature `generic_associated_types` is incomplete
14 // FIXME(#44265): "lifetime parameter not allowed on this type" errors will be addressed in a
17 use std::fmt::Display;
19 trait StreamingIterator {
21 // Applying the lifetime parameter `'a` to `Self::Item` inside the trait.
22 fn next<'a>(&'a self) -> Option<Self::Item<'a>>;
23 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
26 struct Foo<T: StreamingIterator> {
27 // Applying a concrete lifetime to the constructor outside the trait.
28 bar: <T as StreamingIterator>::Item<'static>,
29 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
32 // Users can bound parameters by the type constructed by that trait's associated type constructor
33 // of a trait using HRTB. Both type equality bounds and trait bounds of this kind are valid:
34 //FIXME(sunjay): This next line should parse and be valid
35 //fn foo<T: for<'a> StreamingIterator<Item<'a>=&'a [i32]>>(iter: T) { /* ... */ }
36 fn foo<T>(iter: T) where T: StreamingIterator, for<'a> T::Item<'a>: Display { /* ... */ }
37 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
39 // Full example of enumerate iterator
41 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
42 struct StreamEnumerate<I> {
47 impl<I: StreamingIterator> StreamingIterator for StreamEnumerate<I> {
48 type Item<'a> = (usize, I::Item<'a>);
49 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
50 fn next<'a>(&'a self) -> Option<Self::Item<'a>> {
51 //~^ ERROR lifetime parameters are not allowed on this type [E0110]
52 match self.iter.next() {
55 let r = Some((self.count, val));
63 impl<I> StreamEnumerate<I> {
64 pub fn new(iter: I) -> Self {
72 fn test_stream_enumerate() {
73 let v = vec!["a", "b", "c"];
74 let se = StreamEnumerate::new(v.iter());
75 let a: &str = se.next().unwrap().1;
77 println!("{} {}", i, s);