5 // We have a `&'a self`, so we need a `Self: 'a`
9 fn iter<'a>(&'a self) -> Self::Item<'a>;
13 impl<T> Iterable for T {
14 type Item<'a> = &'a T;
15 fn iter<'a>(&'a self) -> Self::Item<'a> {
21 // We have a `&'a T`, so we need a `T: 'x`
22 trait Deserializer<T> {
25 fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a>;
29 impl<T> Deserializer<T> for () {
31 fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a> { input }
35 // We have a `&'b T` and a `'b: 'a`, so it is implied that `T: 'a`. Therefore, we need a `T: 'x`
36 trait Deserializer2<T> {
39 fn deserialize2<'a, 'b: 'a>(&self, input1: &'b T) -> Self::Out<'a>;
42 // We have a `&'a T` and a `&'b U`, so we need a `T: 'x` and a `U: 'y`
43 trait Deserializer3<T, U> {
46 fn deserialize2<'a, 'b>(&self, input: &'a T, input2: &'b U) -> Self::Out<'a, 'b>;
49 // `T` is a param on the function, so it can't be named by the associated type
52 fn deserialize<'a, T>(&self, input: &'a T) -> Self::Out<'a>;
57 // We pass `Wrap<T>` and we see `&'z Wrap<T>`, so we require `D: 'x`
61 fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, Wrap<T>>;
65 type Out<'x, D> = &'x D; // Not okay
66 fn des<'a, T>(&self, data: &'a Wrap<T>) -> Self::Out<'a, Wrap<T>> {
72 // We have `T` and `'z` as GAT substs. Because of `&'z Wrap<T>`, there is an
73 // implied bound that `T: 'z`, so we require `D: 'x`
77 fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, T>;
81 type Out<'x, D> = &'x D;
82 fn des<'a, T>(&self, data: &'a Wrap<T>) -> Self::Out<'a, T> {
88 // We see `&'z T`, so we require `D: 'x`
92 fn des<'z, T>(&self, data: &'z T) -> Self::Out<'z, T>;
96 type Out<'x, D> = &'x D;
97 fn des<'a, T>(&self, data: &'a T) -> Self::Out<'a, T> {
103 // Similar case to before, except with GAT.
106 fn method(&'a self) -> Self::Bar;
109 // Lifetime is not on function; except `Self: 'a`
110 // FIXME: we require two bounds (`where Self: 'a, Self: 'b`) when we should only require one
111 trait TraitLifetime<'a> {
113 //~^ missing required
114 fn method(&'a self) -> Self::Bar<'a>;
117 // Like above, but we have a where clause that can prove what we want
118 // FIXME: we require two bounds (`where Self: 'a, Self: 'b`) when we should only require one
119 trait TraitLifetimeWhere<'a> where Self: 'a {
121 //~^ missing required
122 fn method(&'a self) -> Self::Bar<'a>;
125 // Explicit bound instead of implicit; we want to still error
126 trait ExplicitBound {
128 //~^ missing required
129 fn method<'b>(&self, token: &'b ()) -> Self::Bar<'b> where Self: 'b;
132 // The use of the GAT here is not in the return, we don't want to error
135 fn method<'b>(&'b self) where Self::Bar<'b>: Debug;
138 // We obviously error for `Iterator`, but we should also error for `Item`
141 //~^ missing required
142 type Iterator<'a>: Iterator<Item = Self::Item<'a>>;
143 //~^ missing required
144 fn iter<'a>(&'a self) -> Self::Iterator<'a>;
147 trait IterableTwoWhere {
149 //~^ missing required
150 type Iterator<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
151 fn iter<'a>(&'a self) -> Self::Iterator<'a>;
154 // We also should report region outlives clauses. Here, we know that `'y: 'x`,
155 // because of `&'x &'y`, so we require that `'b: 'a`.
156 trait RegionOutlives {
158 //~^ missing required
159 fn foo<'x, 'y>(&self, input: &'x &'y ()) -> Self::Bar<'x, 'y>;
164 type Bar<'a, 'b> = &'a &'b ();
165 fn foo<'x, 'y>(&self, input: &'x &'y ()) -> Self::Bar<'x, 'y> {
171 // Similar to the above, except with explicit bounds
172 trait ExplicitRegionOutlives<'ctx> {
174 //~^ missing required
176 fn test<'out>(ctx: &'ctx i32) -> Self::Fut<'out>
182 // If there are multiple methods that return the GAT, require a set of clauses
183 // that can be satisfied by *all* methods
184 trait MultipleMethods {
187 fn gimme<'a>(&'a self) -> Self::Bar<'a>;
188 fn gimme_default(&self) -> Self::Bar<'static>;
191 // We would normally require `Self: 'a`, but we can prove that `Self: 'static`
192 // because of the the bounds on the trait, so the bound is proven
193 trait Trait: 'static {
195 fn make_assoc(_: &u32) -> Self::Assoc<'_>;
198 // We ignore `'static` lifetimes for any lints
199 trait StaticReturn<'a> {
201 fn foo(&self) -> Self::Y<'static>;
204 // Same as above, but with extra method that takes GAT - just make sure this works
205 trait StaticReturnAndTakes<'a> {
207 fn foo(&self) -> Self::Y<'static>;
208 fn bar<'b>(&self, arg: Self::Y<'b>);
211 // We require bounds when the GAT appears in the inputs
214 //~^ missing required
215 fn takes_item<'a>(&'a self, item: Self::Item<'a>);
218 // We don't require bounds when the GAT appears in the where clauses
221 fn takes_item<'a>(&'a self) where Self::Item<'a>: ;