]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0309.md
Rollup merge of #62514 - stephaneyfx:box-ffi, r=nikomatsakis
[rust.git] / src / librustc_error_codes / error_codes / E0309.md
1 The type definition contains some field whose type
2 requires an outlives annotation. Outlives annotations
3 (e.g., `T: 'a`) are used to guarantee that all the data in T is valid
4 for at least the lifetime `'a`. This scenario most commonly
5 arises when the type contains an associated type reference
6 like `<T as SomeTrait<'a>>::Output`, as shown in this example:
7
8 ```compile_fail,E0309
9 // This won't compile because the applicable impl of
10 // `SomeTrait` (below) requires that `T: 'a`, but the struct does
11 // not have a matching where-clause.
12 struct Foo<'a, T> {
13     foo: <T as SomeTrait<'a>>::Output,
14 }
15
16 trait SomeTrait<'a> {
17     type Output;
18 }
19
20 impl<'a, T> SomeTrait<'a> for T
21 where
22     T: 'a,
23 {
24     type Output = u32;
25 }
26 ```
27
28 Here, the where clause `T: 'a` that appears on the impl is not known to be
29 satisfied on the struct. To make this example compile, you have to add
30 a where-clause like `T: 'a` to the struct definition:
31
32 ```
33 struct Foo<'a, T>
34 where
35     T: 'a,
36 {
37     foo: <T as SomeTrait<'a>>::Output
38 }
39
40 trait SomeTrait<'a> {
41     type Output;
42 }
43
44 impl<'a, T> SomeTrait<'a> for T
45 where
46     T: 'a,
47 {
48     type Output = u32;
49 }
50 ```