File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,30 @@ impl<'a> Contains for Foo {
195195Please note that unconstrained lifetime parameters are not supported if they are
196196being used by an associated type.
197197
198+ In cases where the associated type's lifetime is meant to be tied to the the
199+ self type, and none of the methods on the trait need ownership or different
200+ mutability, then an option is to implement the trait on a borrowed type:
201+
202+ ``` rust
203+ struct Foo (i32 );
204+
205+ trait Contents {
206+ type Item ;
207+
208+ fn get (& self ) -> Self :: Item ;
209+ }
210+
211+ // Note the lifetime `'a` is used both for the self type...
212+ impl <'a > Contents for & 'a Foo {
213+ // ...and the associated type.
214+ type Item = & 'a i32 ;
215+
216+ fn get (& self ) -> Self :: Item {
217+ & self . 0
218+ }
219+ }
220+ ```
221+
198222### Additional information
199223
200224For more information, please see [ RFC 447] .
You can’t perform that action at this time.
0 commit comments