]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc1598-generic-associated-types/iterable.rs
tests: prefer edition: directives to compile-flags:--edition.
[rust.git] / src / test / ui / rfc1598-generic-associated-types / iterable.rs
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.
4 //
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.
10
11 #![feature(generic_associated_types)]
12
13 use std::ops::Deref;
14
15 //FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
16 //follow-up PR
17
18 trait Iterable {
19     type Item<'a>;
20     type Iter<'a>: Iterator<Item = Self::Item<'a>>;
21     //~^ ERROR lifetime parameters are not allowed on this type [E0110]
22
23     fn iter<'a>(&'a self) -> Self::Iter<'a>;
24     //~^ ERROR lifetime parameters are not allowed on this type [E0110]
25 }
26
27 // Impl for struct type
28 impl<T> Iterable for Vec<T> {
29     type Item<'a> = &'a T;
30     type Iter<'a> = std::slice::Iter<'a, T>;
31
32     fn iter<'a>(&'a self) -> Self::Iter<'a> {
33     //~^ ERROR lifetime parameters are not allowed on this type [E0110]
34         self.iter()
35     }
36 }
37
38 // Impl for a primitive type
39 impl<T> Iterable for [T] {
40     type Item<'a> = &'a T;
41     type Iter<'a> = std::slice::Iter<'a, T>;
42
43     fn iter<'a>(&'a self) -> Self::Iter<'a> {
44     //~^ ERROR lifetime parameters are not allowed on this type [E0110]
45         self.iter()
46     }
47 }
48
49 fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> {
50     //~^ ERROR lifetime parameters are not allowed on this type [E0110]
51     it.iter()
52 }
53
54 fn get_first<'a, I: Iterable>(it: &'a I) -> Option<I::Item<'a>> {
55     //~^ ERROR lifetime parameters are not allowed on this type [E0110]
56     it.iter().next()
57 }
58
59 fn main() {}