1 #![feature(generic_associated_types)]
7 // We have a `&'a self`, so we need a `Self: 'a`
11 fn iter<'a>(&'a self) -> Self::Item<'a>;
15 impl<T> Iterable for T {
16 type Item<'a> = &'a T;
17 fn iter<'a>(&'a self) -> Self::Item<'a> {
23 // We have a `&'a T`, so we need a `T: 'x`
24 trait Deserializer<T> {
27 fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a>;
31 impl<T> Deserializer<T> for () {
33 fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a> { input }
37 // We have a `&'b T` and a `'b: 'a`, so it is implied that `T: 'a`. Therefore, we need a `T: 'x`
38 trait Deserializer2<T> {
41 fn deserialize2<'a, 'b: 'a>(&self, input1: &'b T) -> Self::Out<'a>;
44 // We have a `&'a T` and a `&'b U`, so we need a `T: 'x` and a `U: 'y`
45 trait Deserializer3<T, U> {
48 fn deserialize2<'a, 'b>(&self, input: &'a T, input2: &'b U) -> Self::Out<'a, 'b>;
51 // `T` is a param on the function, so it can't be named by the associated type
54 fn deserialize<'a, T>(&self, input: &'a T) -> Self::Out<'a>;
59 // We pass `Wrap<T>` and we see `&'z Wrap<T>`, so we require `D: 'x`
63 fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, Wrap<T>>;
67 type Out<'x, D> = &'x D; // Not okay
68 fn des<'a, T>(&self, data: &'a Wrap<T>) -> Self::Out<'a, Wrap<T>> {
74 // We have `T` and `'z` as GAT substs. Because of `&'z Wrap<T>`, there is an
75 // implied bound that `T: 'z`, so we require `D: 'x`
79 fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, T>;
83 type Out<'x, D> = &'x D;
84 fn des<'a, T>(&self, data: &'a Wrap<T>) -> Self::Out<'a, T> {
90 // We see `&'z T`, so we require `D: 'x`
94 fn des<'z, T>(&self, data: &'z T) -> Self::Out<'z, T>;
98 type Out<'x, D> = &'x D;
99 fn des<'a, T>(&self, data: &'a T) -> Self::Out<'a, T> {
105 // Similar case to before, except with GAT.
108 fn method(&'a self) -> Self::Bar;
111 // Lifetime is not on function; except `Self: 'a`
112 // FIXME: we require two bounds (`where Self: 'a, Self: 'b`) when we should only require one
113 trait TraitLifetime<'a> {
115 //~^ missing required
116 fn method(&'a self) -> Self::Bar<'a>;
119 // Like above, but we have a where clause that can prove what we want
120 // FIXME: we require two bounds (`where Self: 'a, Self: 'b`) when we should only require one
121 trait TraitLifetimeWhere<'a> where Self: 'a {
123 //~^ missing required
124 fn method(&'a self) -> Self::Bar<'a>;
127 // Explicit bound instead of implicit; we want to still error
128 trait ExplicitBound {
130 //~^ missing required
131 fn method<'b>(&self, token: &'b ()) -> Self::Bar<'b> where Self: 'b;
134 // The use of the GAT here is not in the return, we don't want to error
137 fn method<'b>(&'b self) where Self::Bar<'b>: Debug;
140 // We obviously error for `Iterator`, but we should also error for `Item`
143 //~^ missing required
144 type Iterator<'a>: Iterator<Item = Self::Item<'a>>;
145 //~^ missing required
146 fn iter<'a>(&'a self) -> Self::Iterator<'a>;
149 trait IterableTwoWhere {
151 //~^ missing required
152 type Iterator<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
153 fn iter<'a>(&'a self) -> Self::Iterator<'a>;
156 // We also should report region outlives clauses. Here, we know that `'y: 'x`,
157 // because of `&'x &'y`, so we require that `'b: 'a`.
158 trait RegionOutlives {
160 //~^ missing required
161 fn foo<'x, 'y>(&self, input: &'x &'y ()) -> Self::Bar<'x, 'y>;
166 type Bar<'a, 'b> = &'a &'b ();
167 fn foo<'x, 'y>(&self, input: &'x &'y ()) -> Self::Bar<'x, 'y> {
173 // Similar to the above, except with explicit bounds
174 trait ExplicitRegionOutlives<'ctx> {
176 //~^ missing required
178 fn test<'out>(ctx: &'ctx i32) -> Self::Fut<'out>
184 // If there are multiple methods that return the GAT, require a set of clauses
185 // that can be satisfied by *all* methods
186 trait MultipleMethods {
189 fn gimme<'a>(&'a self) -> Self::Bar<'a>;
190 fn gimme_default(&self) -> Self::Bar<'static>;
193 // We would normally require `Self: 'a`, but we can prove that `Self: 'static`
194 // because of the the bounds on the trait, so the bound is proven
195 trait Trait: 'static {
197 fn make_assoc(_: &u32) -> Self::Assoc<'_>;
200 // We ignore `'static` lifetimes for any lints
201 trait StaticReturn<'a> {
203 fn foo(&self) -> Self::Y<'static>;
206 // Same as above, but with extra method that takes GAT - just make sure this works
207 trait StaticReturnAndTakes<'a> {
209 fn foo(&self) -> Self::Y<'static>;
210 fn bar<'b>(&self, arg: Self::Y<'b>);
213 // We require bounds when the GAT appears in the inputs
216 //~^ missing required
217 fn takes_item<'a>(&'a self, item: Self::Item<'a>);
220 // We don't require bounds when the GAT appears in the where clauses
223 fn takes_item<'a>(&'a self) where Self::Item<'a>: ;