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